Completed
Push — master ( b89b53...97debb )
by Dwain
04:52
created
includes/shortcodes/class-sensei-legacy-shortcodes.php 1 patch
Indentation   +249 added lines, -249 removed lines patch added patch discarded remove patch
@@ -17,323 +17,323 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class Sensei_Legacy_Shortcodes {
19 19
 
20
-    /**
21
-     * Add the legacy shortcodes to WordPress
22
-     *
23
-     * @since 1.9.0
24
-     */
25
-    public static function init(){
26
-
27
-        add_shortcode( 'allcourses',      array( __CLASS__, 'all_courses' ) );
28
-        add_shortcode( 'newcourses',      array( __CLASS__,'new_courses' ) );
29
-        add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') );
30
-        add_shortcode( 'freecourses',     array( __CLASS__,'free_courses') );
31
-        add_shortcode( 'paidcourses',     array( __CLASS__,'paid_courses') );
32
-        add_shortcode( 'usercourses',     array( __CLASS__,'user_courses' ) );
33
-
34
-    }
35
-    /**
36
-     * all_courses shortcode output function.
37
-     *
38
-     * The function should only be called indirectly through do_shortcode()
39
-     *
40
-     * @access public
41
-     * @param mixed $atts
42
-     * @param mixed $content (default: null)
43
-     * @return string
44
-     */
45
-    public static function all_courses( $atts, $content = null ) {
46
-
47
-        return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title
48
-
49
-    } // all_courses()
50
-
51
-    /**
52
-     * paid_courses function.
53
-     *
54
-     * @access public
55
-     * @param mixed $atts
56
-     * @param mixed $content (default: null)
57
-     * @return string
58
-     */
59
-    public static function paid_courses( $atts, $content = null ) {
60
-
61
-        return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' );
62
-
63
-    } // End paid_courses()
64
-
65
-
66
-    /**
67
-     * featured_courses function.
68
-     *
69
-     * @access public
70
-     * @param mixed $atts
71
-     * @param mixed $content (default: null)
72
-     * @return string
73
-     */
74
-    public static function featured_courses( $atts, $content = null ) {
75
-
76
-        return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' );
20
+	/**
21
+	 * Add the legacy shortcodes to WordPress
22
+	 *
23
+	 * @since 1.9.0
24
+	 */
25
+	public static function init(){
26
+
27
+		add_shortcode( 'allcourses',      array( __CLASS__, 'all_courses' ) );
28
+		add_shortcode( 'newcourses',      array( __CLASS__,'new_courses' ) );
29
+		add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') );
30
+		add_shortcode( 'freecourses',     array( __CLASS__,'free_courses') );
31
+		add_shortcode( 'paidcourses',     array( __CLASS__,'paid_courses') );
32
+		add_shortcode( 'usercourses',     array( __CLASS__,'user_courses' ) );
33
+
34
+	}
35
+	/**
36
+	 * all_courses shortcode output function.
37
+	 *
38
+	 * The function should only be called indirectly through do_shortcode()
39
+	 *
40
+	 * @access public
41
+	 * @param mixed $atts
42
+	 * @param mixed $content (default: null)
43
+	 * @return string
44
+	 */
45
+	public static function all_courses( $atts, $content = null ) {
46
+
47
+		return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title
48
+
49
+	} // all_courses()
50
+
51
+	/**
52
+	 * paid_courses function.
53
+	 *
54
+	 * @access public
55
+	 * @param mixed $atts
56
+	 * @param mixed $content (default: null)
57
+	 * @return string
58
+	 */
59
+	public static function paid_courses( $atts, $content = null ) {
60
+
61
+		return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' );
62
+
63
+	} // End paid_courses()
64
+
65
+
66
+	/**
67
+	 * featured_courses function.
68
+	 *
69
+	 * @access public
70
+	 * @param mixed $atts
71
+	 * @param mixed $content (default: null)
72
+	 * @return string
73
+	 */
74
+	public static function featured_courses( $atts, $content = null ) {
75
+
76
+		return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' );
77 77
 
78
-    } // End featured_courses()
78
+	} // End featured_courses()
79 79
 
80
-    /**
81
-     * shortcode_free_courses function.
82
-     *
83
-     * @access public
84
-     * @param mixed $atts
85
-     * @param mixed $content (default: null)
86
-     * @return string
87
-     */
88
-    public static function free_courses( $atts, $content = null ) {
80
+	/**
81
+	 * shortcode_free_courses function.
82
+	 *
83
+	 * @access public
84
+	 * @param mixed $atts
85
+	 * @param mixed $content (default: null)
86
+	 * @return string
87
+	 */
88
+	public static function free_courses( $atts, $content = null ) {
89 89
 
90
-        return self::generate_shortcode_courses( 'Free Courses', 'freecourses' );
90
+		return self::generate_shortcode_courses( 'Free Courses', 'freecourses' );
91 91
 
92
-    } // End free_courses()
92
+	} // End free_courses()
93 93
 
94
-    /**
95
-     * shortcode_new_courses function.
96
-     *
97
-     * @access public
98
-     * @param mixed $atts
99
-     * @param mixed $content (default: null)
100
-     * @return string
101
-     */
102
-    public static function new_courses( $atts, $content = null ) {
94
+	/**
95
+	 * shortcode_new_courses function.
96
+	 *
97
+	 * @access public
98
+	 * @param mixed $atts
99
+	 * @param mixed $content (default: null)
100
+	 * @return string
101
+	 */
102
+	public static function new_courses( $atts, $content = null ) {
103 103
 
104
-        return self::generate_shortcode_courses( 'New Courses', 'newcourses' );
104
+		return self::generate_shortcode_courses( 'New Courses', 'newcourses' );
105 105
 
106
-    } // End new_courses()
106
+	} // End new_courses()
107 107
 
108
-    /**
109
-     * Generate courses adding a title.
110
-     *
111
-     * @since 1.9.0
112
-     *
113
-     * @param $title
114
-     * @param $shortcode_specific_override
115
-     * @return string
116
-     */
117
-    public static function generate_shortcode_courses( $title , $shortcode_specific_override  ){
108
+	/**
109
+	 * Generate courses adding a title.
110
+	 *
111
+	 * @since 1.9.0
112
+	 *
113
+	 * @param $title
114
+	 * @param $shortcode_specific_override
115
+	 * @return string
116
+	 */
117
+	public static function generate_shortcode_courses( $title , $shortcode_specific_override  ){
118 118
 
119
-        global  $shortcode_override, $posts_array;
119
+		global  $shortcode_override, $posts_array;
120 120
 
121
-        $shortcode_override = $shortcode_specific_override;
121
+		$shortcode_override = $shortcode_specific_override;
122 122
 
123
-        // do not show this short code if there is a shortcode int he url and
124
-        // this specific shortcode is not the one requested in the ur.
125
-        $specific_shortcode_requested = isset( $_GET['action'] ) ?  sanitize_text_field(  $_GET['action']  ) : '';
126
-        if( ! empty( $specific_shortcode_requested) &&
127
-            $specific_shortcode_requested != $shortcode_override ){
123
+		// do not show this short code if there is a shortcode int he url and
124
+		// this specific shortcode is not the one requested in the ur.
125
+		$specific_shortcode_requested = isset( $_GET['action'] ) ?  sanitize_text_field(  $_GET['action']  ) : '';
126
+		if( ! empty( $specific_shortcode_requested) &&
127
+			$specific_shortcode_requested != $shortcode_override ){
128 128
 
129
-            return '';
129
+			return '';
130 130
 
131
-        }
131
+		}
132 132
 
133
-        // loop and get all courses html
134
-        ob_start();
135
-        self::initialise_legacy_course_loop();
136
-        $courses = ob_get_clean();
133
+		// loop and get all courses html
134
+		ob_start();
135
+		self::initialise_legacy_course_loop();
136
+		$courses = ob_get_clean();
137 137
 
138
-        $content = '';
139
-        if( count( $posts_array ) > 0 ){
138
+		$content = '';
139
+		if( count( $posts_array ) > 0 ){
140 140
 
141
-            $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>';
142
-            $before .= '<section id="main-course" class="course-container">';
141
+			$before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>';
142
+			$before .= '<section id="main-course" class="course-container">';
143 143
 
144
-            $after = '</section>';
144
+			$after = '</section>';
145 145
 
146
-            //assemble
147
-            $content = $before . $courses . $after;
146
+			//assemble
147
+			$content = $before . $courses . $after;
148 148
 
149
-        }
149
+		}
150 150
 
151
-        return $content;
151
+		return $content;
152 152
 
153
-    }// end generate_shortcode_courses
153
+	}// end generate_shortcode_courses
154 154
 
155 155
 
156
-    /**
157
-     * user_courses function.
158
-     *
159
-     * @access public
160
-     * @param mixed $atts
161
-     * @param mixed $content (default: null)
162
-     * @return string
163
-     */
164
-    public static function user_courses( $atts, $content = null ) {
165
-        global $shortcode_override;
166
-        extract( shortcode_atts( array(	'amount' => 0 ), $atts ) );
156
+	/**
157
+	 * user_courses function.
158
+	 *
159
+	 * @access public
160
+	 * @param mixed $atts
161
+	 * @param mixed $content (default: null)
162
+	 * @return string
163
+	 */
164
+	public static function user_courses( $atts, $content = null ) {
165
+		global $shortcode_override;
166
+		extract( shortcode_atts( array(	'amount' => 0 ), $atts ) );
167 167
 
168
-        $shortcode_override = 'usercourses';
168
+		$shortcode_override = 'usercourses';
169 169
 
170
-        ob_start();
170
+		ob_start();
171 171
 
172
-        if( is_user_logged_in() ){
172
+		if( is_user_logged_in() ){
173 173
 
174
-            Sensei_Templates::get_template( 'user/my-courses.php' );
174
+			Sensei_Templates::get_template( 'user/my-courses.php' );
175 175
 
176
-        }else{
176
+		}else{
177 177
 
178
-            Sensei()->frontend->sensei_login_form();
178
+			Sensei()->frontend->sensei_login_form();
179 179
 
180
-        }
180
+		}
181 181
 
182
-        $content = ob_get_clean();
183
-        return $content;
182
+		$content = ob_get_clean();
183
+		return $content;
184 184
 
185
-    } // End user_courses()
185
+	} // End user_courses()
186 186
 
187
-    /**
188
-     * This function is simply to honor the legacy
189
-     * loop-course.php for the old shortcodes.
190
-     * @since 1.9.0
191
-     */
192
-    public static function initialise_legacy_course_loop(){
187
+	/**
188
+	 * This function is simply to honor the legacy
189
+	 * loop-course.php for the old shortcodes.
190
+	 * @since 1.9.0
191
+	 */
192
+	public static function initialise_legacy_course_loop(){
193 193
 
194
-        global  $post, $wp_query, $shortcode_override, $course_excludes;
194
+		global  $post, $wp_query, $shortcode_override, $course_excludes;
195 195
 
196
-        // Handle Query Type
197
-        $query_type = '';
196
+		// Handle Query Type
197
+		$query_type = '';
198 198
 
199
-        if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) {
200
-            $query_type = esc_html( $_GET[ 'action' ] );
201
-        } // End If Statement
199
+		if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) {
200
+			$query_type = esc_html( $_GET[ 'action' ] );
201
+		} // End If Statement
202 202
 
203
-        if ( '' != $shortcode_override ) {
204
-            $query_type = $shortcode_override;
205
-        } // End If Statement
203
+		if ( '' != $shortcode_override ) {
204
+			$query_type = $shortcode_override;
205
+		} // End If Statement
206 206
 
207
-        if ( !is_array( $course_excludes ) ) { $course_excludes = array(); }
207
+		if ( !is_array( $course_excludes ) ) { $course_excludes = array(); }
208 208
 
209
-        // Check that query returns results
210
-        // Handle Pagination
211
-        $paged = $wp_query->get( 'paged' );
212
-        $paged = empty( $paged ) ? 1 : $paged;
209
+		// Check that query returns results
210
+		// Handle Pagination
211
+		$paged = $wp_query->get( 'paged' );
212
+		$paged = empty( $paged ) ? 1 : $paged;
213 213
 
214 214
 
215
-        // Check for pagination settings
216
-        if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) {
215
+		// Check for pagination settings
216
+		if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) {
217 217
 
218
-            $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] );
218
+			$amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] );
219 219
 
220
-        } else {
220
+		} else {
221 221
 
222
-            $amount = $wp_query->get( 'posts_per_page' );
222
+			$amount = $wp_query->get( 'posts_per_page' );
223 223
 
224
-        } // End If Statement
224
+		} // End If Statement
225 225
 
226
-        // This is not a paginated page (or it's simply the first page of a paginated page/post)
226
+		// This is not a paginated page (or it's simply the first page of a paginated page/post)
227 227
 
228
-        global $posts_array;
229
-        $course_includes   = array();
228
+		global $posts_array;
229
+		$course_includes   = array();
230 230
 
231
-        $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes );
232
-        $course_query = new WP_Query( $query_args );
233
-        $posts_array = $course_query->get_posts();
231
+		$query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes );
232
+		$course_query = new WP_Query( $query_args );
233
+		$posts_array = $course_query->get_posts();
234 234
 
235
-        // output the courses
236
-        if( ! empty( $posts_array ) ) {
235
+		// output the courses
236
+		if( ! empty( $posts_array ) ) {
237 237
 
238
-            //output all courses for current query
239
-            self::loop_courses( $course_query, $amount );
238
+			//output all courses for current query
239
+			self::loop_courses( $course_query, $amount );
240 240
 
241
-        }
241
+		}
242 242
 
243
-    }
243
+	}
244 244
 
245
-    /**
246
-     * Loop through courses in the query and output the infomration needed
247
-     *
248
-     * @since 1.9.0
249
-     *
250
-     * @param WP_Query $course_query
251
-     */
252
-    public static function loop_courses( $course_query, $amount ){
245
+	/**
246
+	 * Loop through courses in the query and output the infomration needed
247
+	 *
248
+	 * @since 1.9.0
249
+	 *
250
+	 * @param WP_Query $course_query
251
+	 */
252
+	public static function loop_courses( $course_query, $amount ){
253 253
 
254
-        global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes;
254
+		global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes;
255 255
 
256
-        if ( count( $course_query->get_posts() ) > 0 ) {
256
+		if ( count( $course_query->get_posts() ) > 0 ) {
257 257
 
258
-            do_action( 'sensei_course_archive_header', $shortcode_override );
258
+			do_action( 'sensei_course_archive_header', $shortcode_override );
259 259
 
260
-            foreach ( $course_query->get_posts() as $course){
260
+			foreach ( $course_query->get_posts() as $course){
261 261
 
262
-                // Make sure the other loops dont include the same post twice!
263
-                array_push( $course_excludes, $course->ID );
262
+				// Make sure the other loops dont include the same post twice!
263
+				array_push( $course_excludes, $course->ID );
264 264
 
265
-                // output the course markup
266
-                self::the_course( $course->ID );
265
+				// output the course markup
266
+				self::the_course( $course->ID );
267 267
 
268
-            } // End For Loop
268
+			} // End For Loop
269 269
 
270
-            // More and Prev links
271
-            $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) );
272
-            $posts_array       = $posts_array_query->get_posts();
273
-            $max_pages = $course_query->found_posts / $amount;
274
-            if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) {
270
+			// More and Prev links
271
+			$posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) );
272
+			$posts_array       = $posts_array_query->get_posts();
273
+			$max_pages = $course_query->found_posts / $amount;
274
+			if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) {
275 275
 
276
-                switch( $shortcode_override ){
277
-                    case 'paidcourses':
278
-                        $filter = 'paid';
279
-                        break;
280
-                    case 'featuredcourses':
281
-                        $filter = 'featured';
282
-                        break;
283
-                    case 'freecourses':
284
-                        $filter = 'free';
285
-                        break;
286
-                    default:
287
-                        $filter = '';
288
-                        break;
289
-                }
276
+				switch( $shortcode_override ){
277
+					case 'paidcourses':
278
+						$filter = 'paid';
279
+						break;
280
+					case 'featuredcourses':
281
+						$filter = 'featured';
282
+						break;
283
+					case 'freecourses':
284
+						$filter = 'free';
285
+						break;
286
+					default:
287
+						$filter = '';
288
+						break;
289
+				}
290 290
 
291
-                $quer_args = array();
292
-                $quer_args[ 'paged' ] = '2';
293
-                if( !empty( $filter ) ){
294
-                    $quer_args[ 'course_filter' ] = $filter;
295
-                }
291
+				$quer_args = array();
292
+				$quer_args[ 'paged' ] = '2';
293
+				if( !empty( $filter ) ){
294
+					$quer_args[ 'course_filter' ] = $filter;
295
+				}
296 296
 
297
-                $course_pagination_link = get_post_type_archive_link( 'course' );
298
-                $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] );
299
-                $more_link_url =  esc_url( add_query_arg( $quer_args, $course_pagination_link ) );
297
+				$course_pagination_link = get_post_type_archive_link( 'course' );
298
+				$more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] );
299
+				$more_link_url =  esc_url( add_query_arg( $quer_args, $course_pagination_link ) );
300 300
 
301
-                // next/more
302
-                $html  = '<div class="navigation"><div class="nav-next">';
303
-                $html .= '<a href="' . $more_link_url . '">';
304
-                $html .= $more_link_text;
305
-                $html .= '<span class="meta-nav"></span></a></div>';
301
+				// next/more
302
+				$html  = '<div class="navigation"><div class="nav-next">';
303
+				$html .= '<a href="' . $more_link_url . '">';
304
+				$html .= $more_link_text;
305
+				$html .= '<span class="meta-nav"></span></a></div>';
306 306
 
307
-                echo apply_filters( 'course_archive_next_link', $html );
307
+				echo apply_filters( 'course_archive_next_link', $html );
308 308
 
309
-            } // End If Statement
309
+			} // End If Statement
310 310
 
311
-        } // End If Statement
312
-    }
311
+		} // End If Statement
312
+	}
313 313
 
314
-    /**
315
-     * Print a single course markup
316
-     *
317
-     * @param $course_id
318
-     */
319
-    public static function the_course( $course_id ){
314
+	/**
315
+	 * Print a single course markup
316
+	 *
317
+	 * @param $course_id
318
+	 */
319
+	public static function the_course( $course_id ){
320 320
 
321
-        // Get meta data
322
-        $course =  get_post( $course_id );
323
-        $user_info = get_userdata( absint( $course->post_author ) );
324
-        $author_link = get_author_posts_url( absint( $course->post_author ) );
325
-        $author_display_name = $user_info->display_name;
326
-        $author_id = $course->post_author;
327
-        $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' );
328
-        $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) );
329
-        $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
330
-        ?>
321
+		// Get meta data
322
+		$course =  get_post( $course_id );
323
+		$user_info = get_userdata( absint( $course->post_author ) );
324
+		$author_link = get_author_posts_url( absint( $course->post_author ) );
325
+		$author_display_name = $user_info->display_name;
326
+		$author_id = $course->post_author;
327
+		$category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' );
328
+		$preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) );
329
+		$is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
330
+		?>
331 331
 
332 332
         <article class="<?php echo esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_id ) ) ); ?>">
333 333
             <?php
334
-            // so that legacy shortcodes work with the party plugins that wants to hook in
335
-            do_action('sensei_course_content_before',$course->ID );
336
-            ?>
334
+			// so that legacy shortcodes work with the party plugins that wants to hook in
335
+			do_action('sensei_course_content_before',$course->ID );
336
+			?>
337 337
             <div class="course-content">
338 338
 
339 339
                 <?php Sensei()->course->course_image($course_id); ?>
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
                     </p>
370 370
 
371 371
                     <?php if ( 0 < $preview_lesson_count && !$is_user_taking_course ) {
372
-                        $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?>
372
+						$preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?>
373 373
                         <p class="sensei-free-lessons">
374 374
                             <a href="<?php echo get_permalink( $course_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?>
375 375
                             </a> - <?php echo $preview_lessons; ?>
@@ -380,15 +380,15 @@  discard block
 block discarded – undo
380 380
 
381 381
             </div>
382 382
             <?php
383
-            // so that legacy shortcodes work with thir party plugins that wants to hook in
384
-            do_action('sensei_course_content_after', $course->ID);
385
-            ?>
383
+			// so that legacy shortcodes work with thir party plugins that wants to hook in
384
+			do_action('sensei_course_content_after', $course->ID);
385
+			?>
386 386
 
387 387
         </article>
388 388
 
389 389
         <?php
390 390
 
391 391
 
392
-    } // end the_course
392
+	} // end the_course
393 393
 
394 394
 }// end class legacy shortcodes
395 395
\ No newline at end of file
Please login to merge, or discard this patch.
templates/single-course/lessons.php 1 patch
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -1,83 +1,83 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) exit;
3 3
 /**
4
- * The Template for displaying all single course meta information.
5
- *
6
- * Override this template by copying it to yourtheme/sensei/single-course/course-lessons.php
7
- *
8
- * @author 		Automattic
9
- * @package 	Sensei
10
- * @category    Templates
11
- * @version     1.9.0
12
- */
4
+	 * The Template for displaying all single course meta information.
5
+	 *
6
+	 * Override this template by copying it to yourtheme/sensei/single-course/course-lessons.php
7
+	 *
8
+	 * @author 		Automattic
9
+	 * @package 	Sensei
10
+	 * @category    Templates
11
+	 * @version     1.9.0
12
+	 */
13 13
 ?>
14 14
 
15 15
 <section class="course-lessons">
16 16
 
17 17
     <?php
18 18
 
19
-        /**
20
-         * Actions just before the sensei single course lessons loop begins
21
-         *
22
-         * @hooked WooThemes_Sensei_Course::load_single_course_lessons_query
23
-         * @since 1.9.0
24
-         */
25
-        do_action( 'sensei_single_course_lessons_before' );
19
+		/**
20
+		 * Actions just before the sensei single course lessons loop begins
21
+		 *
22
+		 * @hooked WooThemes_Sensei_Course::load_single_course_lessons_query
23
+		 * @since 1.9.0
24
+		 */
25
+		do_action( 'sensei_single_course_lessons_before' );
26 26
 
27
-    ?>
27
+	?>
28 28
 
29 29
     <?php
30 30
 
31
-    //lessons loaded into loop in the sensei_single_course_lessons_before hook
32
-    if( have_posts() ):
31
+	//lessons loaded into loop in the sensei_single_course_lessons_before hook
32
+	if( have_posts() ):
33 33
 
34
-        // start course lessons loop
35
-        while ( have_posts() ): the_post();  ?>
34
+		// start course lessons loop
35
+		while ( have_posts() ): the_post();  ?>
36 36
 
37 37
             <article <?php post_class(); ?> >
38 38
 
39 39
                 <?php
40 40
 
41
-                    /**
42
-                     * The hook is inside the course lesson on the single course. It fires
43
-                     * for each lesson. It is just before the lesson excerpt.
44
-                     *
45
-                     * @since 1.9.0
46
-                     *
47
-                     * @param $lessons_id
48
-                     *
49
-                     * @hooked WooThemes_Sensei_Lesson::the_lesson_meta -  5
50
-                     * @hooked WooThemes_Sensei_Lesson::the_lesson_thumbnail - 8
51
-                     *
52
-                     */
53
-                    do_action( 'sensei_single_course_inside_before_lesson', get_the_ID() );
54
-
55
-                ?>
41
+					/**
42
+					 * The hook is inside the course lesson on the single course. It fires
43
+					 * for each lesson. It is just before the lesson excerpt.
44
+					 *
45
+					 * @since 1.9.0
46
+					 *
47
+					 * @param $lessons_id
48
+					 *
49
+					 * @hooked WooThemes_Sensei_Lesson::the_lesson_meta -  5
50
+					 * @hooked WooThemes_Sensei_Lesson::the_lesson_thumbnail - 8
51
+					 *
52
+					 */
53
+					do_action( 'sensei_single_course_inside_before_lesson', get_the_ID() );
54
+
55
+				?>
56 56
 
57 57
                 <section class="entry">
58 58
 
59 59
                     <?php
60
-                    /**
61
-                     * Output all course lessons. If none found for this course
62
-                     * a notice will be displayed. What is displayed
63
-                     * is manipulated via a
64
-                     */
65
-                    the_excerpt();
66
-                    ?>
60
+					/**
61
+					 * Output all course lessons. If none found for this course
62
+					 * a notice will be displayed. What is displayed
63
+					 * is manipulated via a
64
+					 */
65
+					the_excerpt();
66
+					?>
67 67
 
68 68
                 </section>
69 69
 
70 70
                 <?php
71 71
 
72
-                    /**
73
-                     * The hook is inside the course lesson on the single course. It is just before the lesson closing markup.
74
-                     * It fires for each lesson.
75
-                     *
76
-                     * @since 1.9.0
77
-                     */
78
-                    do_action( 'sensei_single_course_inside_after_lesson', get_the_ID() );
72
+					/**
73
+					 * The hook is inside the course lesson on the single course. It is just before the lesson closing markup.
74
+					 * It fires for each lesson.
75
+					 *
76
+					 * @since 1.9.0
77
+					 */
78
+					do_action( 'sensei_single_course_inside_after_lesson', get_the_ID() );
79 79
 
80
-                ?>
80
+				?>
81 81
 
82 82
             </article>
83 83
 
@@ -87,15 +87,15 @@  discard block
 block discarded – undo
87 87
 
88 88
     <?php
89 89
 
90
-        /**
91
-         * Actions just before the sensei single course lessons loop begins
92
-         *
93
-         * @hooked WooThemes_Sensei_Course::reset_single_course_query
94
-         *
95
-         * @since 1.9.0
96
-         */
97
-        do_action( 'sensei_single_course_lessons_after' );
90
+		/**
91
+		 * Actions just before the sensei single course lessons loop begins
92
+		 *
93
+		 * @hooked WooThemes_Sensei_Course::reset_single_course_query
94
+		 *
95
+		 * @since 1.9.0
96
+		 */
97
+		do_action( 'sensei_single_course_lessons_after' );
98 98
 
99
-    ?>
99
+	?>
100 100
 
101 101
 </section>
Please login to merge, or discard this patch.
includes/shortcodes/class-sensei-shortcode-user-courses.php 1 patch
Indentation   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -25,167 +25,167 @@  discard block
 block discarded – undo
25 25
  */
26 26
 class Sensei_Shortcode_User_Courses implements Sensei_Shortcode_Interface {
27 27
 
28
-    /**
29
-     * @var WP_Query to help setup the query needed by the render method.
30
-     */
31
-    protected $query;
28
+	/**
29
+	 * @var WP_Query to help setup the query needed by the render method.
30
+	 */
31
+	protected $query;
32 32
 
33
-    /**
34
-     * @var string number of items to show on the current page
35
-     * Default: -1.
36
-     */
37
-    protected $number;
33
+	/**
34
+	 * @var string number of items to show on the current page
35
+	 * Default: -1.
36
+	 */
37
+	protected $number;
38 38
 
39
-    /**
40
-     * @var string ordery by course field
41
-     * Default: date
42
-     */
43
-    protected $orderby;
39
+	/**
40
+	 * @var string ordery by course field
41
+	 * Default: date
42
+	 */
43
+	protected $orderby;
44 44
 
45
-    /**
46
-     * @var string ASC or DESC
47
-     * Default: 'DESC'
48
-     */
49
-    protected  $order;
45
+	/**
46
+	 * @var string ASC or DESC
47
+	 * Default: 'DESC'
48
+	 */
49
+	protected  $order;
50 50
 
51
-    /**
52
-     * @var status can be completed or active. If none is specified all will be shown
53
-     */
54
-    protected $status;
51
+	/**
52
+	 * @var status can be completed or active. If none is specified all will be shown
53
+	 */
54
+	protected $status;
55 55
 
56
-    /**
57
-     * Setup the shortcode object
58
-     *
59
-     * @since 1.9.0
60
-     * @param array $attributes
61
-     * @param string $content
62
-     * @param string $shortcode the shortcode that was called for this instance
63
-     */
64
-    public function __construct( $attributes, $content, $shortcode ){
56
+	/**
57
+	 * Setup the shortcode object
58
+	 *
59
+	 * @since 1.9.0
60
+	 * @param array $attributes
61
+	 * @param string $content
62
+	 * @param string $shortcode the shortcode that was called for this instance
63
+	 */
64
+	public function __construct( $attributes, $content, $shortcode ){
65 65
 
66
-        if(!  is_user_logged_in() ) {
67
-            // show the login form
68
-            Sensei()->frontend->sensei_login_form();
69
-            return;
70
-        }
66
+		if(!  is_user_logged_in() ) {
67
+			// show the login form
68
+			Sensei()->frontend->sensei_login_form();
69
+			return;
70
+		}
71 71
 
72
-        // set up all argument need for constructing the course query
73
-        $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10';
74
-        $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title';
75
-        $this->status = isset( $attributes['status'] ) ? $attributes['status'] : 'all';
72
+		// set up all argument need for constructing the course query
73
+		$this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10';
74
+		$this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title';
75
+		$this->status = isset( $attributes['status'] ) ? $attributes['status'] : 'all';
76 76
 
77
-        // set the default for menu_order to be ASC
78
-        if( 'menu_order' == $this->orderby && !isset( $attributes['order']  ) ){
77
+		// set the default for menu_order to be ASC
78
+		if( 'menu_order' == $this->orderby && !isset( $attributes['order']  ) ){
79 79
 
80
-            $this->order =  'ASC';
80
+			$this->order =  'ASC';
81 81
 
82
-        }else{
82
+		}else{
83 83
 
84
-            // for everything else use the value passed or the default DESC
85
-            $this->order = isset( $attributes['order']  ) ? $attributes['order'] : 'ASC';
84
+			// for everything else use the value passed or the default DESC
85
+			$this->order = isset( $attributes['order']  ) ? $attributes['order'] : 'ASC';
86 86
 
87
-        }
87
+		}
88 88
 
89
-        // setup the course query that will be used when rendering
90
-        $this->setup_course_query();
91
-    }
89
+		// setup the course query that will be used when rendering
90
+		$this->setup_course_query();
91
+	}
92 92
 
93
-    /**
94
-     * Sets up the object course query
95
-     * that will be used in the render method.
96
-     *
97
-     * @since 1.9.0
98
-     */
99
-    protected function setup_course_query(){
93
+	/**
94
+	 * Sets up the object course query
95
+	 * that will be used in the render method.
96
+	 *
97
+	 * @since 1.9.0
98
+	 */
99
+	protected function setup_course_query(){
100 100
 
101
-        $status_query = array( 'user_id' => get_current_user_id(), 'type' => 'sensei_course_status' );
102
-        $user_courses_logs = Sensei_Utils::sensei_check_for_activity( $status_query , true );
103
-        if ( !is_array($user_courses_logs) ) {
101
+		$status_query = array( 'user_id' => get_current_user_id(), 'type' => 'sensei_course_status' );
102
+		$user_courses_logs = Sensei_Utils::sensei_check_for_activity( $status_query , true );
103
+		if ( !is_array($user_courses_logs) ) {
104 104
 
105
-            $user_courses_logs = array( $user_courses_logs );
105
+			$user_courses_logs = array( $user_courses_logs );
106 106
 
107
-        }
107
+		}
108 108
 
109
-        $completed_ids = $active_ids = array();
110
-        foreach( $user_courses_logs as $course_status ) {
109
+		$completed_ids = $active_ids = array();
110
+		foreach( $user_courses_logs as $course_status ) {
111 111
 
112
-            if ( Sensei_Utils::user_completed_course( $course_status, get_current_user_id() ) ) {
112
+			if ( Sensei_Utils::user_completed_course( $course_status, get_current_user_id() ) ) {
113 113
 
114
-                $completed_ids[] = $course_status->comment_post_ID;
114
+				$completed_ids[] = $course_status->comment_post_ID;
115 115
 
116
-            } else {
116
+			} else {
117 117
 
118
-                $active_ids[] = $course_status->comment_post_ID;
118
+				$active_ids[] = $course_status->comment_post_ID;
119 119
 
120
-            }
121
-        }
120
+			}
121
+		}
122 122
 
123
-        if( 'completed' == $this->status ){
123
+		if( 'completed' == $this->status ){
124 124
 
125
-            $included_courses =  $completed_ids;
125
+			$included_courses =  $completed_ids;
126 126
 
127 127
 
128
-        }elseif( 'active'==$this->status ){
128
+		}elseif( 'active'==$this->status ){
129 129
 
130
-            $included_courses =  $active_ids;
130
+			$included_courses =  $active_ids;
131 131
 
132
-        }else{ // all courses
132
+		}else{ // all courses
133 133
 
134
-            if( empty( $completed_ids ) ){
134
+			if( empty( $completed_ids ) ){
135 135
 
136
-                add_action( 'sensei_loop_course_inside_before', array( $this, 'completed_no_course_message_output' ) );
137
-            }
136
+				add_action( 'sensei_loop_course_inside_before', array( $this, 'completed_no_course_message_output' ) );
137
+			}
138 138
 
139
-            if( empty( $active_ids ) ){
139
+			if( empty( $active_ids ) ){
140 140
 
141
-                add_action( 'sensei_loop_course_inside_before', array( $this, 'active_no_course_message_output' ) );
141
+				add_action( 'sensei_loop_course_inside_before', array( $this, 'active_no_course_message_output' ) );
142 142
 
143
-            }
143
+			}
144 144
 
145
-            if( empty( $completed_ids ) &&  empty( $active_ids )  ){
145
+			if( empty( $completed_ids ) &&  empty( $active_ids )  ){
146 146
 
147
-                $included_courses = array('-1000'); // don't show any courses
147
+				$included_courses = array('-1000'); // don't show any courses
148 148
 
149
-            }else{
150
-                $included_courses = Sensei_Utils::array_zip_merge( (array)$active_ids, (array)$completed_ids );
151
-            }
149
+			}else{
150
+				$included_courses = Sensei_Utils::array_zip_merge( (array)$active_ids, (array)$completed_ids );
151
+			}
152
+
153
+
154
+		}
155
+
156
+		// temporary work around to hide pagination on the courses page
157
+		// this is in place until we can load the course for each tab via ajax
158
+		// if the shortcode is not active or in active and the active and completed
159
+		// tabs show up.
160
+		$number_of_posts = $this->number;
161
+		if( 'active' != $this->status && 'complete' != $this->status  ){
162
+			$number_of_posts = 1000;
163
+		}
164
+
165
+		// course query parameters
166
+		$query_var_paged = get_query_var('paged');
167
+		$query_args = array(
168
+			'post_type'        => 'course',
169
+			'post_status'      => 'publish',
170
+			'orderby'          => $this->orderby,
171
+			'order'            => $this->order,
172
+			'paged' => empty( $query_var_paged )? 1 : $query_var_paged,
173
+			'posts_per_page'   => $number_of_posts,
174
+			'post__in'         => $included_courses,
175
+		);
176
+
177
+		$this->query = new WP_Query( $query_args );
152 178
 
179
+	}// end setup _course_query
153 180
 
154
-        }
155
-
156
-        // temporary work around to hide pagination on the courses page
157
-        // this is in place until we can load the course for each tab via ajax
158
-        // if the shortcode is not active or in active and the active and completed
159
-        // tabs show up.
160
-        $number_of_posts = $this->number;
161
-        if( 'active' != $this->status && 'complete' != $this->status  ){
162
-            $number_of_posts = 1000;
163
-        }
164
-
165
-        // course query parameters
166
-        $query_var_paged = get_query_var('paged');
167
-        $query_args = array(
168
-            'post_type'        => 'course',
169
-            'post_status'      => 'publish',
170
-            'orderby'          => $this->orderby,
171
-            'order'            => $this->order,
172
-            'paged' => empty( $query_var_paged )? 1 : $query_var_paged,
173
-            'posts_per_page'   => $number_of_posts,
174
-            'post__in'         => $included_courses,
175
-        );
176
-
177
-        $this->query = new WP_Query( $query_args );
178
-
179
-    }// end setup _course_query
180
-
181
-    /**
182
-     * Output the message that tells the user they have
183
-     * no completed courses.
184
-     *
185
-     * @since 1.9.0
186
-     */
187
-    public function completed_no_course_message_output(){
188
-        ?>
181
+	/**
182
+	 * Output the message that tells the user they have
183
+	 * no completed courses.
184
+	 *
185
+	 * @since 1.9.0
186
+	 */
187
+	public function completed_no_course_message_output(){
188
+		?>
189 189
         <li class="user-completed">
190 190
             <div class="sensei-message info">
191 191
 
@@ -194,16 +194,16 @@  discard block
 block discarded – undo
194 194
             </div>
195 195
         </li>
196 196
         <?php
197
-    }
197
+	}
198 198
 
199
-    /**
200
-     * Output the message that tells the user they have
201
-     * no active courses.
202
-     *
203
-     * @since 1.9.0
204
-     */
205
-    public function active_no_course_message_output(){
206
-        ?>
199
+	/**
200
+	 * Output the message that tells the user they have
201
+	 * no active courses.
202
+	 *
203
+	 * @since 1.9.0
204
+	 */
205
+	public function active_no_course_message_output(){
206
+		?>
207 207
 
208 208
         <li class="user-active">
209 209
             <div class="sensei-message info">
@@ -219,141 +219,141 @@  discard block
 block discarded – undo
219 219
             </div>
220 220
         </li>
221 221
         <?php
222
-    }
222
+	}
223 223
 
224
-    /**
225
-     * Rendering the shortcode this class is responsible for.
226
-     *
227
-     * @return string $content
228
-     */
229
-    public function render(){
224
+	/**
225
+	 * Rendering the shortcode this class is responsible for.
226
+	 *
227
+	 * @return string $content
228
+	 */
229
+	public function render(){
230 230
 
231
-        global $wp_query;
231
+		global $wp_query;
232 232
 
233
-        if(!  is_user_logged_in() ) {
234
-            return '';
235
-        }
233
+		if(!  is_user_logged_in() ) {
234
+			return '';
235
+		}
236 236
 
237
-        // keep a reference to old query
238
-        $current_global_query = $wp_query;
237
+		// keep a reference to old query
238
+		$current_global_query = $wp_query;
239 239
 
240
-        // assign the query setup in $this-> setup_course_query
241
-        $wp_query = $this->query;
240
+		// assign the query setup in $this-> setup_course_query
241
+		$wp_query = $this->query;
242 242
 
243
-        $this->attach_shortcode_hooks();
243
+		$this->attach_shortcode_hooks();
244 244
 
245
-        ob_start();
246
-        echo '<section id="sensei-user-courses">';
247
-        Sensei_Messages::the_my_messages_link();
248
-        Sensei_Templates::get_template('loop-course.php');
249
-        Sensei_Templates::get_template('globals/pagination.php');
250
-        echo '</section>';
245
+		ob_start();
246
+		echo '<section id="sensei-user-courses">';
247
+		Sensei_Messages::the_my_messages_link();
248
+		Sensei_Templates::get_template('loop-course.php');
249
+		Sensei_Templates::get_template('globals/pagination.php');
250
+		echo '</section>';
251 251
 
252
-        $shortcode_output =  ob_get_clean();
252
+		$shortcode_output =  ob_get_clean();
253 253
 
254
-        $this->detach_shortcode_hooks();
254
+		$this->detach_shortcode_hooks();
255 255
 
256
-        //restore old query
257
-        $wp_query = $current_global_query;
256
+		//restore old query
257
+		$wp_query = $current_global_query;
258 258
 
259
-        return $shortcode_output;
259
+		return $shortcode_output;
260 260
 
261
-    }// end render
261
+	}// end render
262 262
 
263
-    /**
264
-     * Add hooks for the shortcode
265
-     *
266
-     * @since 1.9.0
267
-     */
268
-    public function attach_shortcode_hooks(){
263
+	/**
264
+	 * Add hooks for the shortcode
265
+	 *
266
+	 * @since 1.9.0
267
+	 */
268
+	public function attach_shortcode_hooks(){
269 269
 
270
-        // attach the toggle functionality
271
-        // don't show the toggle action if the user specified complete or active for this shortcode
272
-        if( ! in_array( $this->status, array( 'active', 'complete' ) ) ){
270
+		// attach the toggle functionality
271
+		// don't show the toggle action if the user specified complete or active for this shortcode
272
+		if( ! in_array( $this->status, array( 'active', 'complete' ) ) ){
273 273
 
274
-            add_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) );
275
-            add_action( 'wp_footer', array( $this, 'print_course_toggle_actions_inline_script' ), 90 );
274
+			add_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) );
275
+			add_action( 'wp_footer', array( $this, 'print_course_toggle_actions_inline_script' ), 90 );
276 276
 
277
-        }
277
+		}
278 278
 
279
-        // add extra classes to distinguish the course based on user completed or active
280
-        add_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 );
279
+		// add extra classes to distinguish the course based on user completed or active
280
+		add_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 );
281 281
 
282
-        // attach progress meter below course
283
-        add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) );
284
-        add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) );
282
+		// attach progress meter below course
283
+		add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) );
284
+		add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) );
285 285
 
286
-    }
286
+	}
287 287
 
288
-    /**
289
-     * Remove hooks for the shortcode
290
-     *
291
-     * @since 1.9.0
292
-     */
293
-    public function detach_shortcode_hooks(){
288
+	/**
289
+	 * Remove hooks for the shortcode
290
+	 *
291
+	 * @since 1.9.0
292
+	 */
293
+	public function detach_shortcode_hooks(){
294 294
 
295
-        //remove all hooks after the output is generated
296
-        remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) );
297
-        remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) );
298
-        remove_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 );
299
-        remove_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) );
300
-    }
295
+		//remove all hooks after the output is generated
296
+		remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) );
297
+		remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) );
298
+		remove_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 );
299
+		remove_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) );
300
+	}
301 301
 
302
-    /**
303
-     * Hooks into sensei_course_content_inside_after
304
-     *
305
-     * @param $course
306
-     */
307
-    public function attach_course_progress( $course_id ){
302
+	/**
303
+	 * Hooks into sensei_course_content_inside_after
304
+	 *
305
+	 * @param $course
306
+	 */
307
+	public function attach_course_progress( $course_id ){
308 308
 
309
-        $percentage = Sensei()->course->get_completion_percentage( $course_id, get_current_user_id() );
310
-        echo Sensei()->course->get_progress_meter( $percentage );
309
+		$percentage = Sensei()->course->get_completion_percentage( $course_id, get_current_user_id() );
310
+		echo Sensei()->course->get_progress_meter( $percentage );
311 311
 
312
-    }// attach_course_progress
312
+	}// attach_course_progress
313 313
 
314 314
 
315
-    /**
316
-     * Hooked into sensei_course_content_inside_after
317
-     *
318
-     * Prints out the course action buttons
319
-     *
320
-     * @param integer $course_id
321
-     */
322
-    public function attach_course_buttons( $course_id ){
315
+	/**
316
+	 * Hooked into sensei_course_content_inside_after
317
+	 *
318
+	 * Prints out the course action buttons
319
+	 *
320
+	 * @param integer $course_id
321
+	 */
322
+	public function attach_course_buttons( $course_id ){
323 323
 
324
-        Sensei()->course->the_course_action_buttons( get_post( $course_id ) );
324
+		Sensei()->course->the_course_action_buttons( get_post( $course_id ) );
325 325
 
326
-    }// attach_course_buttons
326
+	}// attach_course_buttons
327 327
 
328
-    /**
329
-     * Add a the user status class for the given course.
330
-     *
331
-     * @since 1.9
332
-     *
333
-     * @param array $classes
334
-     * @param WP_Post $course
335
-     * @return array $classes
336
-     */
337
-    public function course_status_class_tagging($classes, $course){
328
+	/**
329
+	 * Add a the user status class for the given course.
330
+	 *
331
+	 * @since 1.9
332
+	 *
333
+	 * @param array $classes
334
+	 * @param WP_Post $course
335
+	 * @return array $classes
336
+	 */
337
+	public function course_status_class_tagging($classes, $course){
338 338
 
339
-        if ( Sensei_Utils::user_completed_course( $course, get_current_user_id() ) ) {
339
+		if ( Sensei_Utils::user_completed_course( $course, get_current_user_id() ) ) {
340 340
 
341
-            $classes[] = 'user-completed';
341
+			$classes[] = 'user-completed';
342 342
 
343
-        } else {
343
+		} else {
344 344
 
345
-            $classes[] = 'user-active';
345
+			$classes[] = 'user-active';
346 346
 
347
-        }
347
+		}
348 348
 
349
-        return $classes;
349
+		return $classes;
350 350
 
351
-    }// end course_status_class_tagging
351
+	}// end course_status_class_tagging
352 352
 
353
-    /**
354
-     * Output the course toggle functionality
355
-     */
356
-    public function course_toggle_actions(){ ?>
353
+	/**
354
+	 * Output the course toggle functionality
355
+	 */
356
+	public function course_toggle_actions(){ ?>
357 357
 
358 358
         <section id="user-course-status-toggle">
359 359
             <a id="sensei-user-courses-active-action" href=""><?php _e('Active Courses'); ?></a>
@@ -363,12 +363,12 @@  discard block
 block discarded – undo
363 363
 
364 364
     <?php }
365 365
 
366
-    /**
367
-     * Load the javascript for the toggle functionality
368
-     *
369
-     * @since 1.9.0
370
-     */
371
-    function print_course_toggle_actions_inline_script() { ?>
366
+	/**
367
+	 * Load the javascript for the toggle functionality
368
+	 *
369
+	 * @since 1.9.0
370
+	 */
371
+	function print_course_toggle_actions_inline_script() { ?>
372 372
 
373 373
         <script type="text/javascript">
374 374
             var buttonContainer = jQuery('#user-course-status-toggle');
Please login to merge, or discard this patch.
includes/class-sensei-analysis-overview-list-table.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -159,10 +159,10 @@  discard block
 block discarded – undo
159 159
 			'order' => $order,
160 160
 		);
161 161
 
162
-        // Handle search
163
-        if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
164
-            $args['search'] = esc_html( $_GET['s'] );
165
-        }
162
+		// Handle search
163
+		if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
164
+			$args['search'] = esc_html( $_GET['s'] );
165
+		}
166 166
 
167 167
 		switch ( $this->type ) {
168 168
 			case 'courses':
@@ -219,10 +219,10 @@  discard block
 block discarded – undo
219 219
 		);
220 220
 
221 221
 
222
-        // Handle search
223
-        if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
224
-            $args['search'] = esc_html( $_GET['s'] );
225
-        }
222
+		// Handle search
223
+		if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
224
+			$args['search'] = esc_html( $_GET['s'] );
225
+		}
226 226
 
227 227
 
228 228
 		// Start the csv with the column headings
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 	 * Generates the overall array for a single item in the display
261 261
 	 * @since  1.7.0
262 262
 	 * @param object $item The current item
263
-     * @return array $column_data;
263
+	 * @return array $column_data;
264 264
 	 */
265 265
 	protected function get_row_data( $item ) {
266 266
 
@@ -296,10 +296,10 @@  discard block
 block discarded – undo
296 296
 				$percent_count = count( Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_course_percentage', $grade_args, $item ), true ) );
297 297
 				$percent_total = Sensei_Grading::get_course_users_grades_sum( $item->ID );
298 298
 
299
-                $course_average_percent = 0;
300
-                if( $percent_count > 0 && $percent_total > 0 ){
301
-                    $course_average_percent = abs( round( doubleval( $percent_total / $percent_count ), 2 ) );
302
-                }
299
+				$course_average_percent = 0;
300
+				if( $percent_count > 0 && $percent_total > 0 ){
301
+					$course_average_percent = abs( round( doubleval( $percent_total / $percent_count ), 2 ) );
302
+				}
303 303
 
304 304
 
305 305
 				// Output course data
@@ -355,12 +355,12 @@  discard block
 block discarded – undo
355 355
 					$grade_count = count( Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_grades', $grade_args, $item ), true ));
356 356
 					$grade_total = Sensei_Grading::get_lessons_users_grades_sum( $item->ID );
357 357
 
358
-                    $lesson_average_grade = 0;
359
-                    if( $grade_total > 0 && $grade_count > 0 ){
360
-                        $lesson_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) );
361
-                    }
358
+					$lesson_average_grade = 0;
359
+					if( $grade_total > 0 && $grade_count > 0 ){
360
+						$lesson_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) );
361
+					}
362 362
 
363
-                }
363
+				}
364 364
 				// Output lesson data
365 365
 				if ( $this->csv_output ) {
366 366
 					$lesson_title = apply_filters( 'the_title', $item->post_title, $item->ID );
@@ -417,15 +417,15 @@  discard block
 block discarded – undo
417 417
 				$grade_count = count( Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_user_lesson_grades', $grade_args, $item ), true ));
418 418
 				$grade_total = Sensei_Grading::get_user_graded_lessons_sum( $item->ID );
419 419
 
420
-                $user_average_grade = 0;
421
-                if( $grade_total > 0 && $grade_count > 0 ){
422
-                    $user_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) );
423
-                }
420
+				$user_average_grade = 0;
421
+				if( $grade_total > 0 && $grade_count > 0 ){
422
+					$user_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) );
423
+				}
424 424
 
425 425
 				// Output the users data
426 426
 				if ( $this->csv_output ) {
427
-                    $user_name = Sensei_Learner::get_full_name( $item->ID );
428
-                }
427
+					$user_name = Sensei_Learner::get_full_name( $item->ID );
428
+				}
429 429
 				else {
430 430
 					$url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->ID ), admin_url( 'admin.php' ) );
431 431
 					$user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $item->display_name . '</a></strong>';
@@ -519,17 +519,17 @@  discard block
 block discarded – undo
519 519
 		// This stops the full meta data of each user being loaded
520 520
 		$args['fields'] = array( 'ID', 'user_login', 'user_email', 'user_registered', 'display_name' );
521 521
 
522
-        /**
523
-         * Filter the WP_User_Query arguments
524
-         * @since 1.6.0
525
-         * @param $args
526
-         */
527
-        $args = apply_filters( 'sensei_analysis_overview_filter_users', $args );
522
+		/**
523
+		 * Filter the WP_User_Query arguments
524
+		 * @since 1.6.0
525
+		 * @param $args
526
+		 */
527
+		$args = apply_filters( 'sensei_analysis_overview_filter_users', $args );
528 528
 		$wp_user_search = new WP_User_Query( $args );
529
-        $learners = $wp_user_search->get_results();
529
+		$learners = $wp_user_search->get_results();
530 530
 		$this->total_items = $wp_user_search->get_total();
531 531
 
532
-        return $learners;
532
+		return $learners;
533 533
 
534 534
 	} // End get_learners()
535 535
 
@@ -546,15 +546,15 @@  discard block
 block discarded – undo
546 546
 		$total_courses = Sensei()->course->course_count( array('publish', 'private') );
547 547
 		$total_lessons = Sensei()->lesson->lesson_count( array('publish', 'private') );
548 548
 
549
-        /**
550
-         * filter the analysis tot grades query args
551
-         */
549
+		/**
550
+		 * filter the analysis tot grades query args
551
+		 */
552 552
 		$grade_args = apply_filters( 'sensei_analysis_total_quiz_grades', array(
553 553
 				'type' => 'sensei_lesson_status',
554 554
 				'status' => 'any',
555 555
 
556
-                'meta_key' => 'grade'
557
-        ));
556
+				'meta_key' => 'grade'
557
+		));
558 558
 
559 559
 		$total_grade_count = Sensei_Grading::get_graded_lessons_count();
560 560
 		$total_grade_total = Sensei_Grading::get_graded_lessons_sum();
Please login to merge, or discard this patch.
templates/course-results.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -1,26 +1,26 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * The Template for displaying course archives, including the course page template.
4
- *
5
- * Override this template by copying it to yourtheme/sensei/archive-course.php
6
- *
7
- * @author 		Automattic
8
- * @package 	Sensei
9
- * @category    Templates
10
- * @version     1.9.0
11
- */
3
+		 * The Template for displaying course archives, including the course page template.
4
+		 *
5
+		 * Override this template by copying it to yourtheme/sensei/archive-course.php
6
+		 *
7
+		 * @author 		Automattic
8
+		 * @package 	Sensei
9
+		 * @category    Templates
10
+		 * @version     1.9.0
11
+		 */
12 12
 ?>
13 13
 
14 14
 <?php  get_sensei_header();  ?>
15 15
 
16 16
 <?php
17 17
 /**
18
- * This hook fire inside learner-profile.php before the content
19
- *
20
- * @since 1.9.0
21
- *
22
- * @hooked Sensei_Course_Results::deprecate_sensei_course_results_content_hook() - 20
23
- */
18
+		 * This hook fire inside learner-profile.php before the content
19
+		 *
20
+		 * @since 1.9.0
21
+		 *
22
+		 * @hooked Sensei_Course_Results::deprecate_sensei_course_results_content_hook() - 20
23
+		 */
24 24
 do_action( 'sensei_course_results_content_before' );
25 25
 ?>
26 26
 
@@ -34,16 +34,16 @@  discard block
 block discarded – undo
34 34
     <section class="entry fix">
35 35
 
36 36
         <?php
37
-        /**
38
-         * This hook fire inside learner-profile.php inside directly before the content
39
-         *
40
-         * @since 1.9.0
41
-         *
42
-         * @param integer $course_id
43
-         *
44
-         */
45
-        do_action( 'sensei_course_results_content_inside_before', $course->ID );
46
-        ?>
37
+		/**
38
+		 * This hook fire inside learner-profile.php inside directly before the content
39
+		 *
40
+		 * @since 1.9.0
41
+		 *
42
+		 * @param integer $course_id
43
+		 *
44
+		 */
45
+		do_action( 'sensei_course_results_content_inside_before', $course->ID );
46
+		?>
47 47
 
48 48
         <header>
49 49
 
@@ -56,44 +56,44 @@  discard block
 block discarded – undo
56 56
         <?php if ( is_user_logged_in() ):?>
57 57
 
58 58
             <?php
59
-            /**
60
-             * This hook fire inside learner-profile.php inside directly before the content
61
-             *
62
-             * @since 1.9.0
63
-             *
64
-             * @param integer $course_id
65
-             *
66
-             * @hooked Sensei_Course_Results::course_info() - 20
67
-             */
68
-            do_action( 'sensei_course_results_content_inside_before_lessons', $course->ID );
69
-            ?>
59
+			/**
60
+			 * This hook fire inside learner-profile.php inside directly before the content
61
+			 *
62
+			 * @since 1.9.0
63
+			 *
64
+			 * @param integer $course_id
65
+			 *
66
+			 * @hooked Sensei_Course_Results::course_info() - 20
67
+			 */
68
+			do_action( 'sensei_course_results_content_inside_before_lessons', $course->ID );
69
+			?>
70 70
 
71 71
 
72 72
             <section class="course-results-lessons">
73 73
                 <?php
74
-                $started_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() );
75
-                if( $started_course ) {
74
+				$started_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() );
75
+				if( $started_course ) {
76 76
 
77
-                    sensei_the_course_results_lessons();
77
+					sensei_the_course_results_lessons();
78 78
 
79
-                }
80
-                ?>
79
+				}
80
+				?>
81 81
             </section>
82 82
 
83 83
         <?php endif; ?>
84 84
 
85 85
         <?php
86
-        /**
87
-         * This hook fire inside learner-profile.php inside directly after the content
88
-         *
89
-         * @since 1.9.0
90
-         *
91
-         * @param integer $course_id
92
-         *
93
-         * @hooked Sensei()->course_results->course_info - 20
94
-         */
95
-        do_action( 'sensei_course_results_content_inside_after', $course->ID );
96
-        ?>
86
+		/**
87
+		 * This hook fire inside learner-profile.php inside directly after the content
88
+		 *
89
+		 * @since 1.9.0
90
+		 *
91
+		 * @param integer $course_id
92
+		 *
93
+		 * @hooked Sensei()->course_results->course_info - 20
94
+		 */
95
+		do_action( 'sensei_course_results_content_inside_after', $course->ID );
96
+		?>
97 97
 
98 98
     </section>
99 99
 
@@ -101,11 +101,11 @@  discard block
 block discarded – undo
101 101
 
102 102
 <?php
103 103
 /**
104
- * This hook fire inside course-results.php before the content
105
- *
106
- * @since 1.9.0
107
- *
108
- */
104
+		 * This hook fire inside course-results.php before the content
105
+		 *
106
+		 * @since 1.9.0
107
+		 *
108
+		 */
109 109
 do_action( 'sensei_course_results_content_after' );
110 110
 ?>
111 111
 
Please login to merge, or discard this patch.
includes/theme-integrations/_s.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -1,42 +1,42 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Class Sensei__S
4
- *
5
- * Responsible for wrapping for the underscores theme
6
- * with the correct markup
7
- *
8
- *
9
- * @package Views
10
- * @subpackage Theme-Integration
11
- * @author Automattic
12
- *
13
- * @since 1.9.0
3
+	 * Class Sensei__S
4
+	 *
5
+	 * Responsible for wrapping for the underscores theme
6
+	 * with the correct markup
7
+	 *
8
+	 *
9
+	 * @package Views
10
+	 * @subpackage Theme-Integration
11
+	 * @author Automattic
12
+	 *
13
+	 * @since 1.9.0
14 14
 */
15 15
 Class Sensei__S {
16 16
 
17
-    /**
18
-     * Output opening wrappers
19
-     * @since 1.9.0
20
-     */
21
-    public function wrapper_start(){ ?>
17
+	/**
18
+	 * Output opening wrappers
19
+	 * @since 1.9.0
20
+	 */
21
+	public function wrapper_start(){ ?>
22 22
         <div id="primary" class="content-area">
23 23
             <main id="main" class="site-main" role="main">
24 24
 
25 25
     <?php }
26 26
 
27
-    /**
28
-     * Output closing wrappers
29
-     *
30
-     * @since 1.9.0
31
-     */
32
-    public function wrapper_end(){ ?>
27
+	/**
28
+	 * Output closing wrappers
29
+	 *
30
+	 * @since 1.9.0
31
+	 */
32
+	public function wrapper_end(){ ?>
33 33
 
34 34
             </main> <!-- main-site -->
35 35
           </div> <!-- content-area -->
36 36
 
37 37
 	    <?php
38 38
 
39
-        get_sidebar();
39
+		get_sidebar();
40 40
 
41
-    }
41
+	}
42 42
 } // end class
Please login to merge, or discard this patch.
includes/class-sensei-admin.php 1 patch
Indentation   +251 added lines, -251 removed lines patch added patch discarded remove patch
@@ -16,11 +16,11 @@  discard block
 block discarded – undo
16 16
 	 */
17 17
 	public function __construct () {
18 18
 
19
-        //register admin styles
19
+		//register admin styles
20 20
 		add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles_global' ) );
21 21
 
22
-        //register admin scripts
23
-        add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ) );
22
+		//register admin scripts
23
+		add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ) );
24 24
 
25 25
 		add_action( 'admin_print_styles', array( $this, 'admin_notices_styles' ) );
26 26
 		add_action( 'settings_before_form', array( $this, 'install_pages_output' ) );
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 		add_action( 'admin_head', array( $this, 'admin_menu_highlight' ) );
30 30
 		add_action( 'admin_init', array( $this, 'page_redirect' ) );
31 31
 		add_action( 'admin_init', array( $this, 'sensei_add_custom_menu_items' ) );
32
-        add_action( 'admin_init', array( __CLASS__, 'install_pages' ));
32
+		add_action( 'admin_init', array( __CLASS__, 'install_pages' ));
33 33
 
34 34
 		// Duplicate lesson & courses
35 35
 		add_filter( 'post_row_actions', array( $this, 'duplicate_action_link' ), 10, 2 );
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 
81 81
 		if( $menu_cap ) {
82 82
 			$menu[] = array( '', 'read', 'separator-sensei', '', 'wp-menu-separator sensei' );
83
-            add_menu_page( 'Sensei', 'Sensei', $menu_cap, 'sensei' , array( Sensei()->analysis, 'analysis_page' ) , '', '50' );
83
+			add_menu_page( 'Sensei', 'Sensei', $menu_cap, 'sensei' , array( Sensei()->analysis, 'analysis_page' ) , '', '50' );
84 84
 		}
85 85
 
86 86
 		add_submenu_page( 'edit.php?post_type=course', __( 'Order Courses', 'woothemes-sensei' ), __( 'Order Courses', 'woothemes-sensei' ), 'manage_sensei', 'course-order', array( $this, 'course_order_screen' ) );
@@ -128,9 +128,9 @@  discard block
 block discarded – undo
128 128
 
129 129
 		$screen = get_current_screen();
130 130
 
131
-        if( empty( $screen ) ){
132
-            return;
133
-        }
131
+		if( empty( $screen ) ){
132
+			return;
133
+		}
134 134
 
135 135
 		if ( $screen->base == 'post' && $post_type == 'course' ) {
136 136
 
@@ -141,14 +141,14 @@  discard block
 block discarded – undo
141 141
 			$submenu_file = 'edit-tags.php?taxonomy=course-category&amp;post_type=course';
142 142
 			$parent_file  = 'edit.php?post_type=course';
143 143
 
144
-        } elseif ( $screen->base == 'edit-tags' && $taxonomy == 'module' ) {
144
+		} elseif ( $screen->base == 'edit-tags' && $taxonomy == 'module' ) {
145 145
 
146
-            $submenu_file = 'edit-tags.php?taxonomy=module';
147
-            $parent_file  = 'edit.php?post_type=course';
146
+			$submenu_file = 'edit-tags.php?taxonomy=module';
147
+			$parent_file  = 'edit.php?post_type=course';
148 148
 
149 149
 		} elseif ( in_array( $screen->id, array( 'sensei_message', 'edit-sensei_message' ) ) ) {
150 150
 
151
-            $submenu_file = 'edit.php?post_type=sensei_message';
151
+			$submenu_file = 'edit.php?post_type=sensei_message';
152 152
 			$parent_file  = 'sensei';
153 153
 
154 154
 		}
@@ -176,9 +176,9 @@  discard block
 block discarded – undo
176 176
 	 */
177 177
 	function install_pages_output() {
178 178
 
179
-        if( isset($_GET['sensei_install_complete']) && 'true' == $_GET['sensei_install_complete']) {
179
+		if( isset($_GET['sensei_install_complete']) && 'true' == $_GET['sensei_install_complete']) {
180 180
 
181
-            ?>
181
+			?>
182 182
             <div id="message" class="updated sensei-message sensei-connect">
183 183
                 <p><?php _e( '<strong>Congratulations!</strong> &#8211; Sensei has been installed and set up.', 'woothemes-sensei' ); ?></p>
184 184
                 <p><a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.woothemes.com/sensei/" data-text="A premium Learning Management plugin for #WordPress that helps you create courses. Beautifully." data-via="WooThemes" data-size="large" data-hashtags="Sensei">Tweet</a>
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
             </div>
187 187
             <?php
188 188
 
189
-        }
189
+		}
190 190
 
191 191
 	} // End install_pages_output()
192 192
 
@@ -205,25 +205,25 @@  discard block
 block discarded – undo
205 205
 	function create_page( $slug, $page_title = '', $page_content = '', $post_parent = 0 ) {
206 206
 		global $wpdb;
207 207
 
208
-        $page_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s LIMIT 1;", $slug ) );
208
+		$page_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s LIMIT 1;", $slug ) );
209 209
 		if ( $page_id ) :
210 210
 			return $page_id;
211 211
 		endif;
212 212
 
213 213
 		$page_data = array(
214
-	        'post_status' 		=> 'publish',
215
-	        'post_type' 		=> 'page',
216
-	        'post_author' 		=> 1,
217
-	        'post_name' 		=> $slug,
218
-	        'post_title' 		=> $page_title,
219
-	        'post_content' 		=> $page_content,
220
-	        'post_parent' 		=> $post_parent,
221
-	        'comment_status' 	=> 'closed'
222
-	    );
214
+			'post_status' 		=> 'publish',
215
+			'post_type' 		=> 'page',
216
+			'post_author' 		=> 1,
217
+			'post_name' 		=> $slug,
218
+			'post_title' 		=> $page_title,
219
+			'post_content' 		=> $page_content,
220
+			'post_parent' 		=> $post_parent,
221
+			'comment_status' 	=> 'closed'
222
+		);
223 223
 
224
-	    $page_id = wp_insert_post( $page_data );
224
+		$page_id = wp_insert_post( $page_data );
225 225
 
226
-	    return $page_id;
226
+		return $page_id;
227 227
 
228 228
 	} // End create_page()
229 229
 
@@ -237,12 +237,12 @@  discard block
 block discarded – undo
237 237
 	function create_pages() {
238 238
 
239 239
 		// Courses page
240
-	    $new_course_page_id = $this->create_page( esc_sql( _x('courses-overview', 'page_slug', 'woothemes-sensei') ),  __('Courses', 'woothemes-sensei'), '' );
241
-        Sensei()->settings->set( 'course_page', $new_course_page_id );
240
+		$new_course_page_id = $this->create_page( esc_sql( _x('courses-overview', 'page_slug', 'woothemes-sensei') ),  __('Courses', 'woothemes-sensei'), '' );
241
+		Sensei()->settings->set( 'course_page', $new_course_page_id );
242 242
 
243
-        // User Dashboard page
244
-	    $new_my_course_page_id = $this->create_page( esc_sql( _x('my-courses', 'page_slug', 'woothemes-sensei') ), __('My Courses', 'woothemes-sensei'), '[sensei_user_courses]' );
245
-        Sensei()->settings->set( 'my_course_page',$new_my_course_page_id  );
243
+		// User Dashboard page
244
+		$new_my_course_page_id = $this->create_page( esc_sql( _x('my-courses', 'page_slug', 'woothemes-sensei') ), __('My Courses', 'woothemes-sensei'), '[sensei_user_courses]' );
245
+		Sensei()->settings->set( 'my_course_page',$new_my_course_page_id  );
246 246
 
247 247
 	} // End create_pages()
248 248
 
@@ -263,8 +263,8 @@  discard block
 block discarded – undo
263 263
 		wp_register_style( 'woothemes-sensei-global', Sensei()->plugin_url . 'assets/css/global.css', '', Sensei()->version, 'screen' );
264 264
 		wp_enqueue_style( 'woothemes-sensei-global' );
265 265
 
266
-        // Select 2 styles
267
-        wp_enqueue_style( 'sensei-core-select2', Sensei()->plugin_url . 'assets/css/select2/select2.css', '', Sensei()->version, 'screen' );
266
+		// Select 2 styles
267
+		wp_enqueue_style( 'sensei-core-select2', Sensei()->plugin_url . 'assets/css/select2/select2.css', '', Sensei()->version, 'screen' );
268 268
 
269 269
 		// Test for Write Panel Pages
270 270
 		if ( ( ( isset( $post_type ) && in_array( $post_type, $allowed_post_types ) ) && ( isset( $hook ) && in_array( $hook, $allowed_post_type_pages ) ) ) || ( isset( $_GET['page'] ) && in_array( $_GET['page'], $allowed_pages ) ) ) {
@@ -277,32 +277,32 @@  discard block
 block discarded – undo
277 277
 	} // End admin_styles_global()
278 278
 
279 279
 
280
-    /**
281
-     * Globally register all scripts needed in admin.
282
-     *
283
-     * The script users should enqueue the script when needed.
284
-     *
285
-     * @since 1.8.2
286
-     * @access public
287
-     */
288
-    public function register_scripts( $hook ){
280
+	/**
281
+	 * Globally register all scripts needed in admin.
282
+	 *
283
+	 * The script users should enqueue the script when needed.
284
+	 *
285
+	 * @since 1.8.2
286
+	 * @access public
287
+	 */
288
+	public function register_scripts( $hook ){
289 289
 
290
-        $screen = get_current_screen();
290
+		$screen = get_current_screen();
291 291
 
292
-        // Allow developers to load non-minified versions of scripts
293
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
292
+		// Allow developers to load non-minified versions of scripts
293
+		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
294 294
 
295
-        // Select2 script used to enhance all select boxes
296
-        wp_register_script( 'sensei-core-select2', Sensei()->plugin_url . '/assets/js/select2/select2' . $suffix . '.js', array( 'jquery' ), Sensei()->version );
295
+		// Select2 script used to enhance all select boxes
296
+		wp_register_script( 'sensei-core-select2', Sensei()->plugin_url . '/assets/js/select2/select2' . $suffix . '.js', array( 'jquery' ), Sensei()->version );
297 297
 
298
-        // load edit module scripts
299
-        if( 'edit-module' ==  $screen->id ){
298
+		// load edit module scripts
299
+		if( 'edit-module' ==  $screen->id ){
300 300
 
301
-            wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery.min.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version, true );
301
+			wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery.min.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version, true );
302 302
 
303
-        }
303
+		}
304 304
 
305
-    }
305
+	}
306 306
 
307 307
 
308 308
 	/**
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
 	 * @return void
313 313
 	 */
314 314
 	function admin_install_notice() {
315
-	    ?>
315
+		?>
316 316
 	    <div id="message" class="updated sensei-message sensei-connect">
317 317
 
318 318
             <p>
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 	 * @return void
348 348
 	 */
349 349
 	function admin_installed_notice() {
350
-	    ?>
350
+		?>
351 351
 	    <div id="message" class="updated sensei-message sensei-connect">
352 352
 
353 353
 	    	<p>
@@ -375,8 +375,8 @@  discard block
 block discarded – undo
375 375
 	    </div>
376 376
 	    <?php
377 377
 
378
-	    // Set installed option
379
-	    update_option('sensei_installed', 0);
378
+		// Set installed option
379
+		update_option('sensei_installed', 0);
380 380
 	} // End admin_installed_notice()
381 381
 
382 382
 
@@ -408,21 +408,21 @@  discard block
 block discarded – undo
408 408
 	function admin_notices_styles() {
409 409
 
410 410
 		// Installed notices
411
-	    if ( 1 == get_option( 'sensei_installed' ) ) {
411
+		if ( 1 == get_option( 'sensei_installed' ) ) {
412 412
 
413
-	    	wp_enqueue_style( 'sensei-activation', plugins_url(  '/assets/css/activation.css', dirname( __FILE__ ) ), '', Sensei()->version );
413
+			wp_enqueue_style( 'sensei-activation', plugins_url(  '/assets/css/activation.css', dirname( __FILE__ ) ), '', Sensei()->version );
414 414
 
415
-	    	if (get_option('skip_install_sensei_pages')!=1 && Sensei()->get_page_id('course')<1 && !isset($_GET['install_sensei_pages']) && !isset($_GET['skip_install_sensei_pages'])) {
416
-	    		add_action( 'admin_notices', array( $this, 'admin_install_notice' ) );
417
-	    	} elseif ( !isset($_GET['page']) || $_GET['page']!='woothemes-sensei-settings' ) {
418
-	    		add_action( 'admin_notices', array( $this, 'admin_installed_notice' ) );
419
-	    	} // End If Statement
415
+			if (get_option('skip_install_sensei_pages')!=1 && Sensei()->get_page_id('course')<1 && !isset($_GET['install_sensei_pages']) && !isset($_GET['skip_install_sensei_pages'])) {
416
+				add_action( 'admin_notices', array( $this, 'admin_install_notice' ) );
417
+			} elseif ( !isset($_GET['page']) || $_GET['page']!='woothemes-sensei-settings' ) {
418
+				add_action( 'admin_notices', array( $this, 'admin_installed_notice' ) );
419
+			} // End If Statement
420 420
 
421
-	    } // End If Statement
421
+		} // End If Statement
422 422
 
423
-	    if ( Sensei_Language_Pack_Manager::has_language_pack_available() ) {
424
-	    	add_action( 'admin_notices', array( $this, 'language_pack_install_notice' ) );
425
-	    }
423
+		if ( Sensei_Language_Pack_Manager::has_language_pack_available() ) {
424
+			add_action( 'admin_notices', array( $this, 'language_pack_install_notice' ) );
425
+		}
426 426
 
427 427
 	} // End admin_notices_styles()
428 428
 
@@ -538,30 +538,30 @@  discard block
 block discarded – undo
538 538
 	 */
539 539
 	private function duplicate_lesson_quizzes( $old_lesson_id, $new_lesson_id ) {
540 540
 
541
-        $old_quiz_id = Sensei()->lesson->lesson_quizzes( $old_lesson_id );
542
-        $old_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $old_quiz_id );
541
+		$old_quiz_id = Sensei()->lesson->lesson_quizzes( $old_lesson_id );
542
+		$old_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $old_quiz_id );
543 543
 
544
-        // duplicate the generic wp post information
544
+		// duplicate the generic wp post information
545 545
 		$new_quiz = $this->duplicate_post( get_post( $old_quiz_id ), '' );
546 546
 
547 547
 		//update the new lesson data
548
-        add_post_meta( $new_lesson_id, '_lesson_quiz', $new_quiz->ID );
548
+		add_post_meta( $new_lesson_id, '_lesson_quiz', $new_quiz->ID );
549 549
 
550 550
 		//update the new quiz data
551
-        add_post_meta( $new_quiz->ID, '_quiz_lesson', $new_lesson_id );
552
-        wp_update_post(
553
-            array(
554
-                'ID' => $new_quiz->ID,
555
-                'post_parent' => $new_lesson_id
556
-            )
557
-        );
551
+		add_post_meta( $new_quiz->ID, '_quiz_lesson', $new_lesson_id );
552
+		wp_update_post(
553
+			array(
554
+				'ID' => $new_quiz->ID,
555
+				'post_parent' => $new_lesson_id
556
+			)
557
+		);
558 558
 
559 559
 		foreach( $old_quiz_questions as $question ) {
560 560
 
561 561
 			// copy the question order over to the new quiz
562 562
 			$old_question_order = get_post_meta( $question->ID, '_quiz_question_order'. $old_quiz_id, true );
563
-            $new_question_order = str_ireplace( $old_quiz_id, $new_quiz->ID , $old_question_order );
564
-            add_post_meta( $question->ID, '_quiz_question_order' . $new_quiz->ID, $new_question_order );
563
+			$new_question_order = str_ireplace( $old_quiz_id, $new_quiz->ID , $old_question_order );
564
+			add_post_meta( $question->ID, '_quiz_question_order' . $new_quiz->ID, $new_question_order );
565 565
 
566 566
 			// Add question to quiz
567 567
 			add_post_meta( $question->ID, '_quiz_id', $new_quiz->ID, false );
@@ -883,21 +883,21 @@  discard block
 block discarded – undo
883 883
 								break;
884 884
 
885 885
 								case 'checkbox':
886
-                                    //backwards compatibility
887
-                                    if( empty( $data ) || 'on' == $data ){
888
-                                        $checked_value = 'on';
889
-                                    }elseif( 'yes' == $data  ) {
886
+									//backwards compatibility
887
+									if( empty( $data ) || 'on' == $data ){
888
+										$checked_value = 'on';
889
+									}elseif( 'yes' == $data  ) {
890 890
 
891
-                                        $checked_value = 'yes';
891
+										$checked_value = 'yes';
892 892
 
893
-                                    }elseif( 'auto' == $data  ) {
893
+									}elseif( 'auto' == $data  ) {
894 894
 
895
-                                        $checked_value = 'auto';
895
+										$checked_value = 'auto';
896 896
 
897
-                                    } else {
898
-                                        $checked_value = 1;
899
-                                        $data = intval( $data );
900
-                                    }
897
+									} else {
898
+										$checked_value = 1;
899
+										$data = intval( $data );
900
+									}
901 901
 									$checked = checked( $checked_value, $data, false );
902 902
 									$html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $field['id'] ) . '" ' . $checked . ' ' . $disabled . '/>' . "\n";
903 903
 								break;
@@ -1001,26 +1001,26 @@  discard block
 block discarded – undo
1001 1001
 
1002 1002
 		if( 0 < count( $courses ) ) {
1003 1003
 
1004
-            // order the courses as set by the users
1005
-            $all_course_ids = array();
1006
-            foreach( $courses as $course ){
1004
+			// order the courses as set by the users
1005
+			$all_course_ids = array();
1006
+			foreach( $courses as $course ){
1007 1007
 
1008
-                $all_course_ids[] = (string)$course->ID;
1008
+				$all_course_ids[] = (string)$course->ID;
1009 1009
 
1010
-            }
1011
-            $order_string = $this->get_course_order();
1010
+			}
1011
+			$order_string = $this->get_course_order();
1012 1012
 
1013
-            if( !empty( $order_string ) ){
1014
-                $ordered_course_ids = explode(',' , $order_string );
1015
-                $all_course_ids = array_unique( array_merge( $ordered_course_ids , $all_course_ids ) );
1016
-            }
1013
+			if( !empty( $order_string ) ){
1014
+				$ordered_course_ids = explode(',' , $order_string );
1015
+				$all_course_ids = array_unique( array_merge( $ordered_course_ids , $all_course_ids ) );
1016
+			}
1017 1017
 
1018 1018
 
1019 1019
 			$html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
1020 1020
 			$html .= '<ul class="sortable-course-list">' . "\n";
1021 1021
 			$count = 0;
1022 1022
 			foreach ( $all_course_ids as $course_id ) {
1023
-                $course = get_post( $course_id );
1023
+				$course = get_post( $course_id );
1024 1024
 				$count++;
1025 1025
 				$class = 'course';
1026 1026
 				if ( $count == 1 ) { $class .= ' first'; }
@@ -1135,73 +1135,73 @@  discard block
 block discarded – undo
1135 1135
 
1136 1136
 				$displayed_lessons = array();
1137 1137
 
1138
-                $modules = Sensei()->modules->get_course_modules( intval( $course_id ) );
1139
-
1140
-                foreach( $modules as $module ) {
1141
-
1142
-                    $args = array(
1143
-                        'post_type' => 'lesson',
1144
-                        'post_status' => 'publish',
1145
-                        'posts_per_page' => -1,
1146
-                        'meta_query' => array(
1147
-                            array(
1148
-                                'key' => '_lesson_course',
1149
-                                'value' => intval( $course_id ),
1150
-                                'compare' => '='
1151
-                            )
1152
-                        ),
1153
-                        'tax_query' => array(
1154
-                            array(
1155
-                                'taxonomy' => Sensei()->modules->taxonomy,
1156
-                                'field' => 'id',
1157
-                                'terms' => intval( $module->term_id )
1158
-                            )
1159
-                        ),
1160
-                        'meta_key' => '_order_module_' . $module->term_id,
1161
-                        'orderby' => 'meta_value_num date',
1162
-                        'order' => 'ASC',
1163
-                        'suppress_filters' => 0
1164
-                    );
1165
-
1166
-                    $lessons = get_posts( $args );
1167
-
1168
-                    if( count( $lessons ) > 0 ) {
1169
-                        $html .= '<h3>' . $module->name . '</h3>' . "\n";
1170
-                        $html .= '<ul class="sortable-lesson-list" data-module_id="' . $module->term_id . '">' . "\n";
1171
-
1172
-                        $count = 0;
1173
-                        foreach( $lessons as $lesson ) {
1174
-                            $count++;
1175
-                            $class = 'lesson';
1176
-                            if ( $count == 1 ) { $class .= ' first'; }
1177
-                            if ( $count == count( $lesson ) ) { $class .= ' last'; }
1178
-                            if ( $count % 2 != 0 ) {
1179
-                                $class .= ' alternate';
1180
-                            }
1181
-
1182
-                            $html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $lesson->ID ) . '" style="width: 100%;"> ' . $lesson->post_title . '</span></li>' . "\n";
1183
-
1184
-                            $displayed_lessons[] = $lesson->ID;
1185
-                        }
1186
-
1187
-                        $html .= '</ul>' . "\n";
1188
-
1189
-                        $html .= '<input type="hidden" name="lesson-order-module-' . $module->term_id . '" value="" />' . "\n";
1190
-                    }
1191
-                }
1192
-
1193
-
1194
-                $lessons = Sensei()->course->course_lessons( $course_id );
1138
+				$modules = Sensei()->modules->get_course_modules( intval( $course_id ) );
1139
+
1140
+				foreach( $modules as $module ) {
1141
+
1142
+					$args = array(
1143
+						'post_type' => 'lesson',
1144
+						'post_status' => 'publish',
1145
+						'posts_per_page' => -1,
1146
+						'meta_query' => array(
1147
+							array(
1148
+								'key' => '_lesson_course',
1149
+								'value' => intval( $course_id ),
1150
+								'compare' => '='
1151
+							)
1152
+						),
1153
+						'tax_query' => array(
1154
+							array(
1155
+								'taxonomy' => Sensei()->modules->taxonomy,
1156
+								'field' => 'id',
1157
+								'terms' => intval( $module->term_id )
1158
+							)
1159
+						),
1160
+						'meta_key' => '_order_module_' . $module->term_id,
1161
+						'orderby' => 'meta_value_num date',
1162
+						'order' => 'ASC',
1163
+						'suppress_filters' => 0
1164
+					);
1165
+
1166
+					$lessons = get_posts( $args );
1167
+
1168
+					if( count( $lessons ) > 0 ) {
1169
+						$html .= '<h3>' . $module->name . '</h3>' . "\n";
1170
+						$html .= '<ul class="sortable-lesson-list" data-module_id="' . $module->term_id . '">' . "\n";
1171
+
1172
+						$count = 0;
1173
+						foreach( $lessons as $lesson ) {
1174
+							$count++;
1175
+							$class = 'lesson';
1176
+							if ( $count == 1 ) { $class .= ' first'; }
1177
+							if ( $count == count( $lesson ) ) { $class .= ' last'; }
1178
+							if ( $count % 2 != 0 ) {
1179
+								$class .= ' alternate';
1180
+							}
1181
+
1182
+							$html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $lesson->ID ) . '" style="width: 100%;"> ' . $lesson->post_title . '</span></li>' . "\n";
1183
+
1184
+							$displayed_lessons[] = $lesson->ID;
1185
+						}
1186
+
1187
+						$html .= '</ul>' . "\n";
1188
+
1189
+						$html .= '<input type="hidden" name="lesson-order-module-' . $module->term_id . '" value="" />' . "\n";
1190
+					}
1191
+				}
1192
+
1193
+
1194
+				$lessons = Sensei()->course->course_lessons( $course_id );
1195 1195
 
1196 1196
 				if( 0 < count( $lessons ) ) {
1197 1197
 
1198
-                    //get module term ids, will be used to exclude lessons
1199
-                    $module_items_ids = array();
1200
-                    if( ! empty( $modules ) ) {
1201
-                        foreach ($modules as $module) {
1202
-                            $module_items_ids[] = $module->term_id;
1203
-                        }
1204
-                    }
1198
+					//get module term ids, will be used to exclude lessons
1199
+					$module_items_ids = array();
1200
+					if( ! empty( $modules ) ) {
1201
+						foreach ($modules as $module) {
1202
+							$module_items_ids[] = $module->term_id;
1203
+						}
1204
+					}
1205 1205
 
1206 1206
 					if( 0 < count( $displayed_lessons ) ) {
1207 1207
 						$html .= '<h3>' . __( 'Other Lessons', 'woothemes-sensei' ) . '</h3>' . "\n";
@@ -1211,13 +1211,13 @@  discard block
 block discarded – undo
1211 1211
 					$count = 0;
1212 1212
 					foreach ( $lessons as $lesson ) {
1213 1213
 
1214
-                        // if lesson belongs to one fo the course modules then exclude it here
1215
-                        // as it is listed above
1216
-                        if( has_term( $module_items_ids, 'module', $lesson->ID )  ){
1214
+						// if lesson belongs to one fo the course modules then exclude it here
1215
+						// as it is listed above
1216
+						if( has_term( $module_items_ids, 'module', $lesson->ID )  ){
1217 1217
 
1218
-                            continue;
1218
+							continue;
1219 1219
 
1220
-                        }
1220
+						}
1221 1221
 
1222 1222
 						$count++;
1223 1223
 						$class = 'lesson';
@@ -1261,28 +1261,28 @@  discard block
 block discarded – undo
1261 1261
 
1262 1262
 		if( $course_id ) {
1263 1263
 
1264
-            $modules = Sensei()->modules->get_course_modules( intval( $course_id ) );
1264
+			$modules = Sensei()->modules->get_course_modules( intval( $course_id ) );
1265 1265
 
1266
-            foreach( $modules as $module ) {
1266
+			foreach( $modules as $module ) {
1267 1267
 
1268 1268
 
1269
-                if( isset( $_POST[ 'lesson-order-module-' . $module->term_id ] )
1270
-                    && $_POST[ 'lesson-order-module-' . $module->term_id ] ) {
1269
+				if( isset( $_POST[ 'lesson-order-module-' . $module->term_id ] )
1270
+					&& $_POST[ 'lesson-order-module-' . $module->term_id ] ) {
1271 1271
 
1272
-                    $order = explode( ',', $_POST[ 'lesson-order-module-' . $module->term_id ] );
1273
-                    $i = 1;
1274
-                    foreach( $order as $lesson_id ) {
1272
+					$order = explode( ',', $_POST[ 'lesson-order-module-' . $module->term_id ] );
1273
+					$i = 1;
1274
+					foreach( $order as $lesson_id ) {
1275 1275
 
1276
-                        if( $lesson_id ) {
1277
-                            update_post_meta( $lesson_id, '_order_module_' . $module->term_id, $i );
1278
-                            ++$i;
1279
-                        }
1276
+						if( $lesson_id ) {
1277
+							update_post_meta( $lesson_id, '_order_module_' . $module->term_id, $i );
1278
+							++$i;
1279
+						}
1280 1280
 
1281
-                    }// end for each order
1281
+					}// end for each order
1282 1282
 
1283
-                }// end if
1283
+				}// end if
1284 1284
 
1285
-            } // end for each modules
1285
+			} // end for each modules
1286 1286
 
1287 1287
 
1288 1288
 			if( $order_string ) {
@@ -1365,47 +1365,47 @@  discard block
 block discarded – undo
1365 1365
 
1366 1366
 	/**
1367 1367
 	 * Adding admin notice if the current
1368
-     * installed theme is not compatible
1369
-     *
1368
+	 * installed theme is not compatible
1369
+	 *
1370 1370
 	 * @return void
1371 1371
 	 */
1372 1372
 	public function theme_compatibility_notices() {
1373 1373
 
1374
-        if( isset( $_GET['sensei_hide_notice'] ) ) {
1375
-        	switch( esc_attr( $_GET['sensei_hide_notice'] ) ) {
1374
+		if( isset( $_GET['sensei_hide_notice'] ) ) {
1375
+			switch( esc_attr( $_GET['sensei_hide_notice'] ) ) {
1376 1376
 				case 'menu_settings': add_user_meta( get_current_user_id(), 'sensei_hide_menu_settings_notice', true ); break;
1377 1377
 				case 'theme_check': add_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true ); break;
1378 1378
 			}
1379
-        }
1379
+		}
1380 1380
 
1381
-        // white list templates that are already support by default and do not show notice for them
1382
-        $template = get_option( 'template' );
1381
+		// white list templates that are already support by default and do not show notice for them
1382
+		$template = get_option( 'template' );
1383 1383
 
1384
-        $white_list = array(    'twentyeleven',
1385
-                                'twentytwelve',
1386
-                                'twentyfourteen',
1387
-                                'twentyfifteen',
1388
-                                'twentysixteen',
1389
-                                'storefront',
1390
-                                                );
1384
+		$white_list = array(    'twentyeleven',
1385
+								'twentytwelve',
1386
+								'twentyfourteen',
1387
+								'twentyfifteen',
1388
+								'twentysixteen',
1389
+								'storefront',
1390
+												);
1391 1391
 
1392
-        if ( in_array( $template, $white_list ) ) {
1392
+		if ( in_array( $template, $white_list ) ) {
1393 1393
 
1394
-            return;
1394
+			return;
1395 1395
 
1396
-        }
1396
+		}
1397 1397
 
1398
-        // don't show the notice if the user chose to hide it
1399
-        $hide_theme_check_notice = get_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true );
1400
-        if(  $hide_theme_check_notice ) {
1398
+		// don't show the notice if the user chose to hide it
1399
+		$hide_theme_check_notice = get_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true );
1400
+		if(  $hide_theme_check_notice ) {
1401 1401
 
1402
-            return;
1402
+			return;
1403 1403
 
1404
-        }
1404
+		}
1405 1405
 
1406
-        // show the notice for themes not supporting sensei
1407
-	    if ( ! current_theme_supports( 'sensei' ) ) {
1408
-            ?>
1406
+		// show the notice for themes not supporting sensei
1407
+		if ( ! current_theme_supports( 'sensei' ) ) {
1408
+			?>
1409 1409
 
1410 1410
             <div id="message" class="error sensei-message sensei-connect">
1411 1411
                     <p>
@@ -1441,7 +1441,7 @@  discard block
 block discarded – undo
1441 1441
 	public function reset_theme_check_notices() {
1442 1442
 		global $current_user;
1443 1443
 		wp_get_current_user();
1444
-        $user_id = $current_user->ID;
1444
+		$user_id = $current_user->ID;
1445 1445
 
1446 1446
 		delete_user_meta( $user_id, 'sensei_hide_theme_check_notice' );
1447 1447
 	}
@@ -1461,62 +1461,62 @@  discard block
 block discarded – undo
1461 1461
 		return $prevent_access;
1462 1462
 	}
1463 1463
 
1464
-    /**
1465
-     * Hooked onto admin_init. Listens for install_sensei_pages and skip_install_sensei_pages query args
1466
-     * on the sensei settings page.
1467
-     *
1468
-     * The function
1469
-     *
1470
-     * @since 1.8.7
1471
-     */
1472
-    public  static function install_pages(){
1464
+	/**
1465
+	 * Hooked onto admin_init. Listens for install_sensei_pages and skip_install_sensei_pages query args
1466
+	 * on the sensei settings page.
1467
+	 *
1468
+	 * The function
1469
+	 *
1470
+	 * @since 1.8.7
1471
+	 */
1472
+	public  static function install_pages(){
1473 1473
 
1474
-        // only fire on the settings page
1475
-        if( ! isset( $_GET['page'] )
1476
-            || 'woothemes-sensei-settings' != $_GET['page']
1477
-            || 1 == get_option('skip_install_sensei_pages') ){
1474
+		// only fire on the settings page
1475
+		if( ! isset( $_GET['page'] )
1476
+			|| 'woothemes-sensei-settings' != $_GET['page']
1477
+			|| 1 == get_option('skip_install_sensei_pages') ){
1478 1478
 
1479
-            return;
1479
+			return;
1480 1480
 
1481
-        }
1481
+		}
1482 1482
 
1483
-        // Install/page installer
1484
-        $install_complete = false;
1483
+		// Install/page installer
1484
+		$install_complete = false;
1485 1485
 
1486
-        // Add pages button
1487
-        $settings_url = '';
1488
-        if (isset($_GET['install_sensei_pages']) && $_GET['install_sensei_pages']) {
1486
+		// Add pages button
1487
+		$settings_url = '';
1488
+		if (isset($_GET['install_sensei_pages']) && $_GET['install_sensei_pages']) {
1489 1489
 
1490
-            Sensei()->admin->create_pages();
1490
+			Sensei()->admin->create_pages();
1491 1491
 
1492
-            update_option('skip_install_sensei_pages', 1);
1492
+			update_option('skip_install_sensei_pages', 1);
1493 1493
 
1494
-            $install_complete = true;
1495
-            $settings_url = remove_query_arg('install_sensei_pages');
1494
+			$install_complete = true;
1495
+			$settings_url = remove_query_arg('install_sensei_pages');
1496 1496
 
1497
-            // Skip button
1498
-        } elseif (isset($_GET['skip_install_sensei_pages']) && $_GET['skip_install_sensei_pages']) {
1497
+			// Skip button
1498
+		} elseif (isset($_GET['skip_install_sensei_pages']) && $_GET['skip_install_sensei_pages']) {
1499 1499
 
1500
-            update_option('skip_install_sensei_pages', 1);
1501
-            $install_complete = true;
1502
-            $settings_url = remove_query_arg('skip_install_sensei_pages');
1500
+			update_option('skip_install_sensei_pages', 1);
1501
+			$install_complete = true;
1502
+			$settings_url = remove_query_arg('skip_install_sensei_pages');
1503 1503
 
1504
-        }
1504
+		}
1505 1505
 
1506
-        if ($install_complete) {
1506
+		if ($install_complete) {
1507 1507
 
1508
-            // refresh the rewrite rules on init
1509
-            update_option('sensei_flush_rewrite_rules', '1');
1508
+			// refresh the rewrite rules on init
1509
+			update_option('sensei_flush_rewrite_rules', '1');
1510 1510
 
1511
-            // Set installed option
1512
-            update_option('sensei_installed', 0);
1511
+			// Set installed option
1512
+			update_option('sensei_installed', 0);
1513 1513
 
1514
-            $complete_url = add_query_arg( 'sensei_install_complete', 'true', $settings_url  );
1515
-            wp_redirect( $complete_url );
1514
+			$complete_url = add_query_arg( 'sensei_install_complete', 'true', $settings_url  );
1515
+			wp_redirect( $complete_url );
1516 1516
 
1517
-        }
1517
+		}
1518 1518
 
1519
-    }// end install_pages
1519
+	}// end install_pages
1520 1520
 
1521 1521
 } // End Class
1522 1522
 
Please login to merge, or discard this patch.
includes/class-sensei-settings-api.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function register_hook_listener() {
59 59
 
60
-        add_action( 'admin_menu', array( $this, 'register_settings_screen' ), 60 );
60
+		add_action( 'admin_menu', array( $this, 'register_settings_screen' ), 60 );
61 61
 		add_action( 'admin_init', array( $this, 'settings_fields' ) );
62
-        add_action( 'init', array( $this, 'general_init' ), 5 );
62
+		add_action( 'init', array( $this, 'general_init' ), 5 );
63 63
 
64 64
 	} // End setup_settings()
65 65
 
@@ -293,14 +293,14 @@  discard block
 block discarded – undo
293 293
 	 * @return void
294 294
 	 */
295 295
 	public function settings_screen ()
296
-    {
296
+	{
297 297
 
298
-        ?>
298
+		?>
299 299
         <div id="woothemes-sensei" class="wrap <?php echo esc_attr($this->token); ?>">
300 300
         <?php screen_icon('woothemes-sensei'); ?>
301 301
         <h2><?php echo esc_html($this->name); ?><?php if ('' != $this->settings_version) {
302
-                echo ' <span class="version">' . $this->settings_version . '</span>';
303
-            } ?></h2>
302
+				echo ' <span class="version">' . $this->settings_version . '</span>';
303
+			} ?></h2>
304 304
         <p class="powered-by-woo"><?php _e('Powered by', 'woothemes-sensei'); ?><a href="http://www.woothemes.com/"
305 305
                                                                                    title="WooThemes"><img
306 306
                     src="<?php echo Sensei()->plugin_url; ?>assets/images/woothemes.png" alt="WooThemes"/></a></p>
@@ -308,26 +308,26 @@  discard block
 block discarded – undo
308 308
         <form action="options.php" method="post">
309 309
 
310 310
         <?php
311
-        $this->settings_tabs();
312
-        settings_fields($this->token);
313
-        $page = 'woothemes-sensei-settings';
314
-        foreach ($this->sections as $section_id => $section) {
311
+		$this->settings_tabs();
312
+		settings_fields($this->token);
313
+		$page = 'woothemes-sensei-settings';
314
+		foreach ($this->sections as $section_id => $section) {
315 315
 
316
-            echo '<section id="' . $section_id . '">';
316
+			echo '<section id="' . $section_id . '">';
317 317
 
318
-            if ($section['name'])
319
-                echo "<h2>{$section['name']}</h2>\n";
318
+			if ($section['name'])
319
+				echo "<h2>{$section['name']}</h2>\n";
320 320
 
321
-            echo '<table class="form-table">';
322
-            do_settings_fields($page, $section_id );
323
-            echo '</table>';
321
+			echo '<table class="form-table">';
322
+			do_settings_fields($page, $section_id );
323
+			echo '</table>';
324 324
 
325
-            echo '</section>';
325
+			echo '</section>';
326 326
 
327
-        }
327
+		}
328 328
 
329
-        submit_button();
330
-        ?>
329
+		submit_button();
330
+		?>
331 331
 	</form>
332 332
 	<?php do_action( 'settings_after_form' ); ?>
333 333
 </div><!--/#woothemes-sensei-->
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 	 */
343 343
 	public function get_settings () {
344 344
 
345
-        $this->settings = get_option( $this->token, array() );
345
+		$this->settings = get_option( $this->token, array() );
346 346
 
347 347
 		foreach ( $this->fields as $k => $v ) {
348 348
 			if ( ! isset( $this->settings[$k] ) && isset( $v['default'] ) ) {
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
 	 * @return void
376 376
 	 */
377 377
 	public function settings_errors () {
378
-        settings_errors( $this->token . '-errors' );
378
+		settings_errors( $this->token . '-errors' );
379 379
 	} // End settings_errors()
380 380
 
381 381
 	/**
@@ -441,9 +441,9 @@  discard block
 block discarded – undo
441 441
 		echo '<input id="' . $args['key'] . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" type="checkbox" value="1"' . checked( esc_attr( $options[$args['key']] ), '1', false ) . ' />' . "\n";
442 442
 		if ( $has_description ) {
443 443
 			echo wp_kses( $args['data']['description'], array( 'a' => array(
444
-																	        'href' => array(),
445
-																	        'title' => array()
446
-																	    )
444
+																			'href' => array(),
445
+																			'title' => array()
446
+																		)
447 447
 															)
448 448
 						) . '</label>' . "\n";
449 449
 		}
@@ -832,7 +832,7 @@  discard block
 block discarded – undo
832 832
 	 */
833 833
 	public function enqueue_scripts () {
834 834
 
835
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
835
+		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
836 836
 
837 837
 		wp_enqueue_script( 'farbtastic' );
838 838
 		wp_enqueue_script( 'woothemes-sensei-settings', esc_url( Sensei()->plugin_url . 'assets/js/settings' . $suffix . '.js' ), array( 'jquery', 'farbtastic' ), Sensei()->version );
Please login to merge, or discard this patch.
includes/class-sensei-modules.php 1 patch
Indentation   +1888 added lines, -1888 removed lines patch added patch discarded remove patch
@@ -14,265 +14,265 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class Sensei_Core_Modules
16 16
 {
17
-    private $dir;
18
-    private $file;
19
-    private $assets_dir;
20
-    private $assets_url;
21
-    private $order_page_slug;
22
-    public $taxonomy;
23
-
24
-    public function __construct( $file )
25
-    {
26
-        $this->file = $file;
27
-        $this->dir = dirname($this->file);
28
-        $this->assets_dir = trailingslashit($this->dir) . 'assets';
29
-        $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file)));
30
-        $this->taxonomy = 'module';
31
-        $this->order_page_slug = 'module-order';
32
-
33
-        // setup taxonomy
34
-        add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 );
35
-
36
-        // Manage lesson meta boxes for taxonomy
37
-        add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 );
38
-
39
-        // Save lesson meta box
40
-        add_action('save_post', array($this, 'save_lesson_module'), 10, 1);
41
-
42
-        //Reset the none modules lessons transient
43
-        add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) );
44
-
45
-        // Frontend styling
46
-        add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
47
-
48
-        // Admin styling
49
-        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles'));
50
-        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'),  20 , 2 );
51
-
52
-        // Handle module completion record
53
-        add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3);
54
-        add_action('sensei_user_lesson_reset', array($this, 'save_lesson_module_progress'), 10, 2);
55
-        add_action('wp', array($this, 'save_module_progress'), 10);
56
-
57
-        // Handle module ordering
58
-        add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 );
59
-        add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1);
60
-        add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2);
61
-
62
-        // Ensure modules always show under courses
63
-        add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 );
64
-        add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 );
65
-        add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 );
66
-
67
-        // Add course field to taxonomy
68
-        add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1);
69
-        add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1);
70
-        add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
71
-        add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
72
-        add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json'));
73
-
74
-        // Manage module taxonomy archive page
75
-        add_filter('template_include', array($this, 'module_archive_template'), 10);
76
-        add_action('pre_get_posts', array($this, 'module_archive_filter'), 10, 1);
77
-        add_filter('sensei_lessons_archive_text', array($this, 'module_archive_title'));
78
-        add_action('sensei_content_lesson_inside_before', array($this, 'module_archive_description'), 11);
79
-        add_action('sensei_pagination', array($this, 'module_navigation_links'), 11);
80
-        add_filter('body_class', array($this, 'module_archive_body_class'));
81
-
82
-        // add modules to the single course template
83
-        add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 );
84
-
85
-        //Single Course modules actions. Add to single-course/course-modules.php
86
-        add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20);
87
-
88
-        // Set up display on single lesson page
89
-        add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2);
90
-
91
-        // Add 'Modules' columns to Analysis tables
92
-        add_filter('sensei_analysis_overview_columns', array($this, 'analysis_overview_column_title'), 10, 2);
93
-        add_filter('sensei_analysis_overview_column_data', array($this, 'analysis_overview_column_data'), 10, 3);
94
-        add_filter('sensei_analysis_course_columns', array($this, 'analysis_course_column_title'), 10, 2);
95
-        add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3);
96
-
97
-        // Manage module taxonomy columns
98
-        add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1);
99
-        add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3);
100
-        add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2);
101
-
102
-        //store new modules created on the course edit screen
103
-        add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) );
104
-
105
-        // for non admin users, only show taxonomies that belong to them
106
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
107
-        add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 );
108
-
109
-        // add the teacher name next to the module term in for admin users
110
-        add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 );
111
-
112
-        // remove the default modules  metabox
113
-        add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' ));
114
-
115
-    } // end constructor
116
-
117
-    /**
118
-     * Alter a module term slug when a new taxonomy term is created
119
-     * This will add the creators user name to the slug for uniqueness.
120
-     *
121
-     * @since 1.8.0
122
-     *
123
-     * @param $term_id
124
-     * @param $tt_id
125
-     * @param $taxonomy
126
-     *
127
-     * @return void
128
-     * @deprecated since 1.9.0
129
-     */
130
-    public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){
131
-
132
-        _deprecated_function('change_module_term_slug', '1.9.0' );
133
-
134
-    }// end add_module_term_group
135
-
136
-    /**
137
-     * Hook in all meta boxes related tot he modules taxonomy
138
-     *
139
-     * @since 1.8.0
140
-     *
141
-     * @param string $post_type
142
-     * @param WP_Post $post
143
-     *
144
-     * @return void
145
-     */
146
-    public function modules_metaboxes( $post_type, $post )
147
-    {
148
-        if ('lesson' == $post_type ) {
149
-
150
-            // Remove default taxonomy meta box from Lesson edit screen
151
-            remove_meta_box($this->taxonomy . 'div', 'lesson', 'side');
152
-
153
-            // Add custom meta box to limit module selection to one per lesson
154
-            add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default');
155
-        }
156
-
157
-        if( 'course' == $post_type ){
158
-            // Course modules selection metabox
159
-            add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core');
160
-        }
161
-    }
162
-
163
-    /**
164
-     * Build content for custom module meta box
165
-     *
166
-     * @since 1.8.0
167
-     * @param  object $post Current post object
168
-     * @return void
169
-     */
170
-    public function lesson_module_metabox($post)
171
-    {
172
-
173
-        // Get lesson course
174
-        $lesson_course = get_post_meta($post->ID, '_lesson_course', true);
175
-
176
-        $html = '';
177
-
178
-        // Only show module selection if this lesson is part of a course
179
-        if ($lesson_course && $lesson_course > 0) {
180
-
181
-            // Get existing lesson module
182
-            $lesson_module = 0;
183
-            $lesson_module_list = wp_get_post_terms($post->ID, $this->taxonomy);
184
-            if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
185
-                foreach ($lesson_module_list as $single_module) {
186
-                    $lesson_module = $single_module->term_id;
187
-                    break;
188
-                }
189
-            }
190
-
191
-            // Get the available modules for this lesson's course
192
-            $modules = $this->get_course_modules($lesson_course);
193
-
194
-            // Build the HTML to output
195
-            $html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />';
196
-            if (is_array($modules) && count($modules) > 0) {
197
-                $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n";
198
-                $html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
199
-                foreach ($modules as $module) {
200
-                    $html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n";
201
-                }
202
-                $html .= '</select>' . "\n";
203
-            } else {
204
-                $course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit');
205
-                $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>';
206
-            } // End If Statement
207
-
208
-        } else {
209
-            $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>';
210
-        } // End If Statement
211
-
212
-        // Output the HTML
213
-        echo $html;
214
-    }
215
-
216
-    /**
217
-     * Save module to lesson
218
-     *
219
-     * @since 1.8.0
220
-     * @param  integer $post_id ID of post
221
-     * @return mixed            Post ID on permissions failure, boolean true on success
222
-     */
223
-    public function save_lesson_module($post_id)
224
-    {
225
-        global $post;
226
-
227
-        // Verify post type and nonce
228
-        if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] )
229
-            ||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) {
230
-            return $post_id;
231
-        }
232
-
233
-        // Check if user has permissions to edit lessons
234
-        $post_type = get_post_type_object($post->post_type);
235
-        if (!current_user_can($post_type->cap->edit_post, $post_id)) {
236
-            return $post_id;
237
-        }
238
-
239
-        // Check if user has permissions to edit this specific post
240
-        if (!current_user_can('edit_post', $post_id)) {
241
-            return $post_id;
242
-        }
243
-
244
-        // Cast module ID as an integer if selected, otherwise leave as empty string
245
-        if ( isset( $_POST['lesson_module'] ) ) {
246
-
247
-            if( empty ( $_POST['lesson_module'] ) ){
248
-                wp_delete_object_term_relationships($post_id, $this->taxonomy  );
249
-                return true;
250
-            }
251
-
252
-            $module_id = intval( $_POST['lesson_module'] );
253
-
254
-            // Assign lesson to selected module
255
-            wp_set_object_terms($post_id, $module_id, $this->taxonomy, false);
256
-
257
-            // Set default order for lesson inside module
258
-            if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) {
259
-                update_post_meta($post_id, '_order_module_' . $module_id, 0);
260
-            }
261
-        }
262
-
263
-        return true;
264
-    }
265
-
266
-    /**
267
-     * Display course field on new module screen
268
-     *
269
-     * @since 1.8.0
270
-     * @param object $taxonomy Taxonomy object
271
-     * @return void
272
-     */
273
-    public function add_module_fields($taxonomy)
274
-    {
275
-        ?>
17
+	private $dir;
18
+	private $file;
19
+	private $assets_dir;
20
+	private $assets_url;
21
+	private $order_page_slug;
22
+	public $taxonomy;
23
+
24
+	public function __construct( $file )
25
+	{
26
+		$this->file = $file;
27
+		$this->dir = dirname($this->file);
28
+		$this->assets_dir = trailingslashit($this->dir) . 'assets';
29
+		$this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file)));
30
+		$this->taxonomy = 'module';
31
+		$this->order_page_slug = 'module-order';
32
+
33
+		// setup taxonomy
34
+		add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 );
35
+
36
+		// Manage lesson meta boxes for taxonomy
37
+		add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 );
38
+
39
+		// Save lesson meta box
40
+		add_action('save_post', array($this, 'save_lesson_module'), 10, 1);
41
+
42
+		//Reset the none modules lessons transient
43
+		add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) );
44
+
45
+		// Frontend styling
46
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
47
+
48
+		// Admin styling
49
+		add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles'));
50
+		add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'),  20 , 2 );
51
+
52
+		// Handle module completion record
53
+		add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3);
54
+		add_action('sensei_user_lesson_reset', array($this, 'save_lesson_module_progress'), 10, 2);
55
+		add_action('wp', array($this, 'save_module_progress'), 10);
56
+
57
+		// Handle module ordering
58
+		add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 );
59
+		add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1);
60
+		add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2);
61
+
62
+		// Ensure modules always show under courses
63
+		add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 );
64
+		add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 );
65
+		add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 );
66
+
67
+		// Add course field to taxonomy
68
+		add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1);
69
+		add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1);
70
+		add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
71
+		add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
72
+		add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json'));
73
+
74
+		// Manage module taxonomy archive page
75
+		add_filter('template_include', array($this, 'module_archive_template'), 10);
76
+		add_action('pre_get_posts', array($this, 'module_archive_filter'), 10, 1);
77
+		add_filter('sensei_lessons_archive_text', array($this, 'module_archive_title'));
78
+		add_action('sensei_content_lesson_inside_before', array($this, 'module_archive_description'), 11);
79
+		add_action('sensei_pagination', array($this, 'module_navigation_links'), 11);
80
+		add_filter('body_class', array($this, 'module_archive_body_class'));
81
+
82
+		// add modules to the single course template
83
+		add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 );
84
+
85
+		//Single Course modules actions. Add to single-course/course-modules.php
86
+		add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20);
87
+
88
+		// Set up display on single lesson page
89
+		add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2);
90
+
91
+		// Add 'Modules' columns to Analysis tables
92
+		add_filter('sensei_analysis_overview_columns', array($this, 'analysis_overview_column_title'), 10, 2);
93
+		add_filter('sensei_analysis_overview_column_data', array($this, 'analysis_overview_column_data'), 10, 3);
94
+		add_filter('sensei_analysis_course_columns', array($this, 'analysis_course_column_title'), 10, 2);
95
+		add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3);
96
+
97
+		// Manage module taxonomy columns
98
+		add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1);
99
+		add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3);
100
+		add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2);
101
+
102
+		//store new modules created on the course edit screen
103
+		add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) );
104
+
105
+		// for non admin users, only show taxonomies that belong to them
106
+		add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
107
+		add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 );
108
+
109
+		// add the teacher name next to the module term in for admin users
110
+		add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 );
111
+
112
+		// remove the default modules  metabox
113
+		add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' ));
114
+
115
+	} // end constructor
116
+
117
+	/**
118
+	 * Alter a module term slug when a new taxonomy term is created
119
+	 * This will add the creators user name to the slug for uniqueness.
120
+	 *
121
+	 * @since 1.8.0
122
+	 *
123
+	 * @param $term_id
124
+	 * @param $tt_id
125
+	 * @param $taxonomy
126
+	 *
127
+	 * @return void
128
+	 * @deprecated since 1.9.0
129
+	 */
130
+	public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){
131
+
132
+		_deprecated_function('change_module_term_slug', '1.9.0' );
133
+
134
+	}// end add_module_term_group
135
+
136
+	/**
137
+	 * Hook in all meta boxes related tot he modules taxonomy
138
+	 *
139
+	 * @since 1.8.0
140
+	 *
141
+	 * @param string $post_type
142
+	 * @param WP_Post $post
143
+	 *
144
+	 * @return void
145
+	 */
146
+	public function modules_metaboxes( $post_type, $post )
147
+	{
148
+		if ('lesson' == $post_type ) {
149
+
150
+			// Remove default taxonomy meta box from Lesson edit screen
151
+			remove_meta_box($this->taxonomy . 'div', 'lesson', 'side');
152
+
153
+			// Add custom meta box to limit module selection to one per lesson
154
+			add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default');
155
+		}
156
+
157
+		if( 'course' == $post_type ){
158
+			// Course modules selection metabox
159
+			add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core');
160
+		}
161
+	}
162
+
163
+	/**
164
+	 * Build content for custom module meta box
165
+	 *
166
+	 * @since 1.8.0
167
+	 * @param  object $post Current post object
168
+	 * @return void
169
+	 */
170
+	public function lesson_module_metabox($post)
171
+	{
172
+
173
+		// Get lesson course
174
+		$lesson_course = get_post_meta($post->ID, '_lesson_course', true);
175
+
176
+		$html = '';
177
+
178
+		// Only show module selection if this lesson is part of a course
179
+		if ($lesson_course && $lesson_course > 0) {
180
+
181
+			// Get existing lesson module
182
+			$lesson_module = 0;
183
+			$lesson_module_list = wp_get_post_terms($post->ID, $this->taxonomy);
184
+			if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
185
+				foreach ($lesson_module_list as $single_module) {
186
+					$lesson_module = $single_module->term_id;
187
+					break;
188
+				}
189
+			}
190
+
191
+			// Get the available modules for this lesson's course
192
+			$modules = $this->get_course_modules($lesson_course);
193
+
194
+			// Build the HTML to output
195
+			$html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />';
196
+			if (is_array($modules) && count($modules) > 0) {
197
+				$html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n";
198
+				$html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
199
+				foreach ($modules as $module) {
200
+					$html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n";
201
+				}
202
+				$html .= '</select>' . "\n";
203
+			} else {
204
+				$course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit');
205
+				$html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>';
206
+			} // End If Statement
207
+
208
+		} else {
209
+			$html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>';
210
+		} // End If Statement
211
+
212
+		// Output the HTML
213
+		echo $html;
214
+	}
215
+
216
+	/**
217
+	 * Save module to lesson
218
+	 *
219
+	 * @since 1.8.0
220
+	 * @param  integer $post_id ID of post
221
+	 * @return mixed            Post ID on permissions failure, boolean true on success
222
+	 */
223
+	public function save_lesson_module($post_id)
224
+	{
225
+		global $post;
226
+
227
+		// Verify post type and nonce
228
+		if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] )
229
+			||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) {
230
+			return $post_id;
231
+		}
232
+
233
+		// Check if user has permissions to edit lessons
234
+		$post_type = get_post_type_object($post->post_type);
235
+		if (!current_user_can($post_type->cap->edit_post, $post_id)) {
236
+			return $post_id;
237
+		}
238
+
239
+		// Check if user has permissions to edit this specific post
240
+		if (!current_user_can('edit_post', $post_id)) {
241
+			return $post_id;
242
+		}
243
+
244
+		// Cast module ID as an integer if selected, otherwise leave as empty string
245
+		if ( isset( $_POST['lesson_module'] ) ) {
246
+
247
+			if( empty ( $_POST['lesson_module'] ) ){
248
+				wp_delete_object_term_relationships($post_id, $this->taxonomy  );
249
+				return true;
250
+			}
251
+
252
+			$module_id = intval( $_POST['lesson_module'] );
253
+
254
+			// Assign lesson to selected module
255
+			wp_set_object_terms($post_id, $module_id, $this->taxonomy, false);
256
+
257
+			// Set default order for lesson inside module
258
+			if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) {
259
+				update_post_meta($post_id, '_order_module_' . $module_id, 0);
260
+			}
261
+		}
262
+
263
+		return true;
264
+	}
265
+
266
+	/**
267
+	 * Display course field on new module screen
268
+	 *
269
+	 * @since 1.8.0
270
+	 * @param object $taxonomy Taxonomy object
271
+	 * @return void
272
+	 */
273
+	public function add_module_fields($taxonomy)
274
+	{
275
+		?>
276 276
         <div class="form-field">
277 277
             <label for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label>
278 278
             <input type="hidden" id="module_courses" name="module_courses" class="ajax_chosen_select_courses"
@@ -281,44 +281,44 @@  discard block
 block discarded – undo
281 281
                 class="description"><?php _e('Search for and select the courses that this module will belong to.', 'woothemes-sensei'); ?></span>
282 282
         </div>
283 283
     <?php
284
-    }
285
-
286
-    /**
287
-     * Display course field on module edit screen
288
-     *
289
-     * @since 1.8.0
290
-     * @param  object $module Module term object
291
-     * @return void
292
-     */
293
-    public function edit_module_fields($module)
294
-    {
295
-
296
-        $module_id = $module->term_id;
297
-
298
-        // Get module's existing courses
299
-        $args = array(
300
-            'post_type' => 'course',
301
-            'post_status' => array('publish', 'draft', 'future', 'private'),
302
-            'posts_per_page' => -1,
303
-            'tax_query' => array(
304
-                array(
305
-                    'taxonomy' => $this->taxonomy,
306
-                    'field' => 'id',
307
-                    'terms' => $module_id
308
-                )
309
-            )
310
-        );
311
-        $courses = get_posts($args);
312
-
313
-        //build the defaults array
314
-        $module_courses = array();
315
-        if (isset($courses) && is_array($courses)) {
316
-            foreach ($courses as $course) {
317
-                $module_courses[] =   array( 'id' =>$course->ID, 'details'=>$course->post_title );
318
-            }
319
-        }
320
-
321
-        ?>
284
+	}
285
+
286
+	/**
287
+	 * Display course field on module edit screen
288
+	 *
289
+	 * @since 1.8.0
290
+	 * @param  object $module Module term object
291
+	 * @return void
292
+	 */
293
+	public function edit_module_fields($module)
294
+	{
295
+
296
+		$module_id = $module->term_id;
297
+
298
+		// Get module's existing courses
299
+		$args = array(
300
+			'post_type' => 'course',
301
+			'post_status' => array('publish', 'draft', 'future', 'private'),
302
+			'posts_per_page' => -1,
303
+			'tax_query' => array(
304
+				array(
305
+					'taxonomy' => $this->taxonomy,
306
+					'field' => 'id',
307
+					'terms' => $module_id
308
+				)
309
+			)
310
+		);
311
+		$courses = get_posts($args);
312
+
313
+		//build the defaults array
314
+		$module_courses = array();
315
+		if (isset($courses) && is_array($courses)) {
316
+			foreach ($courses as $course) {
317
+				$module_courses[] =   array( 'id' =>$course->ID, 'details'=>$course->post_title );
318
+			}
319
+		}
320
+
321
+		?>
322 322
         <tr class="form-field">
323 323
             <th scope="row" valign="top"><label
324 324
                     for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label></th>
@@ -335,1405 +335,1405 @@  discard block
 block discarded – undo
335 335
             </td>
336 336
         </tr>
337 337
     <?php
338
-    }
339
-
340
-    /**
341
-     * Save module course on add/edit
342
-     *
343
-     * @since 1.8.0
344
-     * @param  integer $module_id ID of module
345
-     * @return void
346
-     */
347
-    public function save_module_course($module_id)
348
-    {
349
-
350
-        // Get module's existing courses
351
-        $args = array(
352
-            'post_type' => 'course',
353
-            'post_status' => array('publish', 'draft', 'future', 'private'),
354
-            'posts_per_page' => -1,
355
-            'tax_query' => array(
356
-                array(
357
-                    'taxonomy' => $this->taxonomy,
358
-                    'field' => 'id',
359
-                    'terms' => $module_id
360
-                )
361
-            )
362
-        );
363
-        $courses = get_posts($args);
364
-
365
-        // Remove module from existing courses
366
-        if (isset($courses) && is_array($courses)) {
367
-            foreach ($courses as $course) {
368
-                wp_remove_object_terms($course->ID, $module_id, $this->taxonomy);
369
-            }
370
-        }
371
-
372
-        // Add module to selected courses
373
-        if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) {
374
-
375
-            $course_ids = explode( ",", $_POST['module_courses'] );
376
-
377
-            foreach ( $course_ids as $course_id ) {
378
-
379
-                wp_set_object_terms($course_id, $module_id, $this->taxonomy, true);
380
-
381
-            }
382
-        }
383
-    }
384
-
385
-    /**
386
-     * Ajax function to search for courses matching term
387
-     *
388
-     * @since 1.8.0
389
-     * @return void
390
-     */
391
-    public function search_courses_json()
392
-    {
393
-
394
-        // Security check
395
-        check_ajax_referer('search-courses', 'security');
396
-
397
-        // Set content type
398
-        header('Content-Type: application/json; charset=utf-8');
399
-
400
-        // Get user input
401
-        $term = urldecode(stripslashes($_GET['term']));
402
-
403
-        // Return nothing if term is empty
404
-        if (empty($term))
405
-            die();
406
-
407
-        // Set a default if none is given
408
-        $default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei');
409
-
410
-        // Set up array of results
411
-        $found_courses = array('' => $default);
412
-
413
-        // Fetch results
414
-        $args = array(
415
-            'post_type' => 'course',
416
-            'post_status' => array('publish', 'draft', 'future', 'private'),
417
-            'posts_per_page' => -1,
418
-            'orderby' => 'title',
419
-            's' => $term
420
-        );
421
-        $courses = get_posts($args);
422
-
423
-        // Add results to array
424
-        if ($courses) {
425
-            foreach ($courses as $course) {
426
-                $found_courses[$course->ID] = $course->post_title;
427
-            }
428
-        }
429
-
430
-        // Encode and return results for processing & selection
431
-        echo json_encode($found_courses);
432
-        die();
433
-    }
434
-
435
-    /**
436
-     * display modules on single course pages
437
-     *
438
-     * @since 1.8.0
439
-     * @return void
440
-     */
441
-    public function single_course_modules(){
442
-
443
-        _deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
444
-        // only show modules on the course that has modules
445
-        if( is_singular( 'course' ) && has_term( '', 'module' )  )  {
446
-
447
-            $this->load_course_module_content_template();
448
-
449
-        }
450
-
451
-    } // end single_course_modules
452
-
453
-    public function sensei_course_preview_titles($title, $lesson_id)
454
-    {
455
-        global $post, $current_user;
456
-
457
-        $course_id = $post->ID;
458
-        $title_text = '';
459
-
460
-        if (method_exists('Sensei_Utils', 'is_preview_lesson') && Sensei_Utils::is_preview_lesson($lesson_id)) {
461
-            $is_user_taking_course = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status'));
462
-            if (!$is_user_taking_course) {
463
-                if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) {
464
-                    $title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id);
465
-                    // Remove brackets for display here
466
-                    $title_text = str_replace('(', '', $title_text);
467
-                    $title_text = str_replace(')', '', $title_text);
468
-                    $title_text = '<span class="preview-label">' . $title_text . '</span>';
469
-                }
470
-                $title .= ' ' . $title_text;
471
-            }
472
-        }
473
-
474
-        return $title;
475
-    }
476
-
477
-    public function module_breadcrumb_link($html, $separator)
478
-    {
479
-        global $post;
480
-        // Lesson
481
-        if (is_singular('lesson')) {
482
-            if (has_term('', $this->taxonomy, $post->ID)) {
483
-                $module = $this->get_lesson_module($post->ID);
484
-                if( $module ) {
485
-                    $html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' .  __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>';
486
-                }
487
-            }
488
-        }
489
-        // Module
490
-        if (is_tax($this->taxonomy)) {
491
-            if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
492
-                $course_id = intval($_GET['course_id']);
493
-                $html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' .  __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>';
494
-            }
495
-        }
496
-        return $html;
497
-    }
498
-
499
-    /**
500
-     * Set lesson archive template to display on module taxonomy archive page
501
-     *
502
-     * @since 1.8.0
503
-     * @param  string $template Default template
504
-     * @return string           Modified template
505
-     */
506
-    public function module_archive_template($template) {
507
-
508
-        if ( ! is_tax($this->taxonomy) ) {
509
-            return $template;
510
-        }
511
-
512
-        $file = 'archive-lesson.php';
513
-        $find = array( $file, Sensei()->template_url . $file );
514
-
515
-        // locate the template file
516
-        $template = locate_template($find);
517
-        if (!$template) {
518
-
519
-            $template = Sensei()->plugin_path() . 'templates/' . $file;
520
-
521
-        }
522
-
523
-
524
-        return $template;
525
-    }
526
-
527
-    /**
528
-     * Modify module taxonomy archive query
529
-     *
530
-     * @since 1.8.0
531
-     * @param  object $query The query object passed by reference
532
-     * @return void
533
-     */
534
-    public function module_archive_filter($query)
535
-    {
536
-        if (is_tax($this->taxonomy) && $query->is_main_query()) {
537
-
538
-
539
-            // Limit to lessons only
540
-            $query->set('post_type', 'lesson');
541
-
542
-            // Set order of lessons
543
-            if (version_compare(Sensei()->version, '1.6.0', '>=')) {
544
-                $module_id = $query->queried_object_id;
545
-                $query->set('meta_key', '_order_module_' . $module_id);
546
-                $query->set('orderby', 'meta_value_num date');
547
-            } else {
548
-                $query->set('orderby', 'menu_order');
549
-            }
550
-            $query->set('order', 'ASC');
551
-
552
-            // Limit to specific course if specified
553
-            if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
554
-                $course_id = intval($_GET['course_id']);
555
-                $meta_query[] = array(
556
-                    'key' => '_lesson_course',
557
-                    'value' => intval($course_id)
558
-                );
559
-                $query->set('meta_query', $meta_query);
560
-            }
561
-
562
-        }
563
-    }
564
-
565
-    /**
566
-     * Modify archive page title
567
-     *
568
-     * @since 1.8.0
569
-     * @param  string $title Default title
570
-     * @return string        Modified title
571
-     */
572
-    public function module_archive_title($title)
573
-    {
574
-        if (is_tax($this->taxonomy)) {
575
-            $title = apply_filters('sensei_module_archive_title', get_queried_object()->name);
576
-        }
577
-        return $title;
578
-    }
579
-
580
-    /**
581
-     * Display module description on taxonomy archive page
582
-     *
583
-     * @since 1.8.0
584
-     * @return void
585
-     */
586
-    public function module_archive_description()
587
-    {
588
-        if (is_tax($this->taxonomy)) {
589
-
590
-            $module = get_queried_object();
591
-
592
-            $module_progress = false;
593
-            if (is_user_logged_in() && isset($_GET['course_id']) && intval($_GET['course_id']) > 0) {
594
-                global $current_user;
595
-                wp_get_current_user();
596
-                $module_progress = $this->get_user_module_progress($module->term_id, $_GET['course_id'], $current_user->ID);
597
-            }
598
-
599
-            if ($module_progress && $module_progress > 0) {
600
-                $status = __('Completed', 'woothemes-sensei');
601
-                $class = 'completed';
602
-                if ($module_progress < 100) {
603
-                    $status = __('In progress', 'woothemes-sensei');
604
-                    $class = 'in-progress';
605
-                }
606
-                echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>';
607
-            }
608
-
609
-            echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>';
610
-        }
611
-    }
612
-
613
-    public function module_archive_body_class($classes)
614
-    {
615
-        if (is_tax($this->taxonomy)) {
616
-            $classes[] = 'module-archive';
617
-        }
618
-        return $classes;
619
-    }
620
-
621
-    /**
622
-     * Display module navigation links on module taxonomy archive page
623
-     *
624
-     * @since 1.8.0
625
-     * @return void
626
-     */
627
-    public function module_navigation_links()
628
-    {
629
-        if (is_tax($this->taxonomy) && isset($_GET['course_id'])) {
630
-
631
-            $queried_module = get_queried_object();
632
-            $course_modules = $this->get_course_modules($_GET['course_id']);
633
-
634
-            $prev_module = false;
635
-            $next_module = false;
636
-            $on_current = false;
637
-            foreach ($course_modules as $module) {
638
-                $this_module = $module;
639
-                if ($on_current) {
640
-                    $next_module = $this_module;
641
-                    break;
642
-                }
643
-                if ($this_module == $queried_module) {
644
-                    $on_current = true;
645
-                } else {
646
-                    $prev_module = $module;
647
-                }
648
-            }
649
-
650
-            ?>
338
+	}
339
+
340
+	/**
341
+	 * Save module course on add/edit
342
+	 *
343
+	 * @since 1.8.0
344
+	 * @param  integer $module_id ID of module
345
+	 * @return void
346
+	 */
347
+	public function save_module_course($module_id)
348
+	{
349
+
350
+		// Get module's existing courses
351
+		$args = array(
352
+			'post_type' => 'course',
353
+			'post_status' => array('publish', 'draft', 'future', 'private'),
354
+			'posts_per_page' => -1,
355
+			'tax_query' => array(
356
+				array(
357
+					'taxonomy' => $this->taxonomy,
358
+					'field' => 'id',
359
+					'terms' => $module_id
360
+				)
361
+			)
362
+		);
363
+		$courses = get_posts($args);
364
+
365
+		// Remove module from existing courses
366
+		if (isset($courses) && is_array($courses)) {
367
+			foreach ($courses as $course) {
368
+				wp_remove_object_terms($course->ID, $module_id, $this->taxonomy);
369
+			}
370
+		}
371
+
372
+		// Add module to selected courses
373
+		if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) {
374
+
375
+			$course_ids = explode( ",", $_POST['module_courses'] );
376
+
377
+			foreach ( $course_ids as $course_id ) {
378
+
379
+				wp_set_object_terms($course_id, $module_id, $this->taxonomy, true);
380
+
381
+			}
382
+		}
383
+	}
384
+
385
+	/**
386
+	 * Ajax function to search for courses matching term
387
+	 *
388
+	 * @since 1.8.0
389
+	 * @return void
390
+	 */
391
+	public function search_courses_json()
392
+	{
393
+
394
+		// Security check
395
+		check_ajax_referer('search-courses', 'security');
396
+
397
+		// Set content type
398
+		header('Content-Type: application/json; charset=utf-8');
399
+
400
+		// Get user input
401
+		$term = urldecode(stripslashes($_GET['term']));
402
+
403
+		// Return nothing if term is empty
404
+		if (empty($term))
405
+			die();
406
+
407
+		// Set a default if none is given
408
+		$default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei');
409
+
410
+		// Set up array of results
411
+		$found_courses = array('' => $default);
412
+
413
+		// Fetch results
414
+		$args = array(
415
+			'post_type' => 'course',
416
+			'post_status' => array('publish', 'draft', 'future', 'private'),
417
+			'posts_per_page' => -1,
418
+			'orderby' => 'title',
419
+			's' => $term
420
+		);
421
+		$courses = get_posts($args);
422
+
423
+		// Add results to array
424
+		if ($courses) {
425
+			foreach ($courses as $course) {
426
+				$found_courses[$course->ID] = $course->post_title;
427
+			}
428
+		}
429
+
430
+		// Encode and return results for processing & selection
431
+		echo json_encode($found_courses);
432
+		die();
433
+	}
434
+
435
+	/**
436
+	 * display modules on single course pages
437
+	 *
438
+	 * @since 1.8.0
439
+	 * @return void
440
+	 */
441
+	public function single_course_modules(){
442
+
443
+		_deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
444
+		// only show modules on the course that has modules
445
+		if( is_singular( 'course' ) && has_term( '', 'module' )  )  {
446
+
447
+			$this->load_course_module_content_template();
448
+
449
+		}
450
+
451
+	} // end single_course_modules
452
+
453
+	public function sensei_course_preview_titles($title, $lesson_id)
454
+	{
455
+		global $post, $current_user;
456
+
457
+		$course_id = $post->ID;
458
+		$title_text = '';
459
+
460
+		if (method_exists('Sensei_Utils', 'is_preview_lesson') && Sensei_Utils::is_preview_lesson($lesson_id)) {
461
+			$is_user_taking_course = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status'));
462
+			if (!$is_user_taking_course) {
463
+				if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) {
464
+					$title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id);
465
+					// Remove brackets for display here
466
+					$title_text = str_replace('(', '', $title_text);
467
+					$title_text = str_replace(')', '', $title_text);
468
+					$title_text = '<span class="preview-label">' . $title_text . '</span>';
469
+				}
470
+				$title .= ' ' . $title_text;
471
+			}
472
+		}
473
+
474
+		return $title;
475
+	}
476
+
477
+	public function module_breadcrumb_link($html, $separator)
478
+	{
479
+		global $post;
480
+		// Lesson
481
+		if (is_singular('lesson')) {
482
+			if (has_term('', $this->taxonomy, $post->ID)) {
483
+				$module = $this->get_lesson_module($post->ID);
484
+				if( $module ) {
485
+					$html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' .  __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>';
486
+				}
487
+			}
488
+		}
489
+		// Module
490
+		if (is_tax($this->taxonomy)) {
491
+			if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
492
+				$course_id = intval($_GET['course_id']);
493
+				$html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' .  __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>';
494
+			}
495
+		}
496
+		return $html;
497
+	}
498
+
499
+	/**
500
+	 * Set lesson archive template to display on module taxonomy archive page
501
+	 *
502
+	 * @since 1.8.0
503
+	 * @param  string $template Default template
504
+	 * @return string           Modified template
505
+	 */
506
+	public function module_archive_template($template) {
507
+
508
+		if ( ! is_tax($this->taxonomy) ) {
509
+			return $template;
510
+		}
511
+
512
+		$file = 'archive-lesson.php';
513
+		$find = array( $file, Sensei()->template_url . $file );
514
+
515
+		// locate the template file
516
+		$template = locate_template($find);
517
+		if (!$template) {
518
+
519
+			$template = Sensei()->plugin_path() . 'templates/' . $file;
520
+
521
+		}
522
+
523
+
524
+		return $template;
525
+	}
526
+
527
+	/**
528
+	 * Modify module taxonomy archive query
529
+	 *
530
+	 * @since 1.8.0
531
+	 * @param  object $query The query object passed by reference
532
+	 * @return void
533
+	 */
534
+	public function module_archive_filter($query)
535
+	{
536
+		if (is_tax($this->taxonomy) && $query->is_main_query()) {
537
+
538
+
539
+			// Limit to lessons only
540
+			$query->set('post_type', 'lesson');
541
+
542
+			// Set order of lessons
543
+			if (version_compare(Sensei()->version, '1.6.0', '>=')) {
544
+				$module_id = $query->queried_object_id;
545
+				$query->set('meta_key', '_order_module_' . $module_id);
546
+				$query->set('orderby', 'meta_value_num date');
547
+			} else {
548
+				$query->set('orderby', 'menu_order');
549
+			}
550
+			$query->set('order', 'ASC');
551
+
552
+			// Limit to specific course if specified
553
+			if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
554
+				$course_id = intval($_GET['course_id']);
555
+				$meta_query[] = array(
556
+					'key' => '_lesson_course',
557
+					'value' => intval($course_id)
558
+				);
559
+				$query->set('meta_query', $meta_query);
560
+			}
561
+
562
+		}
563
+	}
564
+
565
+	/**
566
+	 * Modify archive page title
567
+	 *
568
+	 * @since 1.8.0
569
+	 * @param  string $title Default title
570
+	 * @return string        Modified title
571
+	 */
572
+	public function module_archive_title($title)
573
+	{
574
+		if (is_tax($this->taxonomy)) {
575
+			$title = apply_filters('sensei_module_archive_title', get_queried_object()->name);
576
+		}
577
+		return $title;
578
+	}
579
+
580
+	/**
581
+	 * Display module description on taxonomy archive page
582
+	 *
583
+	 * @since 1.8.0
584
+	 * @return void
585
+	 */
586
+	public function module_archive_description()
587
+	{
588
+		if (is_tax($this->taxonomy)) {
589
+
590
+			$module = get_queried_object();
591
+
592
+			$module_progress = false;
593
+			if (is_user_logged_in() && isset($_GET['course_id']) && intval($_GET['course_id']) > 0) {
594
+				global $current_user;
595
+				wp_get_current_user();
596
+				$module_progress = $this->get_user_module_progress($module->term_id, $_GET['course_id'], $current_user->ID);
597
+			}
598
+
599
+			if ($module_progress && $module_progress > 0) {
600
+				$status = __('Completed', 'woothemes-sensei');
601
+				$class = 'completed';
602
+				if ($module_progress < 100) {
603
+					$status = __('In progress', 'woothemes-sensei');
604
+					$class = 'in-progress';
605
+				}
606
+				echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>';
607
+			}
608
+
609
+			echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>';
610
+		}
611
+	}
612
+
613
+	public function module_archive_body_class($classes)
614
+	{
615
+		if (is_tax($this->taxonomy)) {
616
+			$classes[] = 'module-archive';
617
+		}
618
+		return $classes;
619
+	}
620
+
621
+	/**
622
+	 * Display module navigation links on module taxonomy archive page
623
+	 *
624
+	 * @since 1.8.0
625
+	 * @return void
626
+	 */
627
+	public function module_navigation_links()
628
+	{
629
+		if (is_tax($this->taxonomy) && isset($_GET['course_id'])) {
630
+
631
+			$queried_module = get_queried_object();
632
+			$course_modules = $this->get_course_modules($_GET['course_id']);
633
+
634
+			$prev_module = false;
635
+			$next_module = false;
636
+			$on_current = false;
637
+			foreach ($course_modules as $module) {
638
+				$this_module = $module;
639
+				if ($on_current) {
640
+					$next_module = $this_module;
641
+					break;
642
+				}
643
+				if ($this_module == $queried_module) {
644
+					$on_current = true;
645
+				} else {
646
+					$prev_module = $module;
647
+				}
648
+			}
649
+
650
+			?>
651 651
             <div id="post-entries" class="post-entries module-navigation fix">
652 652
                 <?php if ($next_module) {
653
-                    $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($next_module, $this->taxonomy));
654
-                    ?>
653
+					$module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($next_module, $this->taxonomy));
654
+					?>
655 655
                     <div class="nav-next fr"><a href="<?php echo esc_url($module_link); ?>"
656 656
                                                 title="<?php esc_attr_e('Next module', 'woothemes-sensei'); ?>"><?php echo $next_module->name; ?>
657 657
                             <span class="meta-nav"></span></a></div>
658 658
                 <?php } ?>
659 659
                 <?php if ($prev_module) {
660
-                    $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($prev_module, $this->taxonomy));
661
-                    ?>
660
+					$module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($prev_module, $this->taxonomy));
661
+					?>
662 662
                     <div class="nav-prev fl"><a href="<?php echo esc_url($module_link); ?>"
663 663
                                                 title="<?php _e('Previous module', 'woothemes-sensei'); ?>"><span
664 664
                                 class="meta-nav"></span> <?php echo $prev_module->name; ?></a></div>
665 665
                 <?php } ?>
666 666
             </div>
667 667
         <?php
668
-        }
669
-    }
670
-
671
-    /**
672
-     * Trigger save_lesson_module_progress() when a lesson status is updated for a specific user
673
-     *
674
-     * @since 1.8.0
675
-     * @param  string $status Status of the lesson for the user
676
-     * @param  integer $user_id ID of user
677
-     * @param  integer $lesson_id ID of lesson
678
-     * @return void
679
-     */
680
-    public function update_lesson_status_module_progress($status = '', $user_id = 0, $lesson_id = 0)
681
-    {
682
-        $this->save_lesson_module_progress($user_id, $lesson_id);
683
-    }
684
-
685
-    /**
686
-     * Save lesson's module progress for a specific user
687
-     *
688
-     * @since 1.8.0
689
-     * @param  integer $user_id ID of user
690
-     * @param  integer $lesson_id ID of lesson
691
-     * @return void
692
-     */
693
-    public function save_lesson_module_progress($user_id = 0, $lesson_id = 0)
694
-    {
695
-        $module = $this->get_lesson_module($lesson_id);
696
-        $course_id = get_post_meta($lesson_id, '_lesson_course', true);
697
-        if ($module && $course_id) {
698
-            $this->save_user_module_progress(intval($module->term_id), intval($course_id), intval($user_id));
699
-        }
700
-    }
701
-
702
-    /**
703
-     * Save progress of module for user
704
-     *
705
-     * @since 1.8.0
706
-     * @return void
707
-     */
708
-    public function save_module_progress()
709
-    {
710
-        if (is_tax($this->taxonomy) && is_user_logged_in() && isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
711
-            global $current_user;
712
-            wp_get_current_user();
713
-            $user_id = $current_user->ID;
714
-
715
-            $module = get_queried_object();
716
-
717
-            $this->save_user_module_progress(intval($module->term_id), intval($_GET['course_id']), intval($user_id));
718
-        }
719
-    }
720
-
721
-    /**
722
-     * Save module progess for user
723
-     *
724
-     * @since 1.8.0
725
-     *
726
-     * @param  integer $module_id ID of module
727
-     * @param  integer $course_id ID of course
728
-     * @param  integer $user_id ID of user
729
-     * @return void
730
-     */
731
-    public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
732
-    {
733
-        $module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id);
734
-        update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress));
735
-
736
-        do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress);
737
-    }
738
-
739
-    /**
740
-     * Get module progress for a user
741
-     *
742
-     * @since 1.8.0
743
-     *
744
-     * @param  integer $module_id ID of module
745
-     * @param  integer $course_id ID of course
746
-     * @param  integer $user_id ID of user
747
-     * @return mixed              Module progress percentage on success, false on failure
748
-     */
749
-    public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
750
-    {
751
-        $module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true);
752
-        if ($module_progress) {
753
-            return (float)$module_progress;
754
-        }
755
-        return false;
756
-    }
757
-
758
-    /**
759
-     * Calculate module progess for user
760
-     *
761
-     * @since 1.8.0
762
-     *
763
-     * @param  integer $user_id ID of user
764
-     * @param  integer $module_id ID of module
765
-     * @param  integer $course_id ID of course
766
-     * @return integer            Module progress percentage
767
-     */
768
-    public function calculate_user_module_progress($user_id = 0, $module_id = 0, $course_id = 0)
769
-    {
770
-
771
-        $args = array(
772
-            'post_type' => 'lesson',
773
-            'post_status' => 'publish',
774
-            'posts_per_page' => -1,
775
-            'tax_query' => array(
776
-                array(
777
-                    'taxonomy' => $this->taxonomy,
778
-                    'field' => 'id',
779
-                    'terms' => $module_id
780
-                )
781
-            ),
782
-            'meta_query' => array(
783
-                array(
784
-                    'key' => '_lesson_course',
785
-                    'value' => $course_id
786
-                )
787
-            ),
788
-            'fields' => 'ids'
789
-        );
790
-        $lessons = get_posts($args);
791
-
792
-        if (is_wp_error($lessons) || 0 >= count($lessons)) return 0;
793
-
794
-        $completed = false;
795
-        $lesson_count = 0;
796
-        $completed_count = 0;
797
-        foreach ($lessons as $lesson_id) {
798
-            $completed = Sensei_Utils::user_completed_lesson($lesson_id, $user_id);
799
-            ++$lesson_count;
800
-            if ($completed) {
801
-                ++$completed_count;
802
-            }
803
-        }
804
-        $module_progress = ($completed_count / $lesson_count) * 100;
805
-
806
-        return (float)$module_progress;
807
-    }
808
-
809
-    /**
810
-     * Register admin screen for ordering modules
811
-     *
812
-     * @since 1.8.0
813
-     *
814
-     * @return void
815
-     */
816
-    public function register_modules_admin_menu_items()
817
-    {
818
-        //add the modules link under the Course main menu
819
-        add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' );
820
-
821
-        // Regsiter new admin page for module ordering
822
-        $hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen'));
823
-
824
-    }
825
-
826
-    /**
827
-     * Display Module Order screen
828
-     *
829
-     * @since 1.8.0
830
-     *
831
-     * @return void
832
-     */
833
-    public function module_order_screen()
834
-    {
835
-        ?>
668
+		}
669
+	}
670
+
671
+	/**
672
+	 * Trigger save_lesson_module_progress() when a lesson status is updated for a specific user
673
+	 *
674
+	 * @since 1.8.0
675
+	 * @param  string $status Status of the lesson for the user
676
+	 * @param  integer $user_id ID of user
677
+	 * @param  integer $lesson_id ID of lesson
678
+	 * @return void
679
+	 */
680
+	public function update_lesson_status_module_progress($status = '', $user_id = 0, $lesson_id = 0)
681
+	{
682
+		$this->save_lesson_module_progress($user_id, $lesson_id);
683
+	}
684
+
685
+	/**
686
+	 * Save lesson's module progress for a specific user
687
+	 *
688
+	 * @since 1.8.0
689
+	 * @param  integer $user_id ID of user
690
+	 * @param  integer $lesson_id ID of lesson
691
+	 * @return void
692
+	 */
693
+	public function save_lesson_module_progress($user_id = 0, $lesson_id = 0)
694
+	{
695
+		$module = $this->get_lesson_module($lesson_id);
696
+		$course_id = get_post_meta($lesson_id, '_lesson_course', true);
697
+		if ($module && $course_id) {
698
+			$this->save_user_module_progress(intval($module->term_id), intval($course_id), intval($user_id));
699
+		}
700
+	}
701
+
702
+	/**
703
+	 * Save progress of module for user
704
+	 *
705
+	 * @since 1.8.0
706
+	 * @return void
707
+	 */
708
+	public function save_module_progress()
709
+	{
710
+		if (is_tax($this->taxonomy) && is_user_logged_in() && isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
711
+			global $current_user;
712
+			wp_get_current_user();
713
+			$user_id = $current_user->ID;
714
+
715
+			$module = get_queried_object();
716
+
717
+			$this->save_user_module_progress(intval($module->term_id), intval($_GET['course_id']), intval($user_id));
718
+		}
719
+	}
720
+
721
+	/**
722
+	 * Save module progess for user
723
+	 *
724
+	 * @since 1.8.0
725
+	 *
726
+	 * @param  integer $module_id ID of module
727
+	 * @param  integer $course_id ID of course
728
+	 * @param  integer $user_id ID of user
729
+	 * @return void
730
+	 */
731
+	public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
732
+	{
733
+		$module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id);
734
+		update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress));
735
+
736
+		do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress);
737
+	}
738
+
739
+	/**
740
+	 * Get module progress for a user
741
+	 *
742
+	 * @since 1.8.0
743
+	 *
744
+	 * @param  integer $module_id ID of module
745
+	 * @param  integer $course_id ID of course
746
+	 * @param  integer $user_id ID of user
747
+	 * @return mixed              Module progress percentage on success, false on failure
748
+	 */
749
+	public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
750
+	{
751
+		$module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true);
752
+		if ($module_progress) {
753
+			return (float)$module_progress;
754
+		}
755
+		return false;
756
+	}
757
+
758
+	/**
759
+	 * Calculate module progess for user
760
+	 *
761
+	 * @since 1.8.0
762
+	 *
763
+	 * @param  integer $user_id ID of user
764
+	 * @param  integer $module_id ID of module
765
+	 * @param  integer $course_id ID of course
766
+	 * @return integer            Module progress percentage
767
+	 */
768
+	public function calculate_user_module_progress($user_id = 0, $module_id = 0, $course_id = 0)
769
+	{
770
+
771
+		$args = array(
772
+			'post_type' => 'lesson',
773
+			'post_status' => 'publish',
774
+			'posts_per_page' => -1,
775
+			'tax_query' => array(
776
+				array(
777
+					'taxonomy' => $this->taxonomy,
778
+					'field' => 'id',
779
+					'terms' => $module_id
780
+				)
781
+			),
782
+			'meta_query' => array(
783
+				array(
784
+					'key' => '_lesson_course',
785
+					'value' => $course_id
786
+				)
787
+			),
788
+			'fields' => 'ids'
789
+		);
790
+		$lessons = get_posts($args);
791
+
792
+		if (is_wp_error($lessons) || 0 >= count($lessons)) return 0;
793
+
794
+		$completed = false;
795
+		$lesson_count = 0;
796
+		$completed_count = 0;
797
+		foreach ($lessons as $lesson_id) {
798
+			$completed = Sensei_Utils::user_completed_lesson($lesson_id, $user_id);
799
+			++$lesson_count;
800
+			if ($completed) {
801
+				++$completed_count;
802
+			}
803
+		}
804
+		$module_progress = ($completed_count / $lesson_count) * 100;
805
+
806
+		return (float)$module_progress;
807
+	}
808
+
809
+	/**
810
+	 * Register admin screen for ordering modules
811
+	 *
812
+	 * @since 1.8.0
813
+	 *
814
+	 * @return void
815
+	 */
816
+	public function register_modules_admin_menu_items()
817
+	{
818
+		//add the modules link under the Course main menu
819
+		add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' );
820
+
821
+		// Regsiter new admin page for module ordering
822
+		$hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen'));
823
+
824
+	}
825
+
826
+	/**
827
+	 * Display Module Order screen
828
+	 *
829
+	 * @since 1.8.0
830
+	 *
831
+	 * @return void
832
+	 */
833
+	public function module_order_screen()
834
+	{
835
+		?>
836 836
         <div id="<?php echo esc_attr($this->order_page_slug); ?>"
837 837
              class="wrap <?php echo esc_attr($this->order_page_slug); ?>">
838 838
         <h2><?php _e('Order Modules', 'woothemes-sensei'); ?></h2><?php
839 839
 
840
-        $html = '';
841
-
842
-        if (isset($_POST['module-order']) && 0 < strlen($_POST['module-order'])) {
843
-            $ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id']));
844
-
845
-            if ($ordered) {
846
-                $html .= '<div class="updated fade">' . "\n";
847
-                $html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n";
848
-                $html .= '</div>' . "\n";
849
-            }
850
-        }
851
-
852
-        $courses = Sensei()->course->get_all_courses();
853
-
854
-        $html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n";
855
-        $html .= '<input type="hidden" name="post_type" value="course" />' . "\n";
856
-        $html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n";
857
-        $html .= '<select id="module-order-course" name="course_id">' . "\n";
858
-        $html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n";
859
-
860
-        foreach ($courses as $course) {
861
-            if (has_term('', $this->taxonomy, $course->ID)) {
862
-                $course_id = '';
863
-                if (isset($_GET['course_id'])) {
864
-                    $course_id = intval($_GET['course_id']);
865
-                }
866
-                $html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n";
867
-            }
868
-        }
869
-
870
-        $html .= '</select>' . "\n";
871
-        $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n";
872
-        $html .= '</form>' . "\n";
873
-
874
-        if (isset($_GET['course_id'])) {
875
-            $course_id = intval($_GET['course_id']);
876
-            if ($course_id > 0) {
877
-                $modules = $this->get_course_modules($course_id);
878
-                $modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() );
879
-                if ($modules) {
880
-
881
-                    $order = $this->get_course_module_order($course_id);
882
-
883
-                    $order_string='';
884
-                    if ($order) {
885
-                        $order_string = implode(',', $order);
886
-                    }
887
-
888
-                    $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
889
-                    $html .= '<ul class="sortable-module-list">' . "\n";
890
-                    $count = 0;
891
-                    foreach ($modules as $module) {
892
-                        $count++;
893
-                        $class = $this->taxonomy;
894
-                        if ($count == 1) {
895
-                            $class .= ' first';
896
-                        }
897
-                        if ($count == count($module)) {
898
-                            $class .= ' last';
899
-                        }
900
-                        if ($count % 2 != 0) {
901
-                            $class .= ' alternate';
902
-                        }
903
-                        $html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n";
904
-                    }
905
-                    $html .= '</ul>' . "\n";
906
-
907
-                    $html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n";
908
-                    $html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n";
909
-                    $html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n";
910
-                    $html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n";
911
-                }
912
-            }
913
-        }
914
-
915
-        echo $html;
916
-
917
-        ?></div><?php
918
-    }
919
-
920
-    /**
921
-     * Add 'Module order' column to courses list table
922
-     *
923
-     * @since 1.8.0
924
-     *
925
-     * @param  array $columns Existing columns
926
-     * @return array           Modifed columns
927
-     */
928
-    public function course_columns($columns = array())
929
-    {
930
-        $columns['module_order'] = __('Module order', 'woothemes-sensei');
931
-        return $columns;
932
-    }
933
-
934
-    /**
935
-     * Load content in 'Module order' column
936
-     *
937
-     * @since 1.8.0
938
-     *
939
-     * @param  string $column Current column name
940
-     * @param  integer $course_id ID of course
941
-     * @return void
942
-     */
943
-    public function course_column_content($column = '', $course_id = 0)
944
-    {
945
-        if ($column == 'module_order') {
946
-            if (has_term('', $this->taxonomy, $course_id)) {
947
-                echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>';
948
-            }
949
-        }
950
-    }
951
-
952
-    /**
953
-     * Save module order for course
954
-     *
955
-     * @since 1.8.0
956
-     *
957
-     * @param  string $order_string Comma-separated string of module IDs
958
-     * @param  integer $course_id ID of course
959
-     * @return boolean                 True on success, false on failure
960
-     */
961
-    private function save_course_module_order($order_string = '', $course_id = 0)
962
-    {
963
-        if ($order_string && $course_id) {
964
-            $order = explode(',', $order_string);
965
-            update_post_meta(intval($course_id), '_module_order', $order);
966
-            return true;
967
-        }
968
-        return false;
969
-    }
970
-
971
-    /**
972
-     * Get module order for course
973
-     *
974
-     * @since 1.8.0
975
-     *
976
-     * @param  integer $course_id ID of course
977
-     * @return mixed              Module order on success, false if no module order has been saved
978
-     */
979
-    public function get_course_module_order($course_id = 0)
980
-    {
981
-        if ($course_id) {
982
-            $order = get_post_meta(intval($course_id), '_module_order', true);
983
-            return $order;
984
-        }
985
-        return false;
986
-    }
987
-
988
-    /**
989
-     * Modify module taxonomy columns
990
-     *
991
-     * @since 1.8.0
992
-     *
993
-     * @param  array $columns Default columns
994
-     * @return array          Modified columns
995
-     */
996
-    public function taxonomy_column_headings($columns)
997
-    {
998
-
999
-        unset($columns['posts']);
1000
-
1001
-        $columns['lessons'] = __('Lessons', 'woothemes-sensei');
1002
-
1003
-        return $columns;
1004
-    }
1005
-
1006
-    /**
1007
-     * Manage content in custom module taxonomy columns
1008
-     *
1009
-     * @since 1.8.0
1010
-     *
1011
-     * @param  string $column_data Default data for column
1012
-     * @param  string $column_name Name of current column
1013
-     * @param  integer $term_id ID of current term
1014
-     * @return string               Modified column data
1015
-     */
1016
-    public function taxonomy_column_content($column_data, $column_name, $term_id)
1017
-    {
1018
-
1019
-        $args = array(
1020
-            'post_status' => 'publish',
1021
-            'posts_per_page' => -1,
1022
-            'tax_query' => array(
1023
-                array(
1024
-                    'taxonomy' => $this->taxonomy,
1025
-                    'field' => 'id',
1026
-                    'terms' => intval($term_id)
1027
-                )
1028
-            )
1029
-        );
1030
-
1031
-        $module = get_term($term_id, $this->taxonomy);
1032
-
1033
-        switch ($column_name) {
1034
-
1035
-            case 'lessons':
1036
-                $args['post_type'] = 'lesson';
1037
-                $lessons = get_posts($args);
1038
-                $total_lessons = count($lessons);
1039
-                $column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>';
1040
-                break;
1041
-        }
1042
-
1043
-        return $column_data;
1044
-    }
1045
-
1046
-    /**
1047
-     * Add 'Module' columns to Analysis Lesson Overview table
1048
-     *
1049
-     * @since 1.8.0
1050
-     *
1051
-     * @param  array $columns Default columns
1052
-     * @return array          Modified columns
1053
-     */
1054
-    public function analysis_overview_column_title($columns)
1055
-    {
1056
-
1057
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1058
-            $new_columns = array();
1059
-            if (is_array($columns) && 0 < count($columns)) {
1060
-                foreach ($columns as $column => $title) {
1061
-                    $new_columns[$column] = $title;
1062
-                    if ($column == 'title') {
1063
-                        $new_columns['lesson_module'] = __('Module', 'woothemes-sensei');
1064
-                    }
1065
-                }
1066
-            }
1067
-
1068
-            if (0 < count($new_columns)) {
1069
-                return $new_columns;
1070
-            }
1071
-        }
1072
-
1073
-        return $columns;
1074
-    }
1075
-
1076
-    /**
1077
-     * Data for 'Module' column Analysis Lesson Overview table
1078
-     *
1079
-     * @since 1.8.0
1080
-     *
1081
-     * @param  array $columns Table column data
1082
-     * @param  WP_Post $lesson
1083
-     * @return array              Updated column data
1084
-     */
1085
-    public function analysis_overview_column_data($columns, $lesson )
1086
-    {
1087
-
1088
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1089
-            $lesson_module = '';
1090
-            $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1091
-            if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1092
-                foreach ($lesson_module_list as $single_module) {
1093
-                    $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1094
-                    break;
1095
-                }
1096
-            }
1097
-
1098
-            $columns['lesson_module'] = $lesson_module;
1099
-        }
1100
-
1101
-        return $columns;
1102
-    }
1103
-
1104
-    /**
1105
-     * Add 'Module' columns to Analysis Course table
1106
-     *
1107
-     * @since 1.8.0
1108
-     *
1109
-     * @param  array $columns Default columns
1110
-     * @return array          Modified columns
1111
-     */
1112
-    public function analysis_course_column_title($columns)
1113
-    {
1114
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1115
-            $columns['lesson_module'] = __('Module', 'woothemes-sensei');
1116
-        }
1117
-        return $columns;
1118
-    }
1119
-
1120
-    /**
1121
-     * Data for 'Module' column in Analysis Course table
1122
-     *
1123
-     * @since 1.8.0
1124
-     *
1125
-     * @param  array $columns Table column data
1126
-     * @param  WP_Post $lesson
1127
-     * @return array              Updated columns data
1128
-     */
1129
-    public function analysis_course_column_data($columns, $lesson )
1130
-    {
1131
-
1132
-        if ( isset( $_GET['course_id'] ) ) {
1133
-            $lesson_module = '';
1134
-            $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1135
-            if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1136
-                foreach ($lesson_module_list as $single_module) {
1137
-                    $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1138
-                    break;
1139
-                }
1140
-            }
1141
-
1142
-            $columns['lesson_module'] = $lesson_module;
1143
-        }
1144
-
1145
-        return $columns;
1146
-    }
1147
-
1148
-    /**
1149
-     * Get module for lesson
1150
-     *
1151
-     * This function also checks if the module still
1152
-     * exists on the course before returning it. Although
1153
-     * the lesson has a module the same module must exist on the
1154
-     * course for it to be valid.
1155
-     *
1156
-     * @since 1.8.0
1157
-     *
1158
-     * @param  integer $lesson_id ID of lesson
1159
-     * @return object             Module taxonomy term object
1160
-     */
1161
-    public function get_lesson_module($lesson_id = 0)
1162
-    {
1163
-        $lesson_id = intval($lesson_id);
1164
-        if ( ! ( intval( $lesson_id > 0) ) ) {
1165
-            return false;
1166
-        }
1167
-
1168
-        // get taxonomy terms on this lesson
1169
-        $modules = wp_get_post_terms($lesson_id, $this->taxonomy);
1170
-
1171
-        //check if error returned
1172
-        if(    empty( $modules )
1173
-            || is_wp_error( $modules )
1174
-            || isset( $modules['errors'] ) ){
1175
-
1176
-            return false;
1177
-
1178
-        }
1179
-
1180
-       // get the last item in the array there should be only be 1 really.
1181
-       // this method works for all php versions.
1182
-       foreach( $modules as $module ){
1183
-           break;
1184
-       }
1185
-
1186
-        if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) {
1187
-            return false;
1188
-        }
1189
-
1190
-        $module->url = get_term_link($module, $this->taxonomy);
1191
-        $course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true));
1192
-        if (isset($course_id) && 0 < $course_id) {
1193
-
1194
-            // the course should contain the same module taxonomy term for this to be valid
1195
-            if( ! has_term( $module, $this->taxonomy, $course_id)){
1196
-                return false;
1197
-            }
1198
-
1199
-            $module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url));
1200
-        }
1201
-        return $module;
1202
-
1203
-    }
1204
-
1205
-    /**
1206
-     * Get ordered array of all modules in course
1207
-     *
1208
-     * @since 1.8.0
1209
-     *
1210
-     * @param  integer $course_id ID of course
1211
-     * @return array              Ordered array of module taxonomy term objects
1212
-     */
1213
-    public function get_course_modules($course_id = 0)
1214
-    {
1215
-        $course_id = intval($course_id);
1216
-        if (0 < $course_id) {
1217
-
1218
-            // Get modules for course
1219
-            $modules = wp_get_post_terms($course_id, $this->taxonomy);
1220
-
1221
-            // Get custom module order for course
1222
-            $order = $this->get_course_module_order($course_id);
1223
-
1224
-            // Sort by custom order if custom order exists
1225
-            if ($order) {
1226
-                $ordered_modules = array();
1227
-                $unordered_modules = array();
1228
-                foreach ($modules as $module) {
1229
-                    $order_key = array_search($module->term_id, $order);
1230
-                    if ($order_key !== false) {
1231
-                        $ordered_modules[$order_key] = $module;
1232
-                    } else {
1233
-                        $unordered_modules[] = $module;
1234
-                    }
1235
-                }
1236
-
1237
-                // Order modules correctly
1238
-                ksort($ordered_modules);
1239
-
1240
-                // Append modules that have not yet been ordered
1241
-                if (count($unordered_modules) > 0) {
1242
-                    $ordered_modules = array_merge($ordered_modules, $unordered_modules);
1243
-                }
1244
-
1245
-            } else {
1246
-
1247
-                $ordered_modules = $modules;
1248
-
1249
-            }
1250
-
1251
-            return $ordered_modules;
1252
-
1253
-        }
1254
-
1255
-        return false;
1256
-    }
1257
-
1258
-    /**
1259
-     * Load frontend CSS
1260
-     *
1261
-     * @since 1.8.0
1262
-     *
1263
-     * @return void
1264
-     */
1265
-    public function enqueue_styles() {
1266
-
1267
-        wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1268
-        wp_enqueue_style($this->taxonomy . '-frontend');
1269
-
1270
-    }
1271
-
1272
-    /**
1273
-     * Load admin Javascript
1274
-     *
1275
-     * @since 1.8.0
1276
-     *
1277
-     * @return void
1278
-     */
1279
-    public function admin_enqueue_scripts( $hook ) {
1280
-
1281
-        /**
1282
-         * Filter the page hooks where modules admin script can be loaded on.
1283
-         *
1284
-         * @param array $white_listed_pages
1285
-         */
1286
-        $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1287
-            'edit-tags.php',
1288
-            'course_page_module-order',
1289
-            'post-new.php',
1290
-            'post.php'
1291
-        ) );
1292
-
1293
-        if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1294
-            return;
1295
-        }
1296
-
1297
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1298
-
1299
-        wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1300
-        wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1301
-        wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'sensei-core-select2' ), Sensei()->version, true );
1302
-
1303
-        // localized module data
1304
-        $localize_modulesAdmin = array(
1305
-            'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1306
-            'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1307
-        );
1308
-
1309
-        wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1310
-    }
1311
-
1312
-    /**
1313
-     * Load admin CSS
1314
-     *
1315
-     * @since 1.8.0
1316
-     *
1317
-     * @return void
1318
-     */
1319
-    public function admin_enqueue_styles() {
1320
-
1321
-        wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1322
-        wp_enqueue_style($this->taxonomy . '-sortable');
1323
-
1324
-    }
1325
-
1326
-    /**
1327
-     * Show the title modules on the single course template.
1328
-     *
1329
-     * Function is hooked into sensei_single_course_modules_before.
1330
-     *
1331
-     * @since 1.8.0
1332
-     * @return void
1333
-     */
1334
-    public function course_modules_title( ) {
1335
-
1336
-       if( sensei_module_has_lessons() ){
1337
-
1338
-            echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1339
-
1340
-        }
1341
-
1342
-    }
1343
-
1344
-    /**
1345
-     * Display the single course modules content this will only show
1346
-     * if the course has modules.
1347
-     *
1348
-     * @since 1.8.0
1349
-     * @return void
1350
-     */
1351
-    public function load_course_module_content_template(){
1352
-
1353
-	    if ( ! is_singular( 'course' )  ) {
1354
-		    return;
1355
-	    }
1356
-
1357
-        // load backwards compatible template name if it exists in the users theme
1358
-        $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1359
-        if( $located_template ){
1360
-
1361
-            Sensei_Templates::get_template( 'single-course/course-modules.php' );
1362
-            return;
1363
-
1364
-        }
1365
-
1366
-        Sensei_Templates::get_template( 'single-course/modules.php' );
1367
-
1368
-    } // end course_module_content
1369
-
1370
-    /**
1371
-     * Returns all lessons for the given module ID
1372
-     *
1373
-     * @since 1.8.0
1374
-     *
1375
-     * @param $course_id
1376
-     * @param $term_id
1377
-     * @return array $lessons
1378
-     */
1379
-    public function get_lessons( $course_id , $term_id ){
1380
-
1381
-        $lesson_query = $this->get_lessons_query( $course_id, $term_id );
1382
-
1383
-        if( isset( $lesson_query->posts ) ){
840
+		$html = '';
841
+
842
+		if (isset($_POST['module-order']) && 0 < strlen($_POST['module-order'])) {
843
+			$ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id']));
844
+
845
+			if ($ordered) {
846
+				$html .= '<div class="updated fade">' . "\n";
847
+				$html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n";
848
+				$html .= '</div>' . "\n";
849
+			}
850
+		}
851
+
852
+		$courses = Sensei()->course->get_all_courses();
853
+
854
+		$html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n";
855
+		$html .= '<input type="hidden" name="post_type" value="course" />' . "\n";
856
+		$html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n";
857
+		$html .= '<select id="module-order-course" name="course_id">' . "\n";
858
+		$html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n";
859
+
860
+		foreach ($courses as $course) {
861
+			if (has_term('', $this->taxonomy, $course->ID)) {
862
+				$course_id = '';
863
+				if (isset($_GET['course_id'])) {
864
+					$course_id = intval($_GET['course_id']);
865
+				}
866
+				$html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n";
867
+			}
868
+		}
869
+
870
+		$html .= '</select>' . "\n";
871
+		$html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n";
872
+		$html .= '</form>' . "\n";
873
+
874
+		if (isset($_GET['course_id'])) {
875
+			$course_id = intval($_GET['course_id']);
876
+			if ($course_id > 0) {
877
+				$modules = $this->get_course_modules($course_id);
878
+				$modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() );
879
+				if ($modules) {
880
+
881
+					$order = $this->get_course_module_order($course_id);
882
+
883
+					$order_string='';
884
+					if ($order) {
885
+						$order_string = implode(',', $order);
886
+					}
887
+
888
+					$html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
889
+					$html .= '<ul class="sortable-module-list">' . "\n";
890
+					$count = 0;
891
+					foreach ($modules as $module) {
892
+						$count++;
893
+						$class = $this->taxonomy;
894
+						if ($count == 1) {
895
+							$class .= ' first';
896
+						}
897
+						if ($count == count($module)) {
898
+							$class .= ' last';
899
+						}
900
+						if ($count % 2 != 0) {
901
+							$class .= ' alternate';
902
+						}
903
+						$html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n";
904
+					}
905
+					$html .= '</ul>' . "\n";
906
+
907
+					$html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n";
908
+					$html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n";
909
+					$html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n";
910
+					$html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n";
911
+				}
912
+			}
913
+		}
914
+
915
+		echo $html;
916
+
917
+		?></div><?php
918
+	}
919
+
920
+	/**
921
+	 * Add 'Module order' column to courses list table
922
+	 *
923
+	 * @since 1.8.0
924
+	 *
925
+	 * @param  array $columns Existing columns
926
+	 * @return array           Modifed columns
927
+	 */
928
+	public function course_columns($columns = array())
929
+	{
930
+		$columns['module_order'] = __('Module order', 'woothemes-sensei');
931
+		return $columns;
932
+	}
933
+
934
+	/**
935
+	 * Load content in 'Module order' column
936
+	 *
937
+	 * @since 1.8.0
938
+	 *
939
+	 * @param  string $column Current column name
940
+	 * @param  integer $course_id ID of course
941
+	 * @return void
942
+	 */
943
+	public function course_column_content($column = '', $course_id = 0)
944
+	{
945
+		if ($column == 'module_order') {
946
+			if (has_term('', $this->taxonomy, $course_id)) {
947
+				echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>';
948
+			}
949
+		}
950
+	}
951
+
952
+	/**
953
+	 * Save module order for course
954
+	 *
955
+	 * @since 1.8.0
956
+	 *
957
+	 * @param  string $order_string Comma-separated string of module IDs
958
+	 * @param  integer $course_id ID of course
959
+	 * @return boolean                 True on success, false on failure
960
+	 */
961
+	private function save_course_module_order($order_string = '', $course_id = 0)
962
+	{
963
+		if ($order_string && $course_id) {
964
+			$order = explode(',', $order_string);
965
+			update_post_meta(intval($course_id), '_module_order', $order);
966
+			return true;
967
+		}
968
+		return false;
969
+	}
970
+
971
+	/**
972
+	 * Get module order for course
973
+	 *
974
+	 * @since 1.8.0
975
+	 *
976
+	 * @param  integer $course_id ID of course
977
+	 * @return mixed              Module order on success, false if no module order has been saved
978
+	 */
979
+	public function get_course_module_order($course_id = 0)
980
+	{
981
+		if ($course_id) {
982
+			$order = get_post_meta(intval($course_id), '_module_order', true);
983
+			return $order;
984
+		}
985
+		return false;
986
+	}
987
+
988
+	/**
989
+	 * Modify module taxonomy columns
990
+	 *
991
+	 * @since 1.8.0
992
+	 *
993
+	 * @param  array $columns Default columns
994
+	 * @return array          Modified columns
995
+	 */
996
+	public function taxonomy_column_headings($columns)
997
+	{
998
+
999
+		unset($columns['posts']);
1000
+
1001
+		$columns['lessons'] = __('Lessons', 'woothemes-sensei');
1002
+
1003
+		return $columns;
1004
+	}
1005
+
1006
+	/**
1007
+	 * Manage content in custom module taxonomy columns
1008
+	 *
1009
+	 * @since 1.8.0
1010
+	 *
1011
+	 * @param  string $column_data Default data for column
1012
+	 * @param  string $column_name Name of current column
1013
+	 * @param  integer $term_id ID of current term
1014
+	 * @return string               Modified column data
1015
+	 */
1016
+	public function taxonomy_column_content($column_data, $column_name, $term_id)
1017
+	{
1018
+
1019
+		$args = array(
1020
+			'post_status' => 'publish',
1021
+			'posts_per_page' => -1,
1022
+			'tax_query' => array(
1023
+				array(
1024
+					'taxonomy' => $this->taxonomy,
1025
+					'field' => 'id',
1026
+					'terms' => intval($term_id)
1027
+				)
1028
+			)
1029
+		);
1030
+
1031
+		$module = get_term($term_id, $this->taxonomy);
1032
+
1033
+		switch ($column_name) {
1034
+
1035
+			case 'lessons':
1036
+				$args['post_type'] = 'lesson';
1037
+				$lessons = get_posts($args);
1038
+				$total_lessons = count($lessons);
1039
+				$column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>';
1040
+				break;
1041
+		}
1042
+
1043
+		return $column_data;
1044
+	}
1045
+
1046
+	/**
1047
+	 * Add 'Module' columns to Analysis Lesson Overview table
1048
+	 *
1049
+	 * @since 1.8.0
1050
+	 *
1051
+	 * @param  array $columns Default columns
1052
+	 * @return array          Modified columns
1053
+	 */
1054
+	public function analysis_overview_column_title($columns)
1055
+	{
1056
+
1057
+		if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1058
+			$new_columns = array();
1059
+			if (is_array($columns) && 0 < count($columns)) {
1060
+				foreach ($columns as $column => $title) {
1061
+					$new_columns[$column] = $title;
1062
+					if ($column == 'title') {
1063
+						$new_columns['lesson_module'] = __('Module', 'woothemes-sensei');
1064
+					}
1065
+				}
1066
+			}
1067
+
1068
+			if (0 < count($new_columns)) {
1069
+				return $new_columns;
1070
+			}
1071
+		}
1072
+
1073
+		return $columns;
1074
+	}
1075
+
1076
+	/**
1077
+	 * Data for 'Module' column Analysis Lesson Overview table
1078
+	 *
1079
+	 * @since 1.8.0
1080
+	 *
1081
+	 * @param  array $columns Table column data
1082
+	 * @param  WP_Post $lesson
1083
+	 * @return array              Updated column data
1084
+	 */
1085
+	public function analysis_overview_column_data($columns, $lesson )
1086
+	{
1087
+
1088
+		if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1089
+			$lesson_module = '';
1090
+			$lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1091
+			if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1092
+				foreach ($lesson_module_list as $single_module) {
1093
+					$lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1094
+					break;
1095
+				}
1096
+			}
1097
+
1098
+			$columns['lesson_module'] = $lesson_module;
1099
+		}
1100
+
1101
+		return $columns;
1102
+	}
1103
+
1104
+	/**
1105
+	 * Add 'Module' columns to Analysis Course table
1106
+	 *
1107
+	 * @since 1.8.0
1108
+	 *
1109
+	 * @param  array $columns Default columns
1110
+	 * @return array          Modified columns
1111
+	 */
1112
+	public function analysis_course_column_title($columns)
1113
+	{
1114
+		if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1115
+			$columns['lesson_module'] = __('Module', 'woothemes-sensei');
1116
+		}
1117
+		return $columns;
1118
+	}
1119
+
1120
+	/**
1121
+	 * Data for 'Module' column in Analysis Course table
1122
+	 *
1123
+	 * @since 1.8.0
1124
+	 *
1125
+	 * @param  array $columns Table column data
1126
+	 * @param  WP_Post $lesson
1127
+	 * @return array              Updated columns data
1128
+	 */
1129
+	public function analysis_course_column_data($columns, $lesson )
1130
+	{
1131
+
1132
+		if ( isset( $_GET['course_id'] ) ) {
1133
+			$lesson_module = '';
1134
+			$lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1135
+			if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1136
+				foreach ($lesson_module_list as $single_module) {
1137
+					$lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1138
+					break;
1139
+				}
1140
+			}
1141
+
1142
+			$columns['lesson_module'] = $lesson_module;
1143
+		}
1144
+
1145
+		return $columns;
1146
+	}
1147
+
1148
+	/**
1149
+	 * Get module for lesson
1150
+	 *
1151
+	 * This function also checks if the module still
1152
+	 * exists on the course before returning it. Although
1153
+	 * the lesson has a module the same module must exist on the
1154
+	 * course for it to be valid.
1155
+	 *
1156
+	 * @since 1.8.0
1157
+	 *
1158
+	 * @param  integer $lesson_id ID of lesson
1159
+	 * @return object             Module taxonomy term object
1160
+	 */
1161
+	public function get_lesson_module($lesson_id = 0)
1162
+	{
1163
+		$lesson_id = intval($lesson_id);
1164
+		if ( ! ( intval( $lesson_id > 0) ) ) {
1165
+			return false;
1166
+		}
1167
+
1168
+		// get taxonomy terms on this lesson
1169
+		$modules = wp_get_post_terms($lesson_id, $this->taxonomy);
1170
+
1171
+		//check if error returned
1172
+		if(    empty( $modules )
1173
+			|| is_wp_error( $modules )
1174
+			|| isset( $modules['errors'] ) ){
1175
+
1176
+			return false;
1177
+
1178
+		}
1179
+
1180
+	   // get the last item in the array there should be only be 1 really.
1181
+	   // this method works for all php versions.
1182
+	   foreach( $modules as $module ){
1183
+		   break;
1184
+	   }
1185
+
1186
+		if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) {
1187
+			return false;
1188
+		}
1189
+
1190
+		$module->url = get_term_link($module, $this->taxonomy);
1191
+		$course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true));
1192
+		if (isset($course_id) && 0 < $course_id) {
1193
+
1194
+			// the course should contain the same module taxonomy term for this to be valid
1195
+			if( ! has_term( $module, $this->taxonomy, $course_id)){
1196
+				return false;
1197
+			}
1198
+
1199
+			$module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url));
1200
+		}
1201
+		return $module;
1202
+
1203
+	}
1204
+
1205
+	/**
1206
+	 * Get ordered array of all modules in course
1207
+	 *
1208
+	 * @since 1.8.0
1209
+	 *
1210
+	 * @param  integer $course_id ID of course
1211
+	 * @return array              Ordered array of module taxonomy term objects
1212
+	 */
1213
+	public function get_course_modules($course_id = 0)
1214
+	{
1215
+		$course_id = intval($course_id);
1216
+		if (0 < $course_id) {
1217
+
1218
+			// Get modules for course
1219
+			$modules = wp_get_post_terms($course_id, $this->taxonomy);
1220
+
1221
+			// Get custom module order for course
1222
+			$order = $this->get_course_module_order($course_id);
1223
+
1224
+			// Sort by custom order if custom order exists
1225
+			if ($order) {
1226
+				$ordered_modules = array();
1227
+				$unordered_modules = array();
1228
+				foreach ($modules as $module) {
1229
+					$order_key = array_search($module->term_id, $order);
1230
+					if ($order_key !== false) {
1231
+						$ordered_modules[$order_key] = $module;
1232
+					} else {
1233
+						$unordered_modules[] = $module;
1234
+					}
1235
+				}
1236
+
1237
+				// Order modules correctly
1238
+				ksort($ordered_modules);
1239
+
1240
+				// Append modules that have not yet been ordered
1241
+				if (count($unordered_modules) > 0) {
1242
+					$ordered_modules = array_merge($ordered_modules, $unordered_modules);
1243
+				}
1244
+
1245
+			} else {
1246
+
1247
+				$ordered_modules = $modules;
1248
+
1249
+			}
1250
+
1251
+			return $ordered_modules;
1252
+
1253
+		}
1254
+
1255
+		return false;
1256
+	}
1257
+
1258
+	/**
1259
+	 * Load frontend CSS
1260
+	 *
1261
+	 * @since 1.8.0
1262
+	 *
1263
+	 * @return void
1264
+	 */
1265
+	public function enqueue_styles() {
1266
+
1267
+		wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1268
+		wp_enqueue_style($this->taxonomy . '-frontend');
1269
+
1270
+	}
1271
+
1272
+	/**
1273
+	 * Load admin Javascript
1274
+	 *
1275
+	 * @since 1.8.0
1276
+	 *
1277
+	 * @return void
1278
+	 */
1279
+	public function admin_enqueue_scripts( $hook ) {
1280
+
1281
+		/**
1282
+		 * Filter the page hooks where modules admin script can be loaded on.
1283
+		 *
1284
+		 * @param array $white_listed_pages
1285
+		 */
1286
+		$script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1287
+			'edit-tags.php',
1288
+			'course_page_module-order',
1289
+			'post-new.php',
1290
+			'post.php'
1291
+		) );
1292
+
1293
+		if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1294
+			return;
1295
+		}
1296
+
1297
+		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1298
+
1299
+		wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1300
+		wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1301
+		wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'sensei-core-select2' ), Sensei()->version, true );
1302
+
1303
+		// localized module data
1304
+		$localize_modulesAdmin = array(
1305
+			'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1306
+			'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1307
+		);
1308
+
1309
+		wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1310
+	}
1311
+
1312
+	/**
1313
+	 * Load admin CSS
1314
+	 *
1315
+	 * @since 1.8.0
1316
+	 *
1317
+	 * @return void
1318
+	 */
1319
+	public function admin_enqueue_styles() {
1320
+
1321
+		wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1322
+		wp_enqueue_style($this->taxonomy . '-sortable');
1323
+
1324
+	}
1325
+
1326
+	/**
1327
+	 * Show the title modules on the single course template.
1328
+	 *
1329
+	 * Function is hooked into sensei_single_course_modules_before.
1330
+	 *
1331
+	 * @since 1.8.0
1332
+	 * @return void
1333
+	 */
1334
+	public function course_modules_title( ) {
1335
+
1336
+	   if( sensei_module_has_lessons() ){
1337
+
1338
+			echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1339
+
1340
+		}
1341
+
1342
+	}
1343
+
1344
+	/**
1345
+	 * Display the single course modules content this will only show
1346
+	 * if the course has modules.
1347
+	 *
1348
+	 * @since 1.8.0
1349
+	 * @return void
1350
+	 */
1351
+	public function load_course_module_content_template(){
1352
+
1353
+		if ( ! is_singular( 'course' )  ) {
1354
+			return;
1355
+		}
1356
+
1357
+		// load backwards compatible template name if it exists in the users theme
1358
+		$located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1359
+		if( $located_template ){
1360
+
1361
+			Sensei_Templates::get_template( 'single-course/course-modules.php' );
1362
+			return;
1363
+
1364
+		}
1365
+
1366
+		Sensei_Templates::get_template( 'single-course/modules.php' );
1367
+
1368
+	} // end course_module_content
1369
+
1370
+	/**
1371
+	 * Returns all lessons for the given module ID
1372
+	 *
1373
+	 * @since 1.8.0
1374
+	 *
1375
+	 * @param $course_id
1376
+	 * @param $term_id
1377
+	 * @return array $lessons
1378
+	 */
1379
+	public function get_lessons( $course_id , $term_id ){
1380
+
1381
+		$lesson_query = $this->get_lessons_query( $course_id, $term_id );
1382
+
1383
+		if( isset( $lesson_query->posts ) ){
1384 1384
 
1385
-            return $lesson_query->posts;
1385
+			return $lesson_query->posts;
1386 1386
 
1387
-        }else{
1387
+		}else{
1388 1388
 
1389
-            return array();
1389
+			return array();
1390 1390
 
1391
-        }
1391
+		}
1392 1392
 
1393
-    } // end get lessons
1393
+	} // end get lessons
1394 1394
 
1395
-    /**
1396
-     * Returns all lessons for the given module ID
1397
-     *
1398
-     * @since 1.8.0
1399
-     *
1400
-     * @param $course_id
1401
-     * @param $term_id
1402
-     * @return WP_Query $lessons_query
1403
-     */
1404
-    public function get_lessons_query( $course_id , $term_id ){
1405
-
1406
-        if( empty( $term_id ) || empty( $course_id ) ){
1407
-
1408
-            return array();
1409
-
1410
-        }
1411
-
1412
-        $args = array(
1413
-            'post_type' => 'lesson',
1414
-            'post_status' => 'publish',
1415
-            'posts_per_page' => -1,
1416
-            'meta_query' => array(
1417
-                array(
1418
-                    'key' => '_lesson_course',
1419
-                    'value' => intval($course_id),
1420
-                    'compare' => '='
1421
-                )
1422
-            ),
1423
-            'tax_query' => array(
1424
-                array(
1425
-                    'taxonomy' => 'module',
1426
-                    'field' => 'id',
1427
-                    'terms' => intval( $term_id )
1428
-                )
1429
-            ),
1430
-            'orderby' => 'menu_order',
1431
-            'order' => 'ASC',
1432
-            'suppress_filters' => 0
1433
-        );
1434
-
1435
-        if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1436
-            $args['meta_key'] = '_order_module_' . intval( $term_id );
1437
-            $args['orderby'] = 'meta_value_num date';
1438
-        }
1439
-
1440
-        $lessons_query = new WP_Query( $args );
1441
-
1442
-        return $lessons_query;
1443
-
1444
-    } // end get lessons
1445
-
1446
-    /**
1447
-     * Find the lesson in the given course that doesn't belong
1448
-     * to any of the courses modules
1449
-     *
1450
-     *
1451
-     * @param $course_id
1452
-     *
1453
-     * @return array $non_module_lessons
1454
-     */
1455
-    public function get_none_module_lessons( $course_id ){
1456
-
1457
-        $non_module_lessons = array();
1458
-
1459
-        //exit if there is no course id passed in
1460
-        if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1461
-
1462
-            return $non_module_lessons;
1463
-        }
1464
-
1465
-        //save some time and check if we already have the saved
1466
-        if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1467
-
1468
-            return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1469
-
1470
-        }
1471
-
1472
-        // create terms array which must be excluded from other arrays
1473
-        $course_modules = $this->get_course_modules( $course_id );
1474
-
1475
-        //exit if there are no module on this course
1476
-        if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1477
-
1478
-            return  Sensei()->course->course_lessons( $course_id );
1479
-
1480
-        }
1481
-
1482
-        $terms = array();
1483
-        foreach( $course_modules as $module ){
1484
-
1485
-            array_push( $terms ,  $module->term_id );
1486
-
1487
-        }
1488
-
1489
-        $args = array(
1490
-            'post_type' => 'lesson',
1491
-            'post_status' => 'publish',
1492
-            'posts_per_page' => -1,
1493
-            'meta_query' => array(
1494
-                array(
1495
-                    'key' => '_lesson_course',
1496
-                    'value' => intval( $course_id ),
1497
-                    'compare' => '='
1498
-                )
1499
-            ),
1500
-            'tax_query' => array(
1501
-                array(
1502
-                    'taxonomy' => 'module',
1503
-                    'field' => 'id',
1504
-                    'terms' =>  $terms,
1505
-                    'operator' => 'NOT IN'
1506
-                )
1507
-            ),
1508
-            'orderby' => 'menu_order',
1509
-            'order' => 'ASC',
1510
-            'suppress_filters' => 0
1511
-        );
1512
-
1513
-        $wp_lessons_query = new WP_Query( $args );
1514
-
1515
-        if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1516
-            $non_module_lessons = $wp_lessons_query->get_posts();
1517
-            set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1518
-        }
1519
-
1520
-        return $non_module_lessons;
1521
-    } // end get_none_module_lessons
1522
-
1523
-    /**
1524
-     * Register the modules taxonomy
1525
-     *
1526
-     * @since 1.8.0
1527
-     */
1528
-    public function setup_modules_taxonomy(){
1529
-
1530
-        $labels = array(
1531
-            'name' => __('Modules', 'woothemes-sensei'),
1532
-            'singular_name' => __('Module', 'woothemes-sensei'),
1533
-            'search_items' => __('Search Modules', 'woothemes-sensei'),
1534
-            'all_items' => __('All Modules', 'woothemes-sensei'),
1535
-            'parent_item' => __('Parent Module', 'woothemes-sensei'),
1536
-            'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'),
1537
-            'edit_item' => __('Edit Module', 'woothemes-sensei'),
1538
-            'update_item' => __('Update Module', 'woothemes-sensei'),
1539
-            'add_new_item' => __('Add New Module', 'woothemes-sensei'),
1540
-            'new_item_name' => __('New Module Name', 'woothemes-sensei'),
1541
-            'menu_name' => __('Modules', 'woothemes-sensei'),
1542
-        );
1543
-
1544
-        /**
1545
-         * Filter to alter the Sensei Modules rewrite slug
1546
-         *
1547
-         * @since 1.8.0
1548
-         * @param string default 'modules'
1549
-         */
1550
-        $modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules');
1551
-
1552
-        $args = array(
1553
-            'public' => true,
1554
-            'hierarchical' => true,
1555
-            'show_admin_column' => true,
1556
-            'capabilities' => array(
1557
-                'manage_terms' => 'manage_categories',
1558
-                'edit_terms'   => 'edit_courses',
1559
-                'delete_terms' => 'manage_categories',
1560
-                'assign_terms' => 'edit_courses'
1561
-            ),
1562
-            'show_in_nav_menus' => false,
1563
-            'show_in_quick_edit' => false,
1564
-            'show_ui' => true,
1565
-            'rewrite' => array('slug' => $modules_rewrite_slug ),
1566
-            'labels' => $labels
1567
-        );
1568
-
1569
-        register_taxonomy( 'module' , array('course', 'lesson'), $args);
1570
-
1571
-    }// end setup_modules_taxonomy
1572
-
1573
-    /**
1574
-     * When the wants to edit the lesson modules redirect them to the course modules.
1575
-     *
1576
-     * This function is hooked into the admin_menu
1577
-     *
1578
-     * @since 1.8.0
1579
-     * @return void
1580
-     */
1581
-    function redirect_to_lesson_module_taxonomy_to_course( ){
1582
-
1583
-        global $typenow , $taxnow;
1584
-
1585
-        if( 'lesson'== $typenow && 'module'==$taxnow ){
1586
-            wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1587
-        }
1588
-
1589
-    }// end redirect to course taxonomy
1590
-
1591
-    /**
1592
-     * Completely remove the module menu item under lessons.
1593
-     *
1594
-     * This function is hooked into the admin_menu
1595
-     *
1596
-     * @since 1.8.0
1597
-     * @return void
1598
-     */
1599
-    public function remove_lessons_menu_model_taxonomy(){
1600
-        global $submenu;
1601
-
1602
-        if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1603
-            return; // exit
1604
-        }
1605
-
1606
-        $lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1607
-        foreach( $lesson_main_menu as $index => $sub_item ){
1608
-
1609
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1610
-                unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1611
-            }
1612
-        }
1613
-
1614
-    }// end remove lesson module tax
1615
-
1616
-    /**
1617
-     * Completely remove the second modules under courses
1618
-     *
1619
-     * This function is hooked into the admin_menu
1620
-     *
1621
-     * @since 1.8.0
1622
-     * @return void
1623
-     */
1624
-    public function remove_courses_menu_model_taxonomy(){
1625
-        global $submenu;
1626
-
1627
-        if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1628
-            return; // exit
1629
-        }
1630
-
1631
-        $course_main_menu = $submenu['edit.php?post_type=course'];
1632
-        foreach( $course_main_menu as $index => $sub_item ){
1633
-
1634
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1635
-                unset( $submenu['edit.php?post_type=course'][ $index ]);
1636
-            }
1637
-        }
1638
-
1639
-    }// end remove courses module tax
1640
-
1641
-    /**
1642
-     * Determine the author of a module term term by looking at
1643
-     * the prefixed author id. This function will query the full term object.
1644
-     * Will return the admin user author could not be determined.
1645
-     *
1646
-     * @since 1.8.0
1647
-     *
1648
-     * @param string $term_name
1649
-     * @return array $owners { type WP_User }. Empty array if none if found.
1650
-     */
1651
-    public static function get_term_authors( $term_name ){
1652
-
1653
-        $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1654
-
1655
-        $owners = array();
1656
-        if( empty( $terms ) ){
1657
-
1658
-            return $owners;
1395
+	/**
1396
+	 * Returns all lessons for the given module ID
1397
+	 *
1398
+	 * @since 1.8.0
1399
+	 *
1400
+	 * @param $course_id
1401
+	 * @param $term_id
1402
+	 * @return WP_Query $lessons_query
1403
+	 */
1404
+	public function get_lessons_query( $course_id , $term_id ){
1405
+
1406
+		if( empty( $term_id ) || empty( $course_id ) ){
1407
+
1408
+			return array();
1409
+
1410
+		}
1411
+
1412
+		$args = array(
1413
+			'post_type' => 'lesson',
1414
+			'post_status' => 'publish',
1415
+			'posts_per_page' => -1,
1416
+			'meta_query' => array(
1417
+				array(
1418
+					'key' => '_lesson_course',
1419
+					'value' => intval($course_id),
1420
+					'compare' => '='
1421
+				)
1422
+			),
1423
+			'tax_query' => array(
1424
+				array(
1425
+					'taxonomy' => 'module',
1426
+					'field' => 'id',
1427
+					'terms' => intval( $term_id )
1428
+				)
1429
+			),
1430
+			'orderby' => 'menu_order',
1431
+			'order' => 'ASC',
1432
+			'suppress_filters' => 0
1433
+		);
1434
+
1435
+		if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1436
+			$args['meta_key'] = '_order_module_' . intval( $term_id );
1437
+			$args['orderby'] = 'meta_value_num date';
1438
+		}
1439
+
1440
+		$lessons_query = new WP_Query( $args );
1441
+
1442
+		return $lessons_query;
1443
+
1444
+	} // end get lessons
1445
+
1446
+	/**
1447
+	 * Find the lesson in the given course that doesn't belong
1448
+	 * to any of the courses modules
1449
+	 *
1450
+	 *
1451
+	 * @param $course_id
1452
+	 *
1453
+	 * @return array $non_module_lessons
1454
+	 */
1455
+	public function get_none_module_lessons( $course_id ){
1456
+
1457
+		$non_module_lessons = array();
1458
+
1459
+		//exit if there is no course id passed in
1460
+		if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1461
+
1462
+			return $non_module_lessons;
1463
+		}
1464
+
1465
+		//save some time and check if we already have the saved
1466
+		if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1467
+
1468
+			return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1469
+
1470
+		}
1471
+
1472
+		// create terms array which must be excluded from other arrays
1473
+		$course_modules = $this->get_course_modules( $course_id );
1474
+
1475
+		//exit if there are no module on this course
1476
+		if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1477
+
1478
+			return  Sensei()->course->course_lessons( $course_id );
1479
+
1480
+		}
1481
+
1482
+		$terms = array();
1483
+		foreach( $course_modules as $module ){
1484
+
1485
+			array_push( $terms ,  $module->term_id );
1486
+
1487
+		}
1488
+
1489
+		$args = array(
1490
+			'post_type' => 'lesson',
1491
+			'post_status' => 'publish',
1492
+			'posts_per_page' => -1,
1493
+			'meta_query' => array(
1494
+				array(
1495
+					'key' => '_lesson_course',
1496
+					'value' => intval( $course_id ),
1497
+					'compare' => '='
1498
+				)
1499
+			),
1500
+			'tax_query' => array(
1501
+				array(
1502
+					'taxonomy' => 'module',
1503
+					'field' => 'id',
1504
+					'terms' =>  $terms,
1505
+					'operator' => 'NOT IN'
1506
+				)
1507
+			),
1508
+			'orderby' => 'menu_order',
1509
+			'order' => 'ASC',
1510
+			'suppress_filters' => 0
1511
+		);
1512
+
1513
+		$wp_lessons_query = new WP_Query( $args );
1514
+
1515
+		if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1516
+			$non_module_lessons = $wp_lessons_query->get_posts();
1517
+			set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1518
+		}
1519
+
1520
+		return $non_module_lessons;
1521
+	} // end get_none_module_lessons
1522
+
1523
+	/**
1524
+	 * Register the modules taxonomy
1525
+	 *
1526
+	 * @since 1.8.0
1527
+	 */
1528
+	public function setup_modules_taxonomy(){
1529
+
1530
+		$labels = array(
1531
+			'name' => __('Modules', 'woothemes-sensei'),
1532
+			'singular_name' => __('Module', 'woothemes-sensei'),
1533
+			'search_items' => __('Search Modules', 'woothemes-sensei'),
1534
+			'all_items' => __('All Modules', 'woothemes-sensei'),
1535
+			'parent_item' => __('Parent Module', 'woothemes-sensei'),
1536
+			'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'),
1537
+			'edit_item' => __('Edit Module', 'woothemes-sensei'),
1538
+			'update_item' => __('Update Module', 'woothemes-sensei'),
1539
+			'add_new_item' => __('Add New Module', 'woothemes-sensei'),
1540
+			'new_item_name' => __('New Module Name', 'woothemes-sensei'),
1541
+			'menu_name' => __('Modules', 'woothemes-sensei'),
1542
+		);
1543
+
1544
+		/**
1545
+		 * Filter to alter the Sensei Modules rewrite slug
1546
+		 *
1547
+		 * @since 1.8.0
1548
+		 * @param string default 'modules'
1549
+		 */
1550
+		$modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules');
1551
+
1552
+		$args = array(
1553
+			'public' => true,
1554
+			'hierarchical' => true,
1555
+			'show_admin_column' => true,
1556
+			'capabilities' => array(
1557
+				'manage_terms' => 'manage_categories',
1558
+				'edit_terms'   => 'edit_courses',
1559
+				'delete_terms' => 'manage_categories',
1560
+				'assign_terms' => 'edit_courses'
1561
+			),
1562
+			'show_in_nav_menus' => false,
1563
+			'show_in_quick_edit' => false,
1564
+			'show_ui' => true,
1565
+			'rewrite' => array('slug' => $modules_rewrite_slug ),
1566
+			'labels' => $labels
1567
+		);
1568
+
1569
+		register_taxonomy( 'module' , array('course', 'lesson'), $args);
1570
+
1571
+	}// end setup_modules_taxonomy
1572
+
1573
+	/**
1574
+	 * When the wants to edit the lesson modules redirect them to the course modules.
1575
+	 *
1576
+	 * This function is hooked into the admin_menu
1577
+	 *
1578
+	 * @since 1.8.0
1579
+	 * @return void
1580
+	 */
1581
+	function redirect_to_lesson_module_taxonomy_to_course( ){
1582
+
1583
+		global $typenow , $taxnow;
1584
+
1585
+		if( 'lesson'== $typenow && 'module'==$taxnow ){
1586
+			wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1587
+		}
1588
+
1589
+	}// end redirect to course taxonomy
1590
+
1591
+	/**
1592
+	 * Completely remove the module menu item under lessons.
1593
+	 *
1594
+	 * This function is hooked into the admin_menu
1595
+	 *
1596
+	 * @since 1.8.0
1597
+	 * @return void
1598
+	 */
1599
+	public function remove_lessons_menu_model_taxonomy(){
1600
+		global $submenu;
1601
+
1602
+		if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1603
+			return; // exit
1604
+		}
1605
+
1606
+		$lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1607
+		foreach( $lesson_main_menu as $index => $sub_item ){
1608
+
1609
+			if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1610
+				unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1611
+			}
1612
+		}
1613
+
1614
+	}// end remove lesson module tax
1615
+
1616
+	/**
1617
+	 * Completely remove the second modules under courses
1618
+	 *
1619
+	 * This function is hooked into the admin_menu
1620
+	 *
1621
+	 * @since 1.8.0
1622
+	 * @return void
1623
+	 */
1624
+	public function remove_courses_menu_model_taxonomy(){
1625
+		global $submenu;
1626
+
1627
+		if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1628
+			return; // exit
1629
+		}
1630
+
1631
+		$course_main_menu = $submenu['edit.php?post_type=course'];
1632
+		foreach( $course_main_menu as $index => $sub_item ){
1633
+
1634
+			if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1635
+				unset( $submenu['edit.php?post_type=course'][ $index ]);
1636
+			}
1637
+		}
1638
+
1639
+	}// end remove courses module tax
1640
+
1641
+	/**
1642
+	 * Determine the author of a module term term by looking at
1643
+	 * the prefixed author id. This function will query the full term object.
1644
+	 * Will return the admin user author could not be determined.
1645
+	 *
1646
+	 * @since 1.8.0
1647
+	 *
1648
+	 * @param string $term_name
1649
+	 * @return array $owners { type WP_User }. Empty array if none if found.
1650
+	 */
1651
+	public static function get_term_authors( $term_name ){
1652
+
1653
+		$terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1654
+
1655
+		$owners = array();
1656
+		if( empty( $terms ) ){
1657
+
1658
+			return $owners;
1659 1659
 
1660
-        }
1660
+		}
1661 1661
 
1662
-        // setup the admin user
1662
+		// setup the admin user
1663 1663
 
1664 1664
 
1665
-        //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1666
-        foreach( $terms as $term){
1667
-            if( $term->name == $term_name ){
1665
+		//if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1666
+		foreach( $terms as $term){
1667
+			if( $term->name == $term_name ){
1668 1668
 
1669
-                // look for the author in the slug
1670
-                $owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1669
+				// look for the author in the slug
1670
+				$owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1671 1671
 
1672
-            }// end if term name
1672
+			}// end if term name
1673 1673
 
1674
-        } // end for each
1674
+		} // end for each
1675 1675
 
1676
-        return $owners;
1676
+		return $owners;
1677 1677
 
1678
-    }// end get_term_author
1678
+	}// end get_term_author
1679 1679
 
1680
-    /**
1681
-     * Looks at a term slug and figures out
1682
-     * which author created the slug. The author was
1683
-     * appended when the user saved the module term in the course edit
1684
-     * screen.
1685
-     *
1686
-     * @since 1.8.0
1687
-     *
1688
-     * @param $slug
1689
-     * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1690
-     */
1691
-    public static function get_term_author( $slug='' ){
1680
+	/**
1681
+	 * Looks at a term slug and figures out
1682
+	 * which author created the slug. The author was
1683
+	 * appended when the user saved the module term in the course edit
1684
+	 * screen.
1685
+	 *
1686
+	 * @since 1.8.0
1687
+	 *
1688
+	 * @param $slug
1689
+	 * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1690
+	 */
1691
+	public static function get_term_author( $slug='' ){
1692 1692
 
1693
-        $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1693
+		$term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1694 1694
 
1695
-        if( empty( $slug ) ){
1695
+		if( empty( $slug ) ){
1696 1696
 
1697
-            return $term_owner;
1697
+			return $term_owner;
1698 1698
 
1699
-        }
1699
+		}
1700 1700
 
1701
-        // look for the author in the slug
1702
-        $slug_parts = explode( '-', $slug );
1701
+		// look for the author in the slug
1702
+		$slug_parts = explode( '-', $slug );
1703 1703
 
1704
-        if( count( $slug_parts ) > 1 ){
1704
+		if( count( $slug_parts ) > 1 ){
1705 1705
 
1706
-            // get the user data
1707
-            $possible_user_id = $slug_parts[0];
1708
-            $author = get_userdata( $possible_user_id );
1706
+			// get the user data
1707
+			$possible_user_id = $slug_parts[0];
1708
+			$author = get_userdata( $possible_user_id );
1709 1709
 
1710
-            // if the user doesnt exist for the first part of the slug
1711
-            // then this slug was also created by admin
1712
-            if( is_a( $author, 'WP_User' ) ){
1710
+			// if the user doesnt exist for the first part of the slug
1711
+			// then this slug was also created by admin
1712
+			if( is_a( $author, 'WP_User' ) ){
1713 1713
 
1714
-                $term_owner =  $author;
1714
+				$term_owner =  $author;
1715 1715
 
1716
-            }
1717
-        }
1716
+			}
1717
+		}
1718 1718
 
1719
-        return $term_owner;
1720
-    }
1719
+		return $term_owner;
1720
+	}
1721 1721
 
1722
-    /**
1723
-     * Display the Sensei modules taxonomy terms metabox
1724
-     *
1725
-     * @since 1.8.0
1726
-     *
1727
-     * @hooked into add_meta_box
1728
-     *
1729
-     * @param WP_Post $post Post object.
1730
-     */
1731
-    public function course_module_metabox( $post ) {
1722
+	/**
1723
+	 * Display the Sensei modules taxonomy terms metabox
1724
+	 *
1725
+	 * @since 1.8.0
1726
+	 *
1727
+	 * @hooked into add_meta_box
1728
+	 *
1729
+	 * @param WP_Post $post Post object.
1730
+	 */
1731
+	public function course_module_metabox( $post ) {
1732 1732
 
1733
-        $tax_name = 'module';
1734
-        $taxonomy = get_taxonomy( 'module' );
1733
+		$tax_name = 'module';
1734
+		$taxonomy = get_taxonomy( 'module' );
1735 1735
 
1736
-        ?>
1736
+		?>
1737 1737
         <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
1738 1738
             <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs">
1739 1739
                 <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li>
@@ -1748,9 +1748,9 @@  discard block
 block discarded – undo
1748 1748
 
1749 1749
             <div id="<?php echo $tax_name; ?>-all" class="tabs-panel">
1750 1750
                 <?php
1751
-                $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1752
-                echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
1753
-                ?>
1751
+				$name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1752
+				echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
1753
+				?>
1754 1754
                 <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">
1755 1755
                     <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?>
1756 1756
                 </ul>
@@ -1760,9 +1760,9 @@  discard block
 block discarded – undo
1760 1760
                     <h4>
1761 1761
                         <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js">
1762 1762
                             <?php
1763
-                            /* translators: %s: add new taxonomy label */
1764
-                            printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1765
-                            ?>
1763
+							/* translators: %s: add new taxonomy label */
1764
+							printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1765
+							?>
1766 1766
                         </a>
1767 1767
                     </h4>
1768 1768
                     <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">
@@ -1777,331 +1777,331 @@  discard block
 block discarded – undo
1777 1777
         </div>
1778 1778
     <?php
1779 1779
 
1780
-    } // end course_module_metabox
1780
+	} // end course_module_metabox
1781 1781
 
1782 1782
 
1783
-    /**
1784
-     * Submits a new module term prefixed with the
1785
-     * the current author id.
1786
-     *
1787
-     * @since 1.8.0
1788
-     */
1789
-    public static function add_new_module_term( ) {
1783
+	/**
1784
+	 * Submits a new module term prefixed with the
1785
+	 * the current author id.
1786
+	 *
1787
+	 * @since 1.8.0
1788
+	 */
1789
+	public static function add_new_module_term( ) {
1790 1790
 
1791 1791
 
1792
-        if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1793
-            wp_send_json_error( array('error'=> 'wrong security nonce') );
1794
-        }
1792
+		if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1793
+			wp_send_json_error( array('error'=> 'wrong security nonce') );
1794
+		}
1795 1795
 
1796
-        // get the term an create the new term storing infomration
1797
-        $term_name = sanitize_text_field( $_POST['newTerm'] );
1796
+		// get the term an create the new term storing infomration
1797
+		$term_name = sanitize_text_field( $_POST['newTerm'] );
1798 1798
 
1799
-        if( current_user_can('manage_options' ) ) {
1799
+		if( current_user_can('manage_options' ) ) {
1800 1800
 
1801
-            $term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1801
+			$term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1802 1802
 
1803
-        } else {
1803
+		} else {
1804 1804
 
1805
-            $term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1805
+			$term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1806 1806
 
1807
-        }
1807
+		}
1808 1808
 
1809
-        $course_id = sanitize_text_field( $_POST['course_id'] );
1809
+		$course_id = sanitize_text_field( $_POST['course_id'] );
1810 1810
 
1811
-        // save the term
1812
-        $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1811
+		// save the term
1812
+		$slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1813 1813
 
1814
-        // send error for all errors except term exits
1815
-        if( is_wp_error( $slug ) ){
1814
+		// send error for all errors except term exits
1815
+		if( is_wp_error( $slug ) ){
1816 1816
 
1817
-            // prepare for possible term name and id to be passed down if term exists
1818
-            $term_data = array();
1817
+			// prepare for possible term name and id to be passed down if term exists
1818
+			$term_data = array();
1819 1819
 
1820
-            // if term exists also send back the term name and id
1821
-            if( isset( $slug->errors['term_exists'] ) ){
1820
+			// if term exists also send back the term name and id
1821
+			if( isset( $slug->errors['term_exists'] ) ){
1822 1822
 
1823
-                $term = get_term_by( 'slug', $term_slug, 'module');
1824
-                $term_data['name'] = $term_name;
1825
-                $term_data['id'] = $term->term_id;
1823
+				$term = get_term_by( 'slug', $term_slug, 'module');
1824
+				$term_data['name'] = $term_name;
1825
+				$term_data['id'] = $term->term_id;
1826 1826
 
1827
-                // set the object terms
1828
-                wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1829
-            }
1827
+				// set the object terms
1828
+				wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1829
+			}
1830 1830
 
1831
-            wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1831
+			wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1832 1832
 
1833
-        }
1833
+		}
1834 1834
 
1835
-        //make sure the new term is checked for this course
1835
+		//make sure the new term is checked for this course
1836 1836
 
1837
-        wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1837
+		wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1838 1838
 
1839
-        // Handle request then generate response using WP_Ajax_Response
1840
-        wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1839
+		// Handle request then generate response using WP_Ajax_Response
1840
+		wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1841 1841
 
1842
-    }
1842
+	}
1843 1843
 
1844
-    /**
1845
-     * Limit the course module metabox
1846
-     * term list to only those on courses belonging to current teacher.
1847
-     *
1848
-     * Hooked into 'get_terms'
1849
-     *
1850
-     * @since 1.8.0
1851
-     */
1852
-    public function filter_module_terms( $terms, $taxonomies, $args ){
1844
+	/**
1845
+	 * Limit the course module metabox
1846
+	 * term list to only those on courses belonging to current teacher.
1847
+	 *
1848
+	 * Hooked into 'get_terms'
1849
+	 *
1850
+	 * @since 1.8.0
1851
+	 */
1852
+	public function filter_module_terms( $terms, $taxonomies, $args ){
1853 1853
 
1854
-        //dont limit for admins and other taxonomies. This should also only apply to admin
1855
-        if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1856
-            return $terms;
1857
-        }
1854
+		//dont limit for admins and other taxonomies. This should also only apply to admin
1855
+		if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1856
+			return $terms;
1857
+		}
1858 1858
 
1859
-        // avoid infinite call loop
1860
-        remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1859
+		// avoid infinite call loop
1860
+		remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1861 1861
 
1862
-        // in certain cases the array is passed in as reference to the parent term_id => parent_id
1863
-        if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1864
-            // change only scrub the terms ids form the array keys
1865
-            $terms = array_keys( $terms );
1866
-        }
1862
+		// in certain cases the array is passed in as reference to the parent term_id => parent_id
1863
+		if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1864
+			// change only scrub the terms ids form the array keys
1865
+			$terms = array_keys( $terms );
1866
+		}
1867 1867
 
1868
-        $teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1868
+		$teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1869 1869
 
1870
-        // add filter again as removed above
1871
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1870
+		// add filter again as removed above
1871
+		add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1872 1872
 
1873
-        return $teachers_terms;
1874
-    }// end filter_module_terms
1873
+		return $teachers_terms;
1874
+	}// end filter_module_terms
1875 1875
 
1876
-    /**
1877
-     * For the selected items on a course module only return those
1878
-     * for the current user. This does not apply to admin and super admin users.
1879
-     *
1880
-     * hooked into get_object_terms
1881
-     *
1882
-     * @since 1.8.0
1883
-     */
1884
-    public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1876
+	/**
1877
+	 * For the selected items on a course module only return those
1878
+	 * for the current user. This does not apply to admin and super admin users.
1879
+	 *
1880
+	 * hooked into get_object_terms
1881
+	 *
1882
+	 * @since 1.8.0
1883
+	 */
1884
+	public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1885 1885
 
1886
-        //dont limit for admins and other taxonomies. This should also only apply to admin
1887
-        if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1888
-            // only apply this to module only taxonomy queries so 1 taxonomy only:
1889
-            ||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1890
-            return $terms;
1891
-        }
1886
+		//dont limit for admins and other taxonomies. This should also only apply to admin
1887
+		if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1888
+			// only apply this to module only taxonomy queries so 1 taxonomy only:
1889
+			||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1890
+			return $terms;
1891
+		}
1892 1892
 
1893
-        $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1893
+		$term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1894 1894
 
1895
-        // if term objects were passed in send back objects
1896
-        // if term id were passed in send that back
1897
-        if( is_object( $terms[0] ) ){
1898
-            return $term_objects;
1899
-        }
1895
+		// if term objects were passed in send back objects
1896
+		// if term id were passed in send that back
1897
+		if( is_object( $terms[0] ) ){
1898
+			return $term_objects;
1899
+		}
1900 1900
 
1901
-        $terms = array();
1902
-        foreach( $term_objects as $term_object ){
1903
-            $terms[] = $term_object->term_id;
1904
-        }
1901
+		$terms = array();
1902
+		foreach( $term_objects as $term_object ){
1903
+			$terms[] = $term_object->term_id;
1904
+		}
1905 1905
 
1906
-        return $terms;
1906
+		return $terms;
1907 1907
 
1908 1908
 
1909
-    }// end filter_course_selected_terms
1909
+	}// end filter_course_selected_terms
1910 1910
 
1911
-    /**
1912
-     * Filter the given terms and only return the
1913
-     * terms that belong to the given user id.
1914
-     *
1915
-     * @since 1.8.0
1916
-     * @param $terms
1917
-     * @param $user_id
1918
-     * @return array
1919
-     */
1920
-    public function filter_terms_by_owner( $terms, $user_id ){
1911
+	/**
1912
+	 * Filter the given terms and only return the
1913
+	 * terms that belong to the given user id.
1914
+	 *
1915
+	 * @since 1.8.0
1916
+	 * @param $terms
1917
+	 * @param $user_id
1918
+	 * @return array
1919
+	 */
1920
+	public function filter_terms_by_owner( $terms, $user_id ){
1921 1921
 
1922
-        $users_terms = array();
1922
+		$users_terms = array();
1923 1923
 
1924
-        foreach( $terms as $index => $term ){
1924
+		foreach( $terms as $index => $term ){
1925 1925
 
1926
-            if( is_numeric( $term ) ){
1927
-                // the term id was given, get the term object
1928
-                $term = get_term( $term, 'module' );
1929
-            }
1926
+			if( is_numeric( $term ) ){
1927
+				// the term id was given, get the term object
1928
+				$term = get_term( $term, 'module' );
1929
+			}
1930 1930
 
1931
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1931
+			$author = Sensei_Core_Modules::get_term_author( $term->slug );
1932 1932
 
1933
-            if ( $user_id == $author->ID ) {
1934
-                // add the term to the teachers terms
1935
-                $users_terms[] = $term;
1936
-            }
1933
+			if ( $user_id == $author->ID ) {
1934
+				// add the term to the teachers terms
1935
+				$users_terms[] = $term;
1936
+			}
1937 1937
 
1938
-        }
1938
+		}
1939 1939
 
1940
-        return $users_terms;
1940
+		return $users_terms;
1941 1941
 
1942
-    } // end filter terms by owner
1942
+	} // end filter terms by owner
1943 1943
 
1944
-    /**
1945
-     * Add the teacher name next to modules. Only works in Admin for Admin users.
1946
-     * This will not add name to terms belonging to admin user.
1947
-     *
1948
-     * Hooked into 'get_terms'
1949
-     *
1950
-     * @since 1.8.0
1951
-     */
1952
-    public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1953
-    {
1944
+	/**
1945
+	 * Add the teacher name next to modules. Only works in Admin for Admin users.
1946
+	 * This will not add name to terms belonging to admin user.
1947
+	 *
1948
+	 * Hooked into 'get_terms'
1949
+	 *
1950
+	 * @since 1.8.0
1951
+	 */
1952
+	public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1953
+	{
1954 1954
 
1955
-        // only for admin users ont he module taxonomy
1956
-        if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1957
-            return $terms;
1958
-        }
1955
+		// only for admin users ont he module taxonomy
1956
+		if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1957
+			return $terms;
1958
+		}
1959 1959
 
1960
-        // in certain cases the array is passed in as reference to the parent term_id => parent_id
1961
-        // simply return this as wp doesn't need an array of stdObject Term
1962
-        if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1960
+		// in certain cases the array is passed in as reference to the parent term_id => parent_id
1961
+		// simply return this as wp doesn't need an array of stdObject Term
1962
+		if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1963 1963
 
1964
-            return $terms;
1964
+			return $terms;
1965 1965
 
1966
-        }
1966
+		}
1967 1967
 
1968
-        // loop through and update all terms adding the author name
1969
-        foreach( $terms as $index => $term ){
1968
+		// loop through and update all terms adding the author name
1969
+		foreach( $terms as $index => $term ){
1970 1970
 
1971
-            if( is_numeric( $term ) ){
1972
-                // the term id was given, get the term object
1973
-                $term = get_term( $term, 'module' );
1974
-            }
1971
+			if( is_numeric( $term ) ){
1972
+				// the term id was given, get the term object
1973
+				$term = get_term( $term, 'module' );
1974
+			}
1975 1975
 
1976
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1976
+			$author = Sensei_Core_Modules::get_term_author( $term->slug );
1977 1977
 
1978
-            if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) {
1979
-                $term->name = $term->name . ' (' . $author->display_name . ') ';
1980
-            }
1978
+			if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) {
1979
+				$term->name = $term->name . ' (' . $author->display_name . ') ';
1980
+			}
1981 1981
 
1982
-            // add the term to the teachers terms
1983
-            $users_terms[] = $term;
1982
+			// add the term to the teachers terms
1983
+			$users_terms[] = $term;
1984 1984
 
1985
-        }
1985
+		}
1986 1986
 
1987
-        return $users_terms;
1988
-    }
1987
+		return $users_terms;
1988
+	}
1989 1989
 
1990
-    /**
1991
-     * Remove modules metabox that come by default
1992
-     * with the modules taxonomy. We are removing this as
1993
-     * we have created our own custom meta box.
1994
-     */
1995
-    public static function remove_default_modules_box() {
1990
+	/**
1991
+	 * Remove modules metabox that come by default
1992
+	 * with the modules taxonomy. We are removing this as
1993
+	 * we have created our own custom meta box.
1994
+	 */
1995
+	public static function remove_default_modules_box() {
1996 1996
 
1997
-        remove_meta_box('modulediv', 'course', 'side');
1997
+		remove_meta_box('modulediv', 'course', 'side');
1998 1998
 
1999
-    }
1999
+	}
2000 2000
 
2001
-    /**
2002
-     * When a course is save make sure to reset the transient set
2003
-     * for it when determining the none module lessons.
2004
-     *
2005
-     * @sine 1.9.0
2006
-     * @param $post_id
2007
-     */
2008
-    public static function reset_none_modules_transient ( $post_id ){
2001
+	/**
2002
+	 * When a course is save make sure to reset the transient set
2003
+	 * for it when determining the none module lessons.
2004
+	 *
2005
+	 * @sine 1.9.0
2006
+	 * @param $post_id
2007
+	 */
2008
+	public static function reset_none_modules_transient ( $post_id ){
2009 2009
 
2010
-        // this should only apply to course and lesson post types
2011
-        if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2010
+		// this should only apply to course and lesson post types
2011
+		if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2012 2012
 
2013
-            $course_id = '';
2013
+			$course_id = '';
2014 2014
 
2015
-            if( 'lesson' == get_post_type( $post_id ) ){
2015
+			if( 'lesson' == get_post_type( $post_id ) ){
2016 2016
 
2017
-                $course_id = Sensei()->lesson->get_course_id( $post_id );
2017
+				$course_id = Sensei()->lesson->get_course_id( $post_id );
2018 2018
 
2019
-            }
2019
+			}
2020 2020
 
2021 2021
 
2022
-            if( !empty( $course_id ) ){
2022
+			if( !empty( $course_id ) ){
2023 2023
 
2024
-                delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2024
+				delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2025 2025
 
2026
-            }
2026
+			}
2027 2027
 
2028
-        } // end if is a course or a lesson
2028
+		} // end if is a course or a lesson
2029 2029
 
2030
-    } // end reset_none_modules_transient
2030
+	} // end reset_none_modules_transient
2031 2031
 
2032
-    /**
2033
-     * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire
2034
-     *
2035
-     * @since 1.9.0
2036
-     * @deprecated since 1.9.0
2037
-     *
2038
-     */
2039
-    public static function deprecate_sensei_single_course_modules_content(){
2032
+	/**
2033
+	 * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire
2034
+	 *
2035
+	 * @since 1.9.0
2036
+	 * @deprecated since 1.9.0
2037
+	 *
2038
+	 */
2039
+	public static function deprecate_sensei_single_course_modules_content(){
2040 2040
 
2041
-        sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2041
+		sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2042 2042
 
2043
-    }
2043
+	}
2044 2044
 
2045
-    /**
2046
-     * Setup the single course module loop.
2047
-     *
2048
-     * Setup the global $sensei_modules_loop
2049
-     *
2050
-     * @since 1.9.0
2051
-     */
2052
-    public static function setup_single_course_module_loop(){
2045
+	/**
2046
+	 * Setup the single course module loop.
2047
+	 *
2048
+	 * Setup the global $sensei_modules_loop
2049
+	 *
2050
+	 * @since 1.9.0
2051
+	 */
2052
+	public static function setup_single_course_module_loop(){
2053 2053
 
2054
-        global $sensei_modules_loop, $post;
2055
-        $course_id = $post->ID;
2054
+		global $sensei_modules_loop, $post;
2055
+		$course_id = $post->ID;
2056 2056
 
2057
-        $modules = Sensei()->modules->get_course_modules( $course_id );
2057
+		$modules = Sensei()->modules->get_course_modules( $course_id );
2058 2058
 
2059
-        //initial setup
2060
-        $sensei_modules_loop['total'] = 0;
2061
-        $sensei_modules_loop['modules'] = array();
2062
-        $sensei_modules_loop['current'] = -1;
2059
+		//initial setup
2060
+		$sensei_modules_loop['total'] = 0;
2061
+		$sensei_modules_loop['modules'] = array();
2062
+		$sensei_modules_loop['current'] = -1;
2063 2063
 
2064
-        // exit if this course doesn't have modules
2065
-        if( !$modules || empty( $modules )  ){
2066
-            return;
2067
-        }
2064
+		// exit if this course doesn't have modules
2065
+		if( !$modules || empty( $modules )  ){
2066
+			return;
2067
+		}
2068 2068
 
2069 2069
 
2070
-        $lessons_in_all_modules = array();
2071
-        foreach( $modules as $term ){
2070
+		$lessons_in_all_modules = array();
2071
+		foreach( $modules as $term ){
2072 2072
 
2073
-            $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2074
-            $lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2073
+			$lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2074
+			$lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2075 2075
 
2076
-        }
2076
+		}
2077 2077
 
2078 2078
 
2079
-        //setup all of the modules loop variables
2080
-        $sensei_modules_loop['total'] = count( $modules );
2081
-        $sensei_modules_loop['modules'] = $modules;
2082
-        $sensei_modules_loop['current'] = -1;
2083
-        $sensei_modules_loop['course_id'] = $course_id;
2079
+		//setup all of the modules loop variables
2080
+		$sensei_modules_loop['total'] = count( $modules );
2081
+		$sensei_modules_loop['modules'] = $modules;
2082
+		$sensei_modules_loop['current'] = -1;
2083
+		$sensei_modules_loop['course_id'] = $course_id;
2084 2084
 
2085
-    }// end setup_single_course_module_loop
2085
+	}// end setup_single_course_module_loop
2086 2086
 
2087
-    /**
2088
-     * Tear down the course module loop.
2089
-     *
2090
-     * @since 1.9.0
2091
-     *
2092
-     */
2093
-    public static function teardown_single_course_module_loop(){
2087
+	/**
2088
+	 * Tear down the course module loop.
2089
+	 *
2090
+	 * @since 1.9.0
2091
+	 *
2092
+	 */
2093
+	public static function teardown_single_course_module_loop(){
2094 2094
 
2095
-        global $sensei_modules_loop, $wp_query, $post;
2095
+		global $sensei_modules_loop, $wp_query, $post;
2096 2096
 
2097
-        //reset all of the modules loop variables
2098
-        $sensei_modules_loop['total'] = 0;
2099
-        $sensei_modules_loop['modules'] = array();
2100
-        $sensei_modules_loop['current'] = -1;
2097
+		//reset all of the modules loop variables
2098
+		$sensei_modules_loop['total'] = 0;
2099
+		$sensei_modules_loop['modules'] = array();
2100
+		$sensei_modules_loop['current'] = -1;
2101 2101
 
2102
-        // set the current course to be the global post again
2103
-        wp_reset_query();
2104
-        $post = $wp_query->post;
2105
-    }// end teardown_single_course_module_loop
2102
+		// set the current course to be the global post again
2103
+		wp_reset_query();
2104
+		$post = $wp_query->post;
2105
+	}// end teardown_single_course_module_loop
2106 2106
 
2107 2107
 } // end modules class
Please login to merge, or discard this patch.