Completed
Push — master ( 77803a...2e041b )
by Dwain
26:34
created
includes/class-sensei-analysis-overview-list-table.php 1 patch
Indentation   +19 added lines, -19 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
 
@@ -419,8 +419,8 @@  discard block
 block discarded – undo
419 419
 
420 420
 				// Output the users data
421 421
 				if ( $this->csv_output ) {
422
-                    $user_name = Sensei_Learner::get_full_name( $item->ID );
423
-                }
422
+					$user_name = Sensei_Learner::get_full_name( $item->ID );
423
+				}
424 424
 				else {
425 425
 					$url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->ID ), admin_url( 'admin.php' ) );
426 426
 					$user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $item->display_name . '</a></strong>';
@@ -514,17 +514,17 @@  discard block
 block discarded – undo
514 514
 		// This stops the full meta data of each user being loaded
515 515
 		$args['fields'] = array( 'ID', 'user_login', 'user_email', 'user_registered', 'display_name' );
516 516
 
517
-        /**
518
-         * Filter the WP_User_Query arguments
519
-         * @since 1.6.0
520
-         * @param $args
521
-         */
522
-        $args = apply_filters( 'sensei_analysis_overview_filter_users', $args );
517
+		/**
518
+		 * Filter the WP_User_Query arguments
519
+		 * @since 1.6.0
520
+		 * @param $args
521
+		 */
522
+		$args = apply_filters( 'sensei_analysis_overview_filter_users', $args );
523 523
 		$wp_user_search = new WP_User_Query( $args );
524
-        $learners = $wp_user_search->get_results();
524
+		$learners = $wp_user_search->get_results();
525 525
 		$this->total_items = $wp_user_search->get_total();
526 526
 
527
-        return $learners;
527
+		return $learners;
528 528
 
529 529
 	} // End get_learners()
530 530
 
Please login to merge, or discard this patch.
includes/class-sensei-settings-api.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  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 62
 		add_action( 'init', array( $this, 'general_init' ) );
63 63
 
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 	 * @return void
354 354
 	 */
355 355
 	public function settings_errors () {
356
-        settings_errors( $this->token . '-errors' );
356
+		settings_errors( $this->token . '-errors' );
357 357
 	} // End settings_errors()
358 358
 
359 359
 	/**
@@ -419,9 +419,9 @@  discard block
 block discarded – undo
419 419
 		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";
420 420
 		if ( $has_description ) {
421 421
 			echo wp_kses( $args['data']['description'], array( 'a' => array(
422
-																	        'href' => array(),
423
-																	        'title' => array()
424
-																	    )
422
+																			'href' => array(),
423
+																			'title' => array()
424
+																		)
425 425
 															)
426 426
 						) . '</label>' . "\n";
427 427
 		}
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
 	 */
811 811
 	public function enqueue_scripts () {
812 812
 
813
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
813
+		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
814 814
 
815 815
 		wp_enqueue_script( 'farbtastic' );
816 816
 		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   +1880 added lines, -1880 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,1397 +335,1397 @@  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 ) || isset( $modules['errors']  ) ){
1173
-            return false;
1174
-        }
1175
-
1176
-       // get the last item in the array there should be only be 1 really.
1177
-       // this method works for all php versions.
1178
-       foreach( $modules as $module ){
1179
-           break;
1180
-       }
1181
-
1182
-        if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) {
1183
-            return false;
1184
-        }
1185
-
1186
-        $module->url = get_term_link($module, $this->taxonomy);
1187
-        $course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true));
1188
-        if (isset($course_id) && 0 < $course_id) {
1189
-
1190
-            // the course should contain the same module taxonomy term for this to be valid
1191
-            if( ! has_term( $module, $this->taxonomy, $course_id)){
1192
-                return false;
1193
-            }
1194
-
1195
-            $module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url));
1196
-        }
1197
-        return $module;
1198
-
1199
-    }
1200
-
1201
-    /**
1202
-     * Get ordered array of all modules in course
1203
-     *
1204
-     * @since 1.8.0
1205
-     *
1206
-     * @param  integer $course_id ID of course
1207
-     * @return array              Ordered array of module taxonomy term objects
1208
-     */
1209
-    public function get_course_modules($course_id = 0)
1210
-    {
1211
-        $course_id = intval($course_id);
1212
-        if (0 < $course_id) {
1213
-
1214
-            // Get modules for course
1215
-            $modules = wp_get_post_terms($course_id, $this->taxonomy);
1216
-
1217
-            // Get custom module order for course
1218
-            $order = $this->get_course_module_order($course_id);
1219
-
1220
-            // Sort by custom order if custom order exists
1221
-            if ($order) {
1222
-                $ordered_modules = array();
1223
-                $unordered_modules = array();
1224
-                foreach ($modules as $module) {
1225
-                    $order_key = array_search($module->term_id, $order);
1226
-                    if ($order_key !== false) {
1227
-                        $ordered_modules[$order_key] = $module;
1228
-                    } else {
1229
-                        $unordered_modules[] = $module;
1230
-                    }
1231
-                }
1232
-
1233
-                // Order modules correctly
1234
-                ksort($ordered_modules);
1235
-
1236
-                // Append modules that have not yet been ordered
1237
-                if (count($unordered_modules) > 0) {
1238
-                    $ordered_modules = array_merge($ordered_modules, $unordered_modules);
1239
-                }
1240
-
1241
-            } else {
1242
-
1243
-                $ordered_modules = $modules;
1244
-
1245
-            }
1246
-
1247
-            return $ordered_modules;
1248
-
1249
-        }
1250
-
1251
-        return false;
1252
-    }
1253
-
1254
-    /**
1255
-     * Load frontend CSS
1256
-     *
1257
-     * @since 1.8.0
1258
-     *
1259
-     * @return void
1260
-     */
1261
-    public function enqueue_styles() {
1262
-
1263
-        wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1264
-        wp_enqueue_style($this->taxonomy . '-frontend');
1265
-
1266
-    }
1267
-
1268
-    /**
1269
-     * Load admin Javascript
1270
-     *
1271
-     * @since 1.8.0
1272
-     *
1273
-     * @return void
1274
-     */
1275
-    public function admin_enqueue_scripts( $hook ) {
1276
-
1277
-        /**
1278
-         * Filter the page hooks where modules admin script can be loaded on.
1279
-         *
1280
-         * @param array $white_listed_pages
1281
-         */
1282
-        $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1283
-            'edit-tags.php',
1284
-            'course_page_module-order',
1285
-            'post-new.php',
1286
-            'post.php'
1287
-        ) );
1288
-
1289
-        if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1290
-            return;
1291
-        }
1292
-
1293
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1294
-
1295
-        wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1296
-        wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1297
-        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', 'select2' ), Sensei()->version, true );
1298
-
1299
-        // localized module data
1300
-        $localize_modulesAdmin = array(
1301
-            'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1302
-            'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1303
-        );
1304
-
1305
-        wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1306
-    }
1307
-
1308
-    /**
1309
-     * Load admin CSS
1310
-     *
1311
-     * @since 1.8.0
1312
-     *
1313
-     * @return void
1314
-     */
1315
-    public function admin_enqueue_styles() {
1316
-
1317
-        wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1318
-        wp_enqueue_style($this->taxonomy . '-sortable');
1319
-
1320
-    }
1321
-
1322
-    /**
1323
-     * Show the title modules on the single course template.
1324
-     *
1325
-     * Function is hooked into sensei_single_course_modules_before.
1326
-     *
1327
-     * @since 1.8.0
1328
-     * @return void
1329
-     */
1330
-    public function course_modules_title( ) {
1331
-
1332
-       if( sensei_module_has_lessons() ){
1333
-
1334
-            echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1335
-
1336
-        }
1337
-
1338
-    }
1339
-
1340
-    /**
1341
-     * Display the single course modules content this will only show
1342
-     * if the course has modules.
1343
-     *
1344
-     * @since 1.8.0
1345
-     * @return void
1346
-     */
1347
-    public function load_course_module_content_template(){
1348
-
1349
-        // load backwards compatible template name if it exists in the users theme
1350
-        $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1351
-        if( $located_template ){
1352
-
1353
-            Sensei_Templates::get_template( 'single-course/course-modules.php' );
1354
-            return;
1355
-
1356
-        }
1357
-
1358
-        Sensei_Templates::get_template( 'single-course/modules.php' );
1359
-
1360
-    } // end course_module_content
1361
-
1362
-    /**
1363
-     * Returns all lessons for the given module ID
1364
-     *
1365
-     * @since 1.8.0
1366
-     *
1367
-     * @param $course_id
1368
-     * @param $term_id
1369
-     * @return array $lessons
1370
-     */
1371
-    public function get_lessons( $course_id , $term_id ){
1372
-
1373
-        $lesson_query = $this->get_lessons_query( $course_id, $term_id );
1374
-
1375
-        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 ) || isset( $modules['errors']  ) ){
1173
+			return false;
1174
+		}
1175
+
1176
+	   // get the last item in the array there should be only be 1 really.
1177
+	   // this method works for all php versions.
1178
+	   foreach( $modules as $module ){
1179
+		   break;
1180
+	   }
1181
+
1182
+		if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) {
1183
+			return false;
1184
+		}
1185
+
1186
+		$module->url = get_term_link($module, $this->taxonomy);
1187
+		$course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true));
1188
+		if (isset($course_id) && 0 < $course_id) {
1189
+
1190
+			// the course should contain the same module taxonomy term for this to be valid
1191
+			if( ! has_term( $module, $this->taxonomy, $course_id)){
1192
+				return false;
1193
+			}
1194
+
1195
+			$module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url));
1196
+		}
1197
+		return $module;
1198
+
1199
+	}
1200
+
1201
+	/**
1202
+	 * Get ordered array of all modules in course
1203
+	 *
1204
+	 * @since 1.8.0
1205
+	 *
1206
+	 * @param  integer $course_id ID of course
1207
+	 * @return array              Ordered array of module taxonomy term objects
1208
+	 */
1209
+	public function get_course_modules($course_id = 0)
1210
+	{
1211
+		$course_id = intval($course_id);
1212
+		if (0 < $course_id) {
1213
+
1214
+			// Get modules for course
1215
+			$modules = wp_get_post_terms($course_id, $this->taxonomy);
1216
+
1217
+			// Get custom module order for course
1218
+			$order = $this->get_course_module_order($course_id);
1219
+
1220
+			// Sort by custom order if custom order exists
1221
+			if ($order) {
1222
+				$ordered_modules = array();
1223
+				$unordered_modules = array();
1224
+				foreach ($modules as $module) {
1225
+					$order_key = array_search($module->term_id, $order);
1226
+					if ($order_key !== false) {
1227
+						$ordered_modules[$order_key] = $module;
1228
+					} else {
1229
+						$unordered_modules[] = $module;
1230
+					}
1231
+				}
1232
+
1233
+				// Order modules correctly
1234
+				ksort($ordered_modules);
1235
+
1236
+				// Append modules that have not yet been ordered
1237
+				if (count($unordered_modules) > 0) {
1238
+					$ordered_modules = array_merge($ordered_modules, $unordered_modules);
1239
+				}
1240
+
1241
+			} else {
1242
+
1243
+				$ordered_modules = $modules;
1244
+
1245
+			}
1246
+
1247
+			return $ordered_modules;
1248
+
1249
+		}
1250
+
1251
+		return false;
1252
+	}
1253
+
1254
+	/**
1255
+	 * Load frontend CSS
1256
+	 *
1257
+	 * @since 1.8.0
1258
+	 *
1259
+	 * @return void
1260
+	 */
1261
+	public function enqueue_styles() {
1262
+
1263
+		wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1264
+		wp_enqueue_style($this->taxonomy . '-frontend');
1265
+
1266
+	}
1267
+
1268
+	/**
1269
+	 * Load admin Javascript
1270
+	 *
1271
+	 * @since 1.8.0
1272
+	 *
1273
+	 * @return void
1274
+	 */
1275
+	public function admin_enqueue_scripts( $hook ) {
1276
+
1277
+		/**
1278
+		 * Filter the page hooks where modules admin script can be loaded on.
1279
+		 *
1280
+		 * @param array $white_listed_pages
1281
+		 */
1282
+		$script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1283
+			'edit-tags.php',
1284
+			'course_page_module-order',
1285
+			'post-new.php',
1286
+			'post.php'
1287
+		) );
1288
+
1289
+		if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1290
+			return;
1291
+		}
1292
+
1293
+		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1294
+
1295
+		wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1296
+		wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1297
+		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', 'select2' ), Sensei()->version, true );
1298
+
1299
+		// localized module data
1300
+		$localize_modulesAdmin = array(
1301
+			'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1302
+			'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1303
+		);
1304
+
1305
+		wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1306
+	}
1307
+
1308
+	/**
1309
+	 * Load admin CSS
1310
+	 *
1311
+	 * @since 1.8.0
1312
+	 *
1313
+	 * @return void
1314
+	 */
1315
+	public function admin_enqueue_styles() {
1316
+
1317
+		wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1318
+		wp_enqueue_style($this->taxonomy . '-sortable');
1319
+
1320
+	}
1321
+
1322
+	/**
1323
+	 * Show the title modules on the single course template.
1324
+	 *
1325
+	 * Function is hooked into sensei_single_course_modules_before.
1326
+	 *
1327
+	 * @since 1.8.0
1328
+	 * @return void
1329
+	 */
1330
+	public function course_modules_title( ) {
1331
+
1332
+	   if( sensei_module_has_lessons() ){
1333
+
1334
+			echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1335
+
1336
+		}
1337
+
1338
+	}
1339
+
1340
+	/**
1341
+	 * Display the single course modules content this will only show
1342
+	 * if the course has modules.
1343
+	 *
1344
+	 * @since 1.8.0
1345
+	 * @return void
1346
+	 */
1347
+	public function load_course_module_content_template(){
1348
+
1349
+		// load backwards compatible template name if it exists in the users theme
1350
+		$located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1351
+		if( $located_template ){
1352
+
1353
+			Sensei_Templates::get_template( 'single-course/course-modules.php' );
1354
+			return;
1355
+
1356
+		}
1357
+
1358
+		Sensei_Templates::get_template( 'single-course/modules.php' );
1359
+
1360
+	} // end course_module_content
1361
+
1362
+	/**
1363
+	 * Returns all lessons for the given module ID
1364
+	 *
1365
+	 * @since 1.8.0
1366
+	 *
1367
+	 * @param $course_id
1368
+	 * @param $term_id
1369
+	 * @return array $lessons
1370
+	 */
1371
+	public function get_lessons( $course_id , $term_id ){
1372
+
1373
+		$lesson_query = $this->get_lessons_query( $course_id, $term_id );
1374
+
1375
+		if( isset( $lesson_query->posts ) ){
1376 1376
 
1377
-            return $lesson_query->posts;
1377
+			return $lesson_query->posts;
1378 1378
 
1379
-        }else{
1379
+		}else{
1380 1380
 
1381
-            return array();
1381
+			return array();
1382 1382
 
1383
-        }
1383
+		}
1384 1384
 
1385
-    } // end get lessons
1385
+	} // end get lessons
1386 1386
 
1387
-    /**
1388
-     * Returns all lessons for the given module ID
1389
-     *
1390
-     * @since 1.8.0
1391
-     *
1392
-     * @param $course_id
1393
-     * @param $term_id
1394
-     * @return WP_Query $lessons_query
1395
-     */
1396
-    public function get_lessons_query( $course_id , $term_id ){
1397
-
1398
-        if( empty( $term_id ) || empty( $course_id ) ){
1399
-
1400
-            return array();
1401
-
1402
-        }
1403
-
1404
-        $args = array(
1405
-            'post_type' => 'lesson',
1406
-            'post_status' => 'publish',
1407
-            'posts_per_page' => -1,
1408
-            'meta_query' => array(
1409
-                array(
1410
-                    'key' => '_lesson_course',
1411
-                    'value' => intval($course_id),
1412
-                    'compare' => '='
1413
-                )
1414
-            ),
1415
-            'tax_query' => array(
1416
-                array(
1417
-                    'taxonomy' => 'module',
1418
-                    'field' => 'id',
1419
-                    'terms' => intval( $term_id )
1420
-                )
1421
-            ),
1422
-            'orderby' => 'menu_order',
1423
-            'order' => 'ASC',
1424
-            'suppress_filters' => 0
1425
-        );
1426
-
1427
-        if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1428
-            $args['meta_key'] = '_order_module_' . intval( $term_id );
1429
-            $args['orderby'] = 'meta_value_num date';
1430
-        }
1431
-
1432
-        $lessons_query = new WP_Query( $args );
1433
-
1434
-        return $lessons_query;
1435
-
1436
-    } // end get lessons
1437
-
1438
-    /**
1439
-     * Find the lesson in the given course that doesn't belong
1440
-     * to any of the courses modules
1441
-     *
1442
-     *
1443
-     * @param $course_id
1444
-     *
1445
-     * @return array $non_module_lessons
1446
-     */
1447
-    public function get_none_module_lessons( $course_id ){
1448
-
1449
-        $non_module_lessons = array();
1450
-
1451
-        //exit if there is no course id passed in
1452
-        if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1453
-
1454
-            return $non_module_lessons;
1455
-        }
1456
-
1457
-        //save some time and check if we already have the saved
1458
-        if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1459
-
1460
-            return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1461
-
1462
-        }
1463
-
1464
-        // create terms array which must be excluded from other arrays
1465
-        $course_modules = $this->get_course_modules( $course_id );
1466
-
1467
-        //exit if there are no module on this course
1468
-        if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1469
-
1470
-            return  Sensei()->course->course_lessons( $course_id );
1471
-
1472
-        }
1473
-
1474
-        $terms = array();
1475
-        foreach( $course_modules as $module ){
1476
-
1477
-            array_push( $terms ,  $module->term_id );
1478
-
1479
-        }
1480
-
1481
-        $args = array(
1482
-            'post_type' => 'lesson',
1483
-            'post_status' => 'publish',
1484
-            'posts_per_page' => -1,
1485
-            'meta_query' => array(
1486
-                array(
1487
-                    'key' => '_lesson_course',
1488
-                    'value' => intval( $course_id ),
1489
-                    'compare' => '='
1490
-                )
1491
-            ),
1492
-            'tax_query' => array(
1493
-                array(
1494
-                    'taxonomy' => 'module',
1495
-                    'field' => 'id',
1496
-                    'terms' =>  $terms,
1497
-                    'operator' => 'NOT IN'
1498
-                )
1499
-            ),
1500
-            'orderby' => 'menu_order',
1501
-            'order' => 'ASC',
1502
-            'suppress_filters' => 0
1503
-        );
1504
-
1505
-        $wp_lessons_query = new WP_Query( $args );
1506
-
1507
-        if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1508
-            $non_module_lessons = $wp_lessons_query->get_posts();
1509
-            set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1510
-        }
1511
-
1512
-        return $non_module_lessons;
1513
-    } // end get_none_module_lessons
1514
-
1515
-    /**
1516
-     * Register the modules taxonomy
1517
-     *
1518
-     * @since 1.8.0
1519
-     */
1520
-    public function setup_modules_taxonomy(){
1521
-
1522
-        $labels = array(
1523
-            'name' => __('Modules', 'woothemes-sensei'),
1524
-            'singular_name' => __('Module', 'woothemes-sensei'),
1525
-            'search_items' => __('Search Modules', 'woothemes-sensei'),
1526
-            'all_items' => __('All Modules', 'woothemes-sensei'),
1527
-            'parent_item' => __('Parent Module', 'woothemes-sensei'),
1528
-            'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'),
1529
-            'edit_item' => __('Edit Module', 'woothemes-sensei'),
1530
-            'update_item' => __('Update Module', 'woothemes-sensei'),
1531
-            'add_new_item' => __('Add New Module', 'woothemes-sensei'),
1532
-            'new_item_name' => __('New Module Name', 'woothemes-sensei'),
1533
-            'menu_name' => __('Modules', 'woothemes-sensei'),
1534
-        );
1535
-
1536
-        /**
1537
-         * Filter to alter the Sensei Modules rewrite slug
1538
-         *
1539
-         * @since 1.8.0
1540
-         * @param string default 'modules'
1541
-         */
1542
-        $modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules');
1543
-
1544
-        $args = array(
1545
-            'public' => true,
1546
-            'hierarchical' => true,
1547
-            'show_admin_column' => true,
1548
-            'capabilities' => array(
1549
-                'manage_terms' => 'manage_categories',
1550
-                'edit_terms'   => 'edit_courses',
1551
-                'delete_terms' => 'manage_categories',
1552
-                'assign_terms' => 'edit_courses'
1553
-            ),
1554
-            'show_in_nav_menus' => false,
1555
-            'show_in_quick_edit' => false,
1556
-            'show_ui' => true,
1557
-            'rewrite' => array('slug' => $modules_rewrite_slug ),
1558
-            'labels' => $labels
1559
-        );
1560
-
1561
-        register_taxonomy( 'module' , array('course', 'lesson'), $args);
1562
-
1563
-    }// end setup_modules_taxonomy
1564
-
1565
-    /**
1566
-     * When the wants to edit the lesson modules redirect them to the course modules.
1567
-     *
1568
-     * This function is hooked into the admin_menu
1569
-     *
1570
-     * @since 1.8.0
1571
-     * @return void
1572
-     */
1573
-    function redirect_to_lesson_module_taxonomy_to_course( ){
1574
-
1575
-        global $typenow , $taxnow;
1576
-
1577
-        if( 'lesson'== $typenow && 'module'==$taxnow ){
1578
-            wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1579
-        }
1580
-
1581
-    }// end redirect to course taxonomy
1582
-
1583
-    /**
1584
-     * Completely remove the module menu item under lessons.
1585
-     *
1586
-     * This function is hooked into the admin_menu
1587
-     *
1588
-     * @since 1.8.0
1589
-     * @return void
1590
-     */
1591
-    public function remove_lessons_menu_model_taxonomy(){
1592
-        global $submenu;
1593
-
1594
-        if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1595
-            return; // exit
1596
-        }
1597
-
1598
-        $lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1599
-        foreach( $lesson_main_menu as $index => $sub_item ){
1600
-
1601
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1602
-                unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1603
-            }
1604
-        }
1605
-
1606
-    }// end remove lesson module tax
1607
-
1608
-    /**
1609
-     * Completely remove the second modules under courses
1610
-     *
1611
-     * This function is hooked into the admin_menu
1612
-     *
1613
-     * @since 1.8.0
1614
-     * @return void
1615
-     */
1616
-    public function remove_courses_menu_model_taxonomy(){
1617
-        global $submenu;
1618
-
1619
-        if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1620
-            return; // exit
1621
-        }
1622
-
1623
-        $course_main_menu = $submenu['edit.php?post_type=course'];
1624
-        foreach( $course_main_menu as $index => $sub_item ){
1625
-
1626
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1627
-                unset( $submenu['edit.php?post_type=course'][ $index ]);
1628
-            }
1629
-        }
1630
-
1631
-    }// end remove courses module tax
1632
-
1633
-    /**
1634
-     * Determine the author of a module term term by looking at
1635
-     * the prefixed author id. This function will query the full term object.
1636
-     * Will return the admin user author could not be determined.
1637
-     *
1638
-     * @since 1.8.0
1639
-     *
1640
-     * @param string $term_name
1641
-     * @return array $owners { type WP_User }. Empty array if none if found.
1642
-     */
1643
-    public static function get_term_authors( $term_name ){
1644
-
1645
-        $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1646
-
1647
-        $owners = array();
1648
-        if( empty( $terms ) ){
1649
-
1650
-            return $owners;
1387
+	/**
1388
+	 * Returns all lessons for the given module ID
1389
+	 *
1390
+	 * @since 1.8.0
1391
+	 *
1392
+	 * @param $course_id
1393
+	 * @param $term_id
1394
+	 * @return WP_Query $lessons_query
1395
+	 */
1396
+	public function get_lessons_query( $course_id , $term_id ){
1397
+
1398
+		if( empty( $term_id ) || empty( $course_id ) ){
1399
+
1400
+			return array();
1401
+
1402
+		}
1403
+
1404
+		$args = array(
1405
+			'post_type' => 'lesson',
1406
+			'post_status' => 'publish',
1407
+			'posts_per_page' => -1,
1408
+			'meta_query' => array(
1409
+				array(
1410
+					'key' => '_lesson_course',
1411
+					'value' => intval($course_id),
1412
+					'compare' => '='
1413
+				)
1414
+			),
1415
+			'tax_query' => array(
1416
+				array(
1417
+					'taxonomy' => 'module',
1418
+					'field' => 'id',
1419
+					'terms' => intval( $term_id )
1420
+				)
1421
+			),
1422
+			'orderby' => 'menu_order',
1423
+			'order' => 'ASC',
1424
+			'suppress_filters' => 0
1425
+		);
1426
+
1427
+		if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1428
+			$args['meta_key'] = '_order_module_' . intval( $term_id );
1429
+			$args['orderby'] = 'meta_value_num date';
1430
+		}
1431
+
1432
+		$lessons_query = new WP_Query( $args );
1433
+
1434
+		return $lessons_query;
1435
+
1436
+	} // end get lessons
1437
+
1438
+	/**
1439
+	 * Find the lesson in the given course that doesn't belong
1440
+	 * to any of the courses modules
1441
+	 *
1442
+	 *
1443
+	 * @param $course_id
1444
+	 *
1445
+	 * @return array $non_module_lessons
1446
+	 */
1447
+	public function get_none_module_lessons( $course_id ){
1448
+
1449
+		$non_module_lessons = array();
1450
+
1451
+		//exit if there is no course id passed in
1452
+		if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1453
+
1454
+			return $non_module_lessons;
1455
+		}
1456
+
1457
+		//save some time and check if we already have the saved
1458
+		if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1459
+
1460
+			return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1461
+
1462
+		}
1463
+
1464
+		// create terms array which must be excluded from other arrays
1465
+		$course_modules = $this->get_course_modules( $course_id );
1466
+
1467
+		//exit if there are no module on this course
1468
+		if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1469
+
1470
+			return  Sensei()->course->course_lessons( $course_id );
1471
+
1472
+		}
1473
+
1474
+		$terms = array();
1475
+		foreach( $course_modules as $module ){
1476
+
1477
+			array_push( $terms ,  $module->term_id );
1478
+
1479
+		}
1480
+
1481
+		$args = array(
1482
+			'post_type' => 'lesson',
1483
+			'post_status' => 'publish',
1484
+			'posts_per_page' => -1,
1485
+			'meta_query' => array(
1486
+				array(
1487
+					'key' => '_lesson_course',
1488
+					'value' => intval( $course_id ),
1489
+					'compare' => '='
1490
+				)
1491
+			),
1492
+			'tax_query' => array(
1493
+				array(
1494
+					'taxonomy' => 'module',
1495
+					'field' => 'id',
1496
+					'terms' =>  $terms,
1497
+					'operator' => 'NOT IN'
1498
+				)
1499
+			),
1500
+			'orderby' => 'menu_order',
1501
+			'order' => 'ASC',
1502
+			'suppress_filters' => 0
1503
+		);
1504
+
1505
+		$wp_lessons_query = new WP_Query( $args );
1506
+
1507
+		if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1508
+			$non_module_lessons = $wp_lessons_query->get_posts();
1509
+			set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1510
+		}
1511
+
1512
+		return $non_module_lessons;
1513
+	} // end get_none_module_lessons
1514
+
1515
+	/**
1516
+	 * Register the modules taxonomy
1517
+	 *
1518
+	 * @since 1.8.0
1519
+	 */
1520
+	public function setup_modules_taxonomy(){
1521
+
1522
+		$labels = array(
1523
+			'name' => __('Modules', 'woothemes-sensei'),
1524
+			'singular_name' => __('Module', 'woothemes-sensei'),
1525
+			'search_items' => __('Search Modules', 'woothemes-sensei'),
1526
+			'all_items' => __('All Modules', 'woothemes-sensei'),
1527
+			'parent_item' => __('Parent Module', 'woothemes-sensei'),
1528
+			'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'),
1529
+			'edit_item' => __('Edit Module', 'woothemes-sensei'),
1530
+			'update_item' => __('Update Module', 'woothemes-sensei'),
1531
+			'add_new_item' => __('Add New Module', 'woothemes-sensei'),
1532
+			'new_item_name' => __('New Module Name', 'woothemes-sensei'),
1533
+			'menu_name' => __('Modules', 'woothemes-sensei'),
1534
+		);
1535
+
1536
+		/**
1537
+		 * Filter to alter the Sensei Modules rewrite slug
1538
+		 *
1539
+		 * @since 1.8.0
1540
+		 * @param string default 'modules'
1541
+		 */
1542
+		$modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules');
1543
+
1544
+		$args = array(
1545
+			'public' => true,
1546
+			'hierarchical' => true,
1547
+			'show_admin_column' => true,
1548
+			'capabilities' => array(
1549
+				'manage_terms' => 'manage_categories',
1550
+				'edit_terms'   => 'edit_courses',
1551
+				'delete_terms' => 'manage_categories',
1552
+				'assign_terms' => 'edit_courses'
1553
+			),
1554
+			'show_in_nav_menus' => false,
1555
+			'show_in_quick_edit' => false,
1556
+			'show_ui' => true,
1557
+			'rewrite' => array('slug' => $modules_rewrite_slug ),
1558
+			'labels' => $labels
1559
+		);
1560
+
1561
+		register_taxonomy( 'module' , array('course', 'lesson'), $args);
1562
+
1563
+	}// end setup_modules_taxonomy
1564
+
1565
+	/**
1566
+	 * When the wants to edit the lesson modules redirect them to the course modules.
1567
+	 *
1568
+	 * This function is hooked into the admin_menu
1569
+	 *
1570
+	 * @since 1.8.0
1571
+	 * @return void
1572
+	 */
1573
+	function redirect_to_lesson_module_taxonomy_to_course( ){
1574
+
1575
+		global $typenow , $taxnow;
1576
+
1577
+		if( 'lesson'== $typenow && 'module'==$taxnow ){
1578
+			wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1579
+		}
1580
+
1581
+	}// end redirect to course taxonomy
1582
+
1583
+	/**
1584
+	 * Completely remove the module menu item under lessons.
1585
+	 *
1586
+	 * This function is hooked into the admin_menu
1587
+	 *
1588
+	 * @since 1.8.0
1589
+	 * @return void
1590
+	 */
1591
+	public function remove_lessons_menu_model_taxonomy(){
1592
+		global $submenu;
1593
+
1594
+		if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1595
+			return; // exit
1596
+		}
1597
+
1598
+		$lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1599
+		foreach( $lesson_main_menu as $index => $sub_item ){
1600
+
1601
+			if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1602
+				unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1603
+			}
1604
+		}
1605
+
1606
+	}// end remove lesson module tax
1607
+
1608
+	/**
1609
+	 * Completely remove the second modules under courses
1610
+	 *
1611
+	 * This function is hooked into the admin_menu
1612
+	 *
1613
+	 * @since 1.8.0
1614
+	 * @return void
1615
+	 */
1616
+	public function remove_courses_menu_model_taxonomy(){
1617
+		global $submenu;
1618
+
1619
+		if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1620
+			return; // exit
1621
+		}
1622
+
1623
+		$course_main_menu = $submenu['edit.php?post_type=course'];
1624
+		foreach( $course_main_menu as $index => $sub_item ){
1625
+
1626
+			if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1627
+				unset( $submenu['edit.php?post_type=course'][ $index ]);
1628
+			}
1629
+		}
1630
+
1631
+	}// end remove courses module tax
1632
+
1633
+	/**
1634
+	 * Determine the author of a module term term by looking at
1635
+	 * the prefixed author id. This function will query the full term object.
1636
+	 * Will return the admin user author could not be determined.
1637
+	 *
1638
+	 * @since 1.8.0
1639
+	 *
1640
+	 * @param string $term_name
1641
+	 * @return array $owners { type WP_User }. Empty array if none if found.
1642
+	 */
1643
+	public static function get_term_authors( $term_name ){
1644
+
1645
+		$terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1646
+
1647
+		$owners = array();
1648
+		if( empty( $terms ) ){
1649
+
1650
+			return $owners;
1651 1651
 
1652
-        }
1652
+		}
1653 1653
 
1654
-        // setup the admin user
1654
+		// setup the admin user
1655 1655
 
1656 1656
 
1657
-        //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1658
-        foreach( $terms as $term){
1659
-            if( $term->name == $term_name ){
1657
+		//if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1658
+		foreach( $terms as $term){
1659
+			if( $term->name == $term_name ){
1660 1660
 
1661
-                // look for the author in the slug
1662
-                $owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1661
+				// look for the author in the slug
1662
+				$owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1663 1663
 
1664
-            }// end if term name
1664
+			}// end if term name
1665 1665
 
1666
-        } // end for each
1666
+		} // end for each
1667 1667
 
1668
-        return $owners;
1668
+		return $owners;
1669 1669
 
1670
-    }// end get_term_author
1670
+	}// end get_term_author
1671 1671
 
1672
-    /**
1673
-     * Looks at a term slug and figures out
1674
-     * which author created the slug. The author was
1675
-     * appended when the user saved the module term in the course edit
1676
-     * screen.
1677
-     *
1678
-     * @since 1.8.0
1679
-     *
1680
-     * @param $slug
1681
-     * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1682
-     */
1683
-    public static function get_term_author( $slug='' ){
1672
+	/**
1673
+	 * Looks at a term slug and figures out
1674
+	 * which author created the slug. The author was
1675
+	 * appended when the user saved the module term in the course edit
1676
+	 * screen.
1677
+	 *
1678
+	 * @since 1.8.0
1679
+	 *
1680
+	 * @param $slug
1681
+	 * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1682
+	 */
1683
+	public static function get_term_author( $slug='' ){
1684 1684
 
1685
-        $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1685
+		$term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1686 1686
 
1687
-        if( empty( $slug ) ){
1687
+		if( empty( $slug ) ){
1688 1688
 
1689
-            return $term_owner;
1689
+			return $term_owner;
1690 1690
 
1691
-        }
1691
+		}
1692 1692
 
1693
-        // look for the author in the slug
1694
-        $slug_parts = explode( '-', $slug );
1693
+		// look for the author in the slug
1694
+		$slug_parts = explode( '-', $slug );
1695 1695
 
1696
-        if( count( $slug_parts ) > 1 ){
1696
+		if( count( $slug_parts ) > 1 ){
1697 1697
 
1698
-            // get the user data
1699
-            $possible_user_id = $slug_parts[0];
1700
-            $author = get_userdata( $possible_user_id );
1698
+			// get the user data
1699
+			$possible_user_id = $slug_parts[0];
1700
+			$author = get_userdata( $possible_user_id );
1701 1701
 
1702
-            // if the user doesnt exist for the first part of the slug
1703
-            // then this slug was also created by admin
1704
-            if( is_a( $author, 'WP_User' ) ){
1702
+			// if the user doesnt exist for the first part of the slug
1703
+			// then this slug was also created by admin
1704
+			if( is_a( $author, 'WP_User' ) ){
1705 1705
 
1706
-                $term_owner =  $author;
1706
+				$term_owner =  $author;
1707 1707
 
1708
-            }
1709
-        }
1708
+			}
1709
+		}
1710 1710
 
1711
-        return $term_owner;
1712
-    }
1711
+		return $term_owner;
1712
+	}
1713 1713
 
1714
-    /**
1715
-     * Display the Sensei modules taxonomy terms metabox
1716
-     *
1717
-     * @since 1.8.0
1718
-     *
1719
-     * @hooked into add_meta_box
1720
-     *
1721
-     * @param WP_Post $post Post object.
1722
-     */
1723
-    public function course_module_metabox( $post ) {
1714
+	/**
1715
+	 * Display the Sensei modules taxonomy terms metabox
1716
+	 *
1717
+	 * @since 1.8.0
1718
+	 *
1719
+	 * @hooked into add_meta_box
1720
+	 *
1721
+	 * @param WP_Post $post Post object.
1722
+	 */
1723
+	public function course_module_metabox( $post ) {
1724 1724
 
1725
-        $tax_name = 'module';
1726
-        $taxonomy = get_taxonomy( 'module' );
1725
+		$tax_name = 'module';
1726
+		$taxonomy = get_taxonomy( 'module' );
1727 1727
 
1728
-        ?>
1728
+		?>
1729 1729
         <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
1730 1730
             <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs">
1731 1731
                 <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li>
@@ -1740,9 +1740,9 @@  discard block
 block discarded – undo
1740 1740
 
1741 1741
             <div id="<?php echo $tax_name; ?>-all" class="tabs-panel">
1742 1742
                 <?php
1743
-                $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1744
-                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.
1745
-                ?>
1743
+				$name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1744
+				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.
1745
+				?>
1746 1746
                 <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">
1747 1747
                     <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?>
1748 1748
                 </ul>
@@ -1752,9 +1752,9 @@  discard block
 block discarded – undo
1752 1752
                     <h4>
1753 1753
                         <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js">
1754 1754
                             <?php
1755
-                            /* translators: %s: add new taxonomy label */
1756
-                            printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1757
-                            ?>
1755
+							/* translators: %s: add new taxonomy label */
1756
+							printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1757
+							?>
1758 1758
                         </a>
1759 1759
                     </h4>
1760 1760
                     <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">
@@ -1769,331 +1769,331 @@  discard block
 block discarded – undo
1769 1769
         </div>
1770 1770
     <?php
1771 1771
 
1772
-    } // end course_module_metabox
1772
+	} // end course_module_metabox
1773 1773
 
1774 1774
 
1775
-    /**
1776
-     * Submits a new module term prefixed with the
1777
-     * the current author id.
1778
-     *
1779
-     * @since 1.8.0
1780
-     */
1781
-    public static function add_new_module_term( ) {
1775
+	/**
1776
+	 * Submits a new module term prefixed with the
1777
+	 * the current author id.
1778
+	 *
1779
+	 * @since 1.8.0
1780
+	 */
1781
+	public static function add_new_module_term( ) {
1782 1782
 
1783 1783
 
1784
-        if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1785
-            wp_send_json_error( array('error'=> 'wrong security nonce') );
1786
-        }
1784
+		if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1785
+			wp_send_json_error( array('error'=> 'wrong security nonce') );
1786
+		}
1787 1787
 
1788
-        // get the term an create the new term storing infomration
1789
-        $term_name = sanitize_text_field( $_POST['newTerm'] );
1788
+		// get the term an create the new term storing infomration
1789
+		$term_name = sanitize_text_field( $_POST['newTerm'] );
1790 1790
 
1791
-        if( current_user_can('manage_options' ) ) {
1791
+		if( current_user_can('manage_options' ) ) {
1792 1792
 
1793
-            $term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1793
+			$term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1794 1794
 
1795
-        } else {
1795
+		} else {
1796 1796
 
1797
-            $term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1797
+			$term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1798 1798
 
1799
-        }
1799
+		}
1800 1800
 
1801
-        $course_id = sanitize_text_field( $_POST['course_id'] );
1801
+		$course_id = sanitize_text_field( $_POST['course_id'] );
1802 1802
 
1803
-        // save the term
1804
-        $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1803
+		// save the term
1804
+		$slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1805 1805
 
1806
-        // send error for all errors except term exits
1807
-        if( is_wp_error( $slug ) ){
1806
+		// send error for all errors except term exits
1807
+		if( is_wp_error( $slug ) ){
1808 1808
 
1809
-            // prepare for possible term name and id to be passed down if term exists
1810
-            $term_data = array();
1809
+			// prepare for possible term name and id to be passed down if term exists
1810
+			$term_data = array();
1811 1811
 
1812
-            // if term exists also send back the term name and id
1813
-            if( isset( $slug->errors['term_exists'] ) ){
1812
+			// if term exists also send back the term name and id
1813
+			if( isset( $slug->errors['term_exists'] ) ){
1814 1814
 
1815
-                $term = get_term_by( 'slug', $term_slug, 'module');
1816
-                $term_data['name'] = $term_name;
1817
-                $term_data['id'] = $term->term_id;
1815
+				$term = get_term_by( 'slug', $term_slug, 'module');
1816
+				$term_data['name'] = $term_name;
1817
+				$term_data['id'] = $term->term_id;
1818 1818
 
1819
-                // set the object terms
1820
-                wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1821
-            }
1819
+				// set the object terms
1820
+				wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1821
+			}
1822 1822
 
1823
-            wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1823
+			wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1824 1824
 
1825
-        }
1825
+		}
1826 1826
 
1827
-        //make sure the new term is checked for this course
1827
+		//make sure the new term is checked for this course
1828 1828
 
1829
-        wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1829
+		wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1830 1830
 
1831
-        // Handle request then generate response using WP_Ajax_Response
1832
-        wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1831
+		// Handle request then generate response using WP_Ajax_Response
1832
+		wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1833 1833
 
1834
-    }
1834
+	}
1835 1835
 
1836
-    /**
1837
-     * Limit the course module metabox
1838
-     * term list to only those on courses belonging to current teacher.
1839
-     *
1840
-     * Hooked into 'get_terms'
1841
-     *
1842
-     * @since 1.8.0
1843
-     */
1844
-    public function filter_module_terms( $terms, $taxonomies, $args ){
1836
+	/**
1837
+	 * Limit the course module metabox
1838
+	 * term list to only those on courses belonging to current teacher.
1839
+	 *
1840
+	 * Hooked into 'get_terms'
1841
+	 *
1842
+	 * @since 1.8.0
1843
+	 */
1844
+	public function filter_module_terms( $terms, $taxonomies, $args ){
1845 1845
 
1846
-        //dont limit for admins and other taxonomies. This should also only apply to admin
1847
-        if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1848
-            return $terms;
1849
-        }
1846
+		//dont limit for admins and other taxonomies. This should also only apply to admin
1847
+		if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1848
+			return $terms;
1849
+		}
1850 1850
 
1851
-        // avoid infinite call loop
1852
-        remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1851
+		// avoid infinite call loop
1852
+		remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1853 1853
 
1854
-        // in certain cases the array is passed in as reference to the parent term_id => parent_id
1855
-        if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1856
-            // change only scrub the terms ids form the array keys
1857
-            $terms = array_keys( $terms );
1858
-        }
1854
+		// in certain cases the array is passed in as reference to the parent term_id => parent_id
1855
+		if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1856
+			// change only scrub the terms ids form the array keys
1857
+			$terms = array_keys( $terms );
1858
+		}
1859 1859
 
1860
-        $teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1860
+		$teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1861 1861
 
1862
-        // add filter again as removed above
1863
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1862
+		// add filter again as removed above
1863
+		add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1864 1864
 
1865
-        return $teachers_terms;
1866
-    }// end filter_module_terms
1865
+		return $teachers_terms;
1866
+	}// end filter_module_terms
1867 1867
 
1868
-    /**
1869
-     * For the selected items on a course module only return those
1870
-     * for the current user. This does not apply to admin and super admin users.
1871
-     *
1872
-     * hooked into get_object_terms
1873
-     *
1874
-     * @since 1.8.0
1875
-     */
1876
-    public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1868
+	/**
1869
+	 * For the selected items on a course module only return those
1870
+	 * for the current user. This does not apply to admin and super admin users.
1871
+	 *
1872
+	 * hooked into get_object_terms
1873
+	 *
1874
+	 * @since 1.8.0
1875
+	 */
1876
+	public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1877 1877
 
1878
-        //dont limit for admins and other taxonomies. This should also only apply to admin
1879
-        if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1880
-            // only apply this to module only taxonomy queries so 1 taxonomy only:
1881
-            ||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1882
-            return $terms;
1883
-        }
1878
+		//dont limit for admins and other taxonomies. This should also only apply to admin
1879
+		if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1880
+			// only apply this to module only taxonomy queries so 1 taxonomy only:
1881
+			||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1882
+			return $terms;
1883
+		}
1884 1884
 
1885
-        $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1885
+		$term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1886 1886
 
1887
-        // if term objects were passed in send back objects
1888
-        // if term id were passed in send that back
1889
-        if( is_object( $terms[0] ) ){
1890
-            return $term_objects;
1891
-        }
1887
+		// if term objects were passed in send back objects
1888
+		// if term id were passed in send that back
1889
+		if( is_object( $terms[0] ) ){
1890
+			return $term_objects;
1891
+		}
1892 1892
 
1893
-        $terms = array();
1894
-        foreach( $term_objects as $term_object ){
1895
-            $terms[] = $term_object->term_id;
1896
-        }
1893
+		$terms = array();
1894
+		foreach( $term_objects as $term_object ){
1895
+			$terms[] = $term_object->term_id;
1896
+		}
1897 1897
 
1898
-        return $terms;
1898
+		return $terms;
1899 1899
 
1900 1900
 
1901
-    }// end filter_course_selected_terms
1901
+	}// end filter_course_selected_terms
1902 1902
 
1903
-    /**
1904
-     * Filter the given terms and only return the
1905
-     * terms that belong to the given user id.
1906
-     *
1907
-     * @since 1.8.0
1908
-     * @param $terms
1909
-     * @param $user_id
1910
-     * @return array
1911
-     */
1912
-    public function filter_terms_by_owner( $terms, $user_id ){
1903
+	/**
1904
+	 * Filter the given terms and only return the
1905
+	 * terms that belong to the given user id.
1906
+	 *
1907
+	 * @since 1.8.0
1908
+	 * @param $terms
1909
+	 * @param $user_id
1910
+	 * @return array
1911
+	 */
1912
+	public function filter_terms_by_owner( $terms, $user_id ){
1913 1913
 
1914
-        $users_terms = array();
1914
+		$users_terms = array();
1915 1915
 
1916
-        foreach( $terms as $index => $term ){
1916
+		foreach( $terms as $index => $term ){
1917 1917
 
1918
-            if( is_numeric( $term ) ){
1919
-                // the term id was given, get the term object
1920
-                $term = get_term( $term, 'module' );
1921
-            }
1918
+			if( is_numeric( $term ) ){
1919
+				// the term id was given, get the term object
1920
+				$term = get_term( $term, 'module' );
1921
+			}
1922 1922
 
1923
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1923
+			$author = Sensei_Core_Modules::get_term_author( $term->slug );
1924 1924
 
1925
-            if ( $user_id == $author->ID ) {
1926
-                // add the term to the teachers terms
1927
-                $users_terms[] = $term;
1928
-            }
1925
+			if ( $user_id == $author->ID ) {
1926
+				// add the term to the teachers terms
1927
+				$users_terms[] = $term;
1928
+			}
1929 1929
 
1930
-        }
1930
+		}
1931 1931
 
1932
-        return $users_terms;
1932
+		return $users_terms;
1933 1933
 
1934
-    } // end filter terms by owner
1934
+	} // end filter terms by owner
1935 1935
 
1936
-    /**
1937
-     * Add the teacher name next to modules. Only works in Admin for Admin users.
1938
-     * This will not add name to terms belonging to admin user.
1939
-     *
1940
-     * Hooked into 'get_terms'
1941
-     *
1942
-     * @since 1.8.0
1943
-     */
1944
-    public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1945
-    {
1936
+	/**
1937
+	 * Add the teacher name next to modules. Only works in Admin for Admin users.
1938
+	 * This will not add name to terms belonging to admin user.
1939
+	 *
1940
+	 * Hooked into 'get_terms'
1941
+	 *
1942
+	 * @since 1.8.0
1943
+	 */
1944
+	public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1945
+	{
1946 1946
 
1947
-        // only for admin users ont he module taxonomy
1948
-        if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1949
-            return $terms;
1950
-        }
1947
+		// only for admin users ont he module taxonomy
1948
+		if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1949
+			return $terms;
1950
+		}
1951 1951
 
1952
-        // in certain cases the array is passed in as reference to the parent term_id => parent_id
1953
-        // simply return this as wp doesn't need an array of stdObject Term
1954
-        if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1952
+		// in certain cases the array is passed in as reference to the parent term_id => parent_id
1953
+		// simply return this as wp doesn't need an array of stdObject Term
1954
+		if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1955 1955
 
1956
-            return $terms;
1956
+			return $terms;
1957 1957
 
1958
-        }
1958
+		}
1959 1959
 
1960
-        // loop through and update all terms adding the author name
1961
-        foreach( $terms as $index => $term ){
1960
+		// loop through and update all terms adding the author name
1961
+		foreach( $terms as $index => $term ){
1962 1962
 
1963
-            if( is_numeric( $term ) ){
1964
-                // the term id was given, get the term object
1965
-                $term = get_term( $term, 'module' );
1966
-            }
1963
+			if( is_numeric( $term ) ){
1964
+				// the term id was given, get the term object
1965
+				$term = get_term( $term, 'module' );
1966
+			}
1967 1967
 
1968
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1968
+			$author = Sensei_Core_Modules::get_term_author( $term->slug );
1969 1969
 
1970
-            if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) {
1971
-                $term->name = $term->name . ' (' . $author->display_name . ') ';
1972
-            }
1970
+			if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) {
1971
+				$term->name = $term->name . ' (' . $author->display_name . ') ';
1972
+			}
1973 1973
 
1974
-            // add the term to the teachers terms
1975
-            $users_terms[] = $term;
1974
+			// add the term to the teachers terms
1975
+			$users_terms[] = $term;
1976 1976
 
1977
-        }
1977
+		}
1978 1978
 
1979
-        return $users_terms;
1980
-    }
1979
+		return $users_terms;
1980
+	}
1981 1981
 
1982
-    /**
1983
-     * Remove modules metabox that come by default
1984
-     * with the modules taxonomy. We are removing this as
1985
-     * we have created our own custom meta box.
1986
-     */
1987
-    public static function remove_default_modules_box() {
1982
+	/**
1983
+	 * Remove modules metabox that come by default
1984
+	 * with the modules taxonomy. We are removing this as
1985
+	 * we have created our own custom meta box.
1986
+	 */
1987
+	public static function remove_default_modules_box() {
1988 1988
 
1989
-        remove_meta_box('modulediv', 'course', 'side');
1989
+		remove_meta_box('modulediv', 'course', 'side');
1990 1990
 
1991
-    }
1991
+	}
1992 1992
 
1993
-    /**
1994
-     * When a course is save make sure to reset the transient set
1995
-     * for it when determining the none module lessons.
1996
-     *
1997
-     * @sine 1.9.0
1998
-     * @param $post_id
1999
-     */
2000
-    public static function reset_none_modules_transient ( $post_id ){
1993
+	/**
1994
+	 * When a course is save make sure to reset the transient set
1995
+	 * for it when determining the none module lessons.
1996
+	 *
1997
+	 * @sine 1.9.0
1998
+	 * @param $post_id
1999
+	 */
2000
+	public static function reset_none_modules_transient ( $post_id ){
2001 2001
 
2002
-        // this should only apply to course and lesson post types
2003
-        if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2002
+		// this should only apply to course and lesson post types
2003
+		if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2004 2004
 
2005
-            $course_id = '';
2005
+			$course_id = '';
2006 2006
 
2007
-            if( 'lesson' == get_post_type( $post_id ) ){
2007
+			if( 'lesson' == get_post_type( $post_id ) ){
2008 2008
 
2009
-                $course_id = Sensei()->lesson->get_course_id( $post_id );
2009
+				$course_id = Sensei()->lesson->get_course_id( $post_id );
2010 2010
 
2011
-            }
2011
+			}
2012 2012
 
2013 2013
 
2014
-            if( !empty( $course_id ) ){
2014
+			if( !empty( $course_id ) ){
2015 2015
 
2016
-                delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2016
+				delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2017 2017
 
2018
-            }
2018
+			}
2019 2019
 
2020
-        } // end if is a course or a lesson
2020
+		} // end if is a course or a lesson
2021 2021
 
2022
-    } // end reset_none_modules_transient
2022
+	} // end reset_none_modules_transient
2023 2023
 
2024
-    /**
2025
-     * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire
2026
-     *
2027
-     * @since 1.9.0
2028
-     * @deprecated since 1.9.0
2029
-     *
2030
-     */
2031
-    public static function deprecate_sensei_single_course_modules_content(){
2024
+	/**
2025
+	 * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire
2026
+	 *
2027
+	 * @since 1.9.0
2028
+	 * @deprecated since 1.9.0
2029
+	 *
2030
+	 */
2031
+	public static function deprecate_sensei_single_course_modules_content(){
2032 2032
 
2033
-        sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2033
+		sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2034 2034
 
2035
-    }
2035
+	}
2036 2036
 
2037
-    /**
2038
-     * Setup the single course module loop.
2039
-     *
2040
-     * Setup the global $sensei_modules_loop
2041
-     *
2042
-     * @since 1.9.0
2043
-     */
2044
-    public static function setup_single_course_module_loop(){
2037
+	/**
2038
+	 * Setup the single course module loop.
2039
+	 *
2040
+	 * Setup the global $sensei_modules_loop
2041
+	 *
2042
+	 * @since 1.9.0
2043
+	 */
2044
+	public static function setup_single_course_module_loop(){
2045 2045
 
2046
-        global $sensei_modules_loop, $post;
2047
-        $course_id = $post->ID;
2046
+		global $sensei_modules_loop, $post;
2047
+		$course_id = $post->ID;
2048 2048
 
2049
-        $modules = Sensei()->modules->get_course_modules( $course_id );
2049
+		$modules = Sensei()->modules->get_course_modules( $course_id );
2050 2050
 
2051
-        //initial setup
2052
-        $sensei_modules_loop['total'] = 0;
2053
-        $sensei_modules_loop['modules'] = array();
2054
-        $sensei_modules_loop['current'] = -1;
2051
+		//initial setup
2052
+		$sensei_modules_loop['total'] = 0;
2053
+		$sensei_modules_loop['modules'] = array();
2054
+		$sensei_modules_loop['current'] = -1;
2055 2055
 
2056
-        // exit if this course doesn't have modules
2057
-        if( !$modules || empty( $modules )  ){
2058
-            return;
2059
-        }
2056
+		// exit if this course doesn't have modules
2057
+		if( !$modules || empty( $modules )  ){
2058
+			return;
2059
+		}
2060 2060
 
2061 2061
 
2062
-        $lessons_in_all_modules = array();
2063
-        foreach( $modules as $term ){
2062
+		$lessons_in_all_modules = array();
2063
+		foreach( $modules as $term ){
2064 2064
 
2065
-            $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2066
-            $lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2065
+			$lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2066
+			$lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2067 2067
 
2068
-        }
2068
+		}
2069 2069
 
2070 2070
 
2071
-        //setup all of the modules loop variables
2072
-        $sensei_modules_loop['total'] = count( $modules );
2073
-        $sensei_modules_loop['modules'] = $modules;
2074
-        $sensei_modules_loop['current'] = -1;
2075
-        $sensei_modules_loop['course_id'] = $course_id;
2071
+		//setup all of the modules loop variables
2072
+		$sensei_modules_loop['total'] = count( $modules );
2073
+		$sensei_modules_loop['modules'] = $modules;
2074
+		$sensei_modules_loop['current'] = -1;
2075
+		$sensei_modules_loop['course_id'] = $course_id;
2076 2076
 
2077
-    }// end setup_single_course_module_loop
2077
+	}// end setup_single_course_module_loop
2078 2078
 
2079
-    /**
2080
-     * Tear down the course module loop.
2081
-     *
2082
-     * @since 1.9.0
2083
-     *
2084
-     */
2085
-    public static function teardown_single_course_module_loop(){
2079
+	/**
2080
+	 * Tear down the course module loop.
2081
+	 *
2082
+	 * @since 1.9.0
2083
+	 *
2084
+	 */
2085
+	public static function teardown_single_course_module_loop(){
2086 2086
 
2087
-        global $sensei_modules_loop, $wp_query, $post;
2087
+		global $sensei_modules_loop, $wp_query, $post;
2088 2088
 
2089
-        //reset all of the modules loop variables
2090
-        $sensei_modules_loop['total'] = 0;
2091
-        $sensei_modules_loop['modules'] = array();
2092
-        $sensei_modules_loop['current'] = -1;
2089
+		//reset all of the modules loop variables
2090
+		$sensei_modules_loop['total'] = 0;
2091
+		$sensei_modules_loop['modules'] = array();
2092
+		$sensei_modules_loop['current'] = -1;
2093 2093
 
2094
-        // set the current course to be the global post again
2095
-        wp_reset_query();
2096
-        $post = $wp_query->post;
2097
-    }// end teardown_single_course_module_loop
2094
+		// set the current course to be the global post again
2095
+		wp_reset_query();
2096
+		$post = $wp_query->post;
2097
+	}// end teardown_single_course_module_loop
2098 2098
 
2099 2099
 } // end modules class
Please login to merge, or discard this patch.
includes/template-functions.php 1 patch
Indentation   +281 added lines, -282 removed lines patch added patch discarded remove patch
@@ -5,18 +5,18 @@  discard block
 block discarded – undo
5 5
 	 * 	Output tags.
6 6
 	 ***************************************************************************************************/
7 7
 
8
-    /**
9
-     * sensei_course_archive_next_link function.
10
-     *
11
-     * @access public
12
-     * @param string $type (default: 'newcourses')
13
-     * @return void
14
-     */
15
-    function sensei_course_archive_next_link( $type = 'newcourses' ) {
8
+	/**
9
+	 * sensei_course_archive_next_link function.
10
+	 *
11
+	 * @access public
12
+	 * @param string $type (default: 'newcourses')
13
+	 * @return void
14
+	 */
15
+	function sensei_course_archive_next_link( $type = 'newcourses' ) {
16 16
 
17
-        _deprecated_function('sensei_course_archive_next_link', '1.9.0','This is no longer used or required in Sensei.');
17
+		_deprecated_function('sensei_course_archive_next_link', '1.9.0','This is no longer used or required in Sensei.');
18 18
 
19
-    } // End sensei_course_archive_next_link()
19
+	} // End sensei_course_archive_next_link()
20 20
 
21 21
 	 /**
22 22
 	  * course_single_lessons function.
@@ -26,14 +26,14 @@  discard block
 block discarded – undo
26 26
 	  */
27 27
 	 function course_single_lessons() {
28 28
 
29
-         // load backwards compatible template name if it exists in the users theme
30
-         $located_template= locate_template( Sensei()->template_url . 'single-course/course-lessons.php' );
31
-         if( $located_template ){
29
+		 // load backwards compatible template name if it exists in the users theme
30
+		 $located_template= locate_template( Sensei()->template_url . 'single-course/course-lessons.php' );
31
+		 if( $located_template ){
32 32
 
33
-             Sensei_Templates::get_template( 'single-course/course-lessons.php' );
34
-             return;
33
+			 Sensei_Templates::get_template( 'single-course/course-lessons.php' );
34
+			 return;
35 35
 
36
-        }
36
+		}
37 37
 
38 38
 		Sensei_Templates::get_template( 'single-course/lessons.php' );
39 39
 
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
 	  */
49 49
 	 function lesson_single_meta() {
50 50
 
51
-         _deprecated_function('lesson_single_meta','1.9;0', 'WooThemes_Sensei_Lesson::the_lesson_meta' );
52
-         sensei_the_single_lesson_meta();
51
+		 _deprecated_function('lesson_single_meta','1.9;0', 'WooThemes_Sensei_Lesson::the_lesson_meta' );
52
+		 sensei_the_single_lesson_meta();
53 53
 
54 54
 	 } // End lesson_single_meta()
55 55
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	  * @access public
61 61
 	  * @param bool $return (default: false)
62 62
 	  * @return void
63
-      * @deprecated since 1.9.0
63
+	  * @deprecated since 1.9.0
64 64
 	  */
65 65
 	 function quiz_questions( $return = false ) {
66 66
 
@@ -74,11 +74,11 @@  discard block
 block discarded – undo
74 74
 	  * @access public
75 75
 	  * @since  1.3.0
76 76
 	  * @return void
77
-      * @deprecated
77
+	  * @deprecated
78 78
 	  */
79 79
 	 function quiz_question_type( $question_type = 'multiple-choice' ) {
80 80
 
81
-         Sensei_Templates::get_template( 'single-quiz/question_type-' . $question_type . '.php' );
81
+		 Sensei_Templates::get_template( 'single-quiz/question_type-' . $question_type . '.php' );
82 82
 
83 83
 	 } // End lesson_single_meta()
84 84
 
@@ -89,14 +89,14 @@  discard block
 block discarded – undo
89 89
 	/**
90 90
 	 * sensei_check_prerequisite_course function.
91 91
 	 *
92
-     * @deprecated since 1.9.0 use Sensei_Course::is_prerequisite_complete( $course_id );
92
+	 * @deprecated since 1.9.0 use Sensei_Course::is_prerequisite_complete( $course_id );
93 93
 	 * @access public
94 94
 	 * @param mixed $course_id
95 95
 	 * @return bool
96 96
 	 */
97 97
 	function sensei_check_prerequisite_course( $course_id ) {
98 98
 
99
-        return Sensei_Course::is_prerequisite_complete( $course_id );
99
+		return Sensei_Course::is_prerequisite_complete( $course_id );
100 100
 
101 101
 	} // End sensei_check_prerequisite_course()
102 102
 
@@ -120,14 +120,14 @@  discard block
 block discarded – undo
120 120
     			<span><input name="course_start" type="submit" class="course-start" value="<?php _e( 'Start taking this Course', 'woothemes-sensei' ); ?>"/></span>
121 121
 
122 122
     		</form><?php
123
-    	} // End If Statement
123
+		} // End If Statement
124 124
 	} // End sensei_start_course_form()
125 125
 
126 126
 
127 127
 	/**
128 128
 	 * sensei_wc_add_to_cart function.
129 129
 	 *
130
-     * @deprecated since Sensei_WC::the_add_to_cart_button_html( $course_id );
130
+	 * @deprecated since Sensei_WC::the_add_to_cart_button_html( $course_id );
131 131
 	 * @access public
132 132
 	 * @param mixed $course_id
133 133
 	 * @return void
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 	 * @return bool
148 148
 	 */
149 149
 	function sensei_check_if_product_is_in_cart( $wc_product_id = 0 ) {
150
-        return Sensei_WC::is_product_in_cart( $wc_product_id );
150
+		return Sensei_WC::is_product_in_cart( $wc_product_id );
151 151
 	} // End sensei_check_if_product_is_in_cart()
152 152
 
153 153
 	/**
@@ -160,17 +160,17 @@  discard block
 block discarded – undo
160 160
 	function sensei_simple_course_price( $post_id ) {
161 161
 
162 162
 		//WooCommerce Pricing
163
-        if ( Sensei_WC::is_woocommerce_active() ) {
164
-    	    $wc_post_id = get_post_meta( $post_id, '_course_woocommerce_product', true );
165
-    	    if ( 0 < $wc_post_id ) {
166
-    	    	// Get the product
167
-    	    	$product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
163
+		if ( Sensei_WC::is_woocommerce_active() ) {
164
+			$wc_post_id = get_post_meta( $post_id, '_course_woocommerce_product', true );
165
+			if ( 0 < $wc_post_id ) {
166
+				// Get the product
167
+				$product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
168 168
 
169
-    	    	if ( isset( $product ) && !empty( $product )  &&  $product->is_purchasable() && $product->is_in_stock() && !sensei_check_if_product_is_in_cart( $wc_post_id ) ) { ?>
169
+				if ( isset( $product ) && !empty( $product )  &&  $product->is_purchasable() && $product->is_in_stock() && !sensei_check_if_product_is_in_cart( $wc_post_id ) ) { ?>
170 170
     	    		<span class="course-price"><?php echo $product->get_price_html(); ?></span>
171 171
     	    	<?php } // End If Statement
172
-    	    } // End If Statement
173
-    	} // End If Statement
172
+			} // End If Statement
173
+		} // End If Statement
174 174
 	} // End sensei_simple_course_price()
175 175
 
176 176
 	/**
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 
198 198
 
199 199
 		if ( ! $query->is_main_query() )
200
-        	return;
200
+			return;
201 201
 
202 202
 		// Apply Filter only if on frontend and when course archive is running
203 203
 		$course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] );
@@ -205,11 +205,11 @@  discard block
 block discarded – undo
205 205
 		if ( ! is_admin() && 0 < $course_page_id && 0 < intval( $query->get( 'page_id' ) ) && $query->get( 'page_id' ) == $course_page_id ) {
206 206
 			// Check for pagination settings
207 207
    			if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) {
208
-    			$amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] );
209
-    		} else {
210
-    			$amount = $query->get( 'posts_per_page' );
211
-    		} // End If Statement
212
-    		$query->set( 'posts_per_page', $amount );
208
+				$amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] );
209
+			} else {
210
+				$amount = $query->get( 'posts_per_page' );
211
+			} // End If Statement
212
+			$query->set( 'posts_per_page', $amount );
213 213
 		} // End If Statement
214 214
 	} // End sensei_course_archive_filter()
215 215
 	add_filter( 'pre_get_posts', 'sensei_course_archive_filter', 10, 1 );
@@ -248,66 +248,66 @@  discard block
 block discarded – undo
248 248
 			$lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true );
249 249
 			$all_lessons = array();
250 250
 
251
-            $modules = Sensei()->modules->get_course_modules( intval( $lesson_course_id ) );
252
-
253
-            foreach( (array) $modules as $module ) {
254
-
255
-                $args = array(
256
-                    'post_type' => 'lesson',
257
-                    'post_status' => 'publish',
258
-                    'posts_per_page' => -1,
259
-                    'meta_query' => array(
260
-                        array(
261
-                            'key' => '_lesson_course',
262
-                            'value' => intval( $lesson_course_id ),
263
-                            'compare' => '='
264
-                        )
265
-                    ),
266
-                    'tax_query' => array(
267
-                        array(
268
-                            'taxonomy' => Sensei()->modules->taxonomy,
269
-                            'field' => 'id',
270
-                            'terms' => intval( $module->term_id )
271
-                        )
272
-                    ),
273
-                    'meta_key' => '_order_module_' . $module->term_id,
274
-                    'orderby' => 'meta_value_num date',
275
-                    'order' => 'ASC',
276
-                    'suppress_filters' => 0
277
-                );
278
-
279
-                $lessons = get_posts( $args );
280
-                if ( 0 < count( $lessons ) ) {
281
-                    foreach ($lessons as $lesson_item){
282
-                        $all_lessons[] = $lesson_item->ID;
283
-                    } // End For Loop
284
-                } // End If Statement
285
-            }
286
-
287
-            $args = array(
288
-                'post_type' => 'lesson',
289
-                'posts_per_page' => -1,
290
-                'suppress_filters' => 0,
291
-                'meta_key' => '_order_' . $lesson_course_id,
292
-                'orderby' => 'meta_value_num date',
293
-                'order' => 'ASC',
294
-                'meta_query' => array(
295
-                    array(
296
-                        'key' => '_lesson_course',
297
-                        'value' => intval( $lesson_course_id ),
298
-                    ),
299
-                ),
300
-                'post__not_in' => $all_lessons,
301
-            );
302
-
303
-            $other_lessons = get_posts( $args );
304
-            if ( 0 < count( $other_lessons ) ) {
251
+			$modules = Sensei()->modules->get_course_modules( intval( $lesson_course_id ) );
252
+
253
+			foreach( (array) $modules as $module ) {
254
+
255
+				$args = array(
256
+					'post_type' => 'lesson',
257
+					'post_status' => 'publish',
258
+					'posts_per_page' => -1,
259
+					'meta_query' => array(
260
+						array(
261
+							'key' => '_lesson_course',
262
+							'value' => intval( $lesson_course_id ),
263
+							'compare' => '='
264
+						)
265
+					),
266
+					'tax_query' => array(
267
+						array(
268
+							'taxonomy' => Sensei()->modules->taxonomy,
269
+							'field' => 'id',
270
+							'terms' => intval( $module->term_id )
271
+						)
272
+					),
273
+					'meta_key' => '_order_module_' . $module->term_id,
274
+					'orderby' => 'meta_value_num date',
275
+					'order' => 'ASC',
276
+					'suppress_filters' => 0
277
+				);
278
+
279
+				$lessons = get_posts( $args );
280
+				if ( 0 < count( $lessons ) ) {
281
+					foreach ($lessons as $lesson_item){
282
+						$all_lessons[] = $lesson_item->ID;
283
+					} // End For Loop
284
+				} // End If Statement
285
+			}
286
+
287
+			$args = array(
288
+				'post_type' => 'lesson',
289
+				'posts_per_page' => -1,
290
+				'suppress_filters' => 0,
291
+				'meta_key' => '_order_' . $lesson_course_id,
292
+				'orderby' => 'meta_value_num date',
293
+				'order' => 'ASC',
294
+				'meta_query' => array(
295
+					array(
296
+						'key' => '_lesson_course',
297
+						'value' => intval( $lesson_course_id ),
298
+					),
299
+				),
300
+				'post__not_in' => $all_lessons,
301
+			);
302
+
303
+			$other_lessons = get_posts( $args );
304
+			if ( 0 < count( $other_lessons ) ) {
305 305
 				foreach ($other_lessons as $lesson_item){
306 306
 					$all_lessons[] = $lesson_item->ID;
307 307
 				} // End For Loop
308 308
 			} // End If Statement
309 309
 
310
-            if ( 0 < count( $all_lessons ) ) {
310
+			if ( 0 < count( $all_lessons ) ) {
311 311
 				$found_index = false;
312 312
 				foreach ( $all_lessons as $lesson ){
313 313
 					if ( $found_index && $return_values['next_lesson'] == 0 ) {
@@ -338,9 +338,9 @@  discard block
 block discarded – undo
338 338
    */
339 339
   function sensei_get_excerpt( $post_id = '' ) {
340 340
 
341
-      global $post;
342
-      _deprecated_function('sensei_get_excerpt', 'use the wordpress excerpt functionality.');
343
-      return get_the_excerpt();
341
+	  global $post;
342
+	  _deprecated_function('sensei_get_excerpt', 'use the wordpress excerpt functionality.');
343
+	  return get_the_excerpt();
344 344
 
345 345
   }
346 346
 
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 */
366 366
 function sensei_has_user_completed_prerequisite_lesson( $current_lesson_id, $user_id ) {
367 367
 
368
-    return WooThemes_Sensei_Lesson::is_pre_requisite_complete( $current_lesson_id, $user_id );
368
+	return WooThemes_Sensei_Lesson::is_pre_requisite_complete( $current_lesson_id, $user_id );
369 369
 
370 370
 } // End sensei_has_user_completed_prerequisite_lesson()
371 371
 
@@ -480,27 +480,27 @@  discard block
 block discarded – undo
480 480
 
481 481
 	}else{
482 482
 
483
-        // if the loop has not been initiated check the first module has lessons
484
-        if( -1 == $sensei_modules_loop[ 'current' ]  ){
483
+		// if the loop has not been initiated check the first module has lessons
484
+		if( -1 == $sensei_modules_loop[ 'current' ]  ){
485 485
 
486
-            $index = 0;
486
+			$index = 0;
487 487
 
488
-            if( isset( $sensei_modules_loop['modules'][ $index ] ) ) {
489
-                // setup the query for the module lessons
490
-                $course_id = $sensei_modules_loop['course_id'];
488
+			if( isset( $sensei_modules_loop['modules'][ $index ] ) ) {
489
+				// setup the query for the module lessons
490
+				$course_id = $sensei_modules_loop['course_id'];
491 491
 
492
-                $module_term_id = $sensei_modules_loop['modules'][ $index ] ->term_id;
493
-                $modules_query = Sensei()->modules->get_lessons_query( $course_id , $module_term_id );
492
+				$module_term_id = $sensei_modules_loop['modules'][ $index ] ->term_id;
493
+				$modules_query = Sensei()->modules->get_lessons_query( $course_id , $module_term_id );
494 494
 
495
-                // setup the global wp-query only if the lessons
496
-                if( $modules_query->have_posts() ){
495
+				// setup the global wp-query only if the lessons
496
+				if( $modules_query->have_posts() ){
497 497
 
498
-                    return true;
498
+					return true;
499 499
 
500
-                }
501
-            }
502
-        }
503
-        // default to false if the first module doesn't have posts
500
+				}
501
+			}
502
+		}
503
+		// default to false if the first module doesn't have posts
504 504
 		return false;
505 505
 
506 506
 	}
@@ -612,21 +612,21 @@  discard block
 block discarded – undo
612 612
  */
613 613
 function sensei_quiz_has_questions(){
614 614
 
615
-    global $sensei_question_loop;
615
+	global $sensei_question_loop;
616 616
 
617
-    if( !isset( $sensei_question_loop['total'] ) ){
618
-        return false;
619
-    }
617
+	if( !isset( $sensei_question_loop['total'] ) ){
618
+		return false;
619
+	}
620 620
 
621
-    if( $sensei_question_loop['current'] + 1 < $sensei_question_loop['total']  ){
621
+	if( $sensei_question_loop['current'] + 1 < $sensei_question_loop['total']  ){
622 622
 
623
-        return true;
623
+		return true;
624 624
 
625
-    }else{
625
+	}else{
626 626
 
627
-        return false;
627
+		return false;
628 628
 
629
-    }
629
+	}
630 630
 
631 631
 }// end sensei_quiz_has_questions
632 632
 
@@ -637,15 +637,14 @@  discard block
 block discarded – undo
637 637
  * execution.
638 638
  *
639 639
  * @since 1.9.0
640
-
641 640
  */
642 641
 function sensei_setup_the_question(){
643 642
 
644
-    global $sensei_question_loop;
643
+	global $sensei_question_loop;
645 644
 
646
-    $sensei_question_loop['current']++;
647
-    $index = $sensei_question_loop['current'];
648
-    $sensei_question_loop['current_question'] =  $sensei_question_loop['questions'][ $index ] ;
645
+	$sensei_question_loop['current']++;
646
+	$index = $sensei_question_loop['current'];
647
+	$sensei_question_loop['current_question'] =  $sensei_question_loop['questions'][ $index ] ;
649 648
 
650 649
 
651 650
 }// end sensei_setup_the_question
@@ -658,12 +657,12 @@  discard block
 block discarded – undo
658 657
  */
659 658
 function sensei_the_question_content(){
660 659
 
661
-    global $sensei_question_loop;
660
+	global $sensei_question_loop;
662 661
 
663
-    $question_type = Sensei()->question->get_question_type( $sensei_question_loop['current_question']->ID );
662
+	$question_type = Sensei()->question->get_question_type( $sensei_question_loop['current_question']->ID );
664 663
 
665
-    // load the template that displays the question information.
666
-    WooThemes_Sensei_Question::load_question_template( $question_type );
664
+	// load the template that displays the question information.
665
+	WooThemes_Sensei_Question::load_question_template( $question_type );
667 666
 
668 667
 }// end sensei_the_question_content
669 668
 
@@ -674,26 +673,26 @@  discard block
 block discarded – undo
674 673
  */
675 674
 function sensei_the_question_class(){
676 675
 
677
-    global $sensei_question_loop;
676
+	global $sensei_question_loop;
678 677
 
679
-    $question_type = Sensei()->question->get_question_type( $sensei_question_loop['current_question']->ID );
678
+	$question_type = Sensei()->question->get_question_type( $sensei_question_loop['current_question']->ID );
680 679
 
681
-    /**
682
-     * filter the sensei question class within
683
-     * the quiz question loop.
684
-     *
685
-     * @since 1.9.0
686
-     */
687
-     $classes = apply_filters( 'sensei_question_classes', array( $question_type ) );
680
+	/**
681
+	 * filter the sensei question class within
682
+	 * the quiz question loop.
683
+	 *
684
+	 * @since 1.9.0
685
+	 */
686
+	 $classes = apply_filters( 'sensei_question_classes', array( $question_type ) );
688 687
 
689
-    $html_classes = '';
690
-    foreach( $classes as $class ){
688
+	$html_classes = '';
689
+	foreach( $classes as $class ){
691 690
 
692
-        $html_classes .= $class . ' ';
691
+		$html_classes .= $class . ' ';
693 692
 
694
-    }// end foreach
693
+	}// end foreach
695 694
 
696
-    esc_attr_e( trim( $html_classes ) );
695
+	esc_attr_e( trim( $html_classes ) );
697 696
 
698 697
 }
699 698
 
@@ -704,12 +703,12 @@  discard block
 block discarded – undo
704 703
  */
705 704
 function sensei_get_the_question_id( ){
706 705
 
707
-    global $sensei_question_loop;
708
-    if( isset( $sensei_question_loop['current_question']->ID ) ){
706
+	global $sensei_question_loop;
707
+	if( isset( $sensei_question_loop['current_question']->ID ) ){
709 708
 
710
-        return $sensei_question_loop['current_question']->ID;
709
+		return $sensei_question_loop['current_question']->ID;
711 710
 
712
-    }
711
+	}
713 712
 
714 713
 }// end sensei_the_question_id
715 714
 
@@ -736,63 +735,63 @@  discard block
 block discarded – undo
736 735
  */
737 736
 function sensei_can_user_view_lesson( $lesson_id = '', $user_id = ''  ){
738 737
 
739
-    if( empty( $lesson_id ) ){
738
+	if( empty( $lesson_id ) ){
740 739
 
741
-        $lesson_id = get_the_ID();
740
+		$lesson_id = get_the_ID();
742 741
 
743
-    }
742
+	}
744 743
 
745
-    if( empty( $user_id ) ){
744
+	if( empty( $user_id ) ){
746 745
 
747
-        $user_id = get_current_user_id();
746
+		$user_id = get_current_user_id();
748 747
 
749
-    }
748
+	}
750 749
 
751
-    // Check for prerequisite lesson completions
752
-    $pre_requisite_complete = WooThemes_Sensei_Lesson::is_prerequisite_complete( $lesson_id, $user_id );
753
-    $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true );
754
-    $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, $user_id );
750
+	// Check for prerequisite lesson completions
751
+	$pre_requisite_complete = WooThemes_Sensei_Lesson::is_prerequisite_complete( $lesson_id, $user_id );
752
+	$lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true );
753
+	$user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, $user_id );
755 754
 
756
-    $is_preview = false;
757
-    if( Sensei_Utils::is_preview_lesson( $lesson_id ) ) {
755
+	$is_preview = false;
756
+	if( Sensei_Utils::is_preview_lesson( $lesson_id ) ) {
758 757
 
759
-        $is_preview = true;
760
-        $pre_requisite_complete = true;
758
+		$is_preview = true;
759
+		$pre_requisite_complete = true;
761 760
 
762
-    };
761
+	};
763 762
 
764 763
 
765
-    $user_can_access_lesson =  false;
764
+	$user_can_access_lesson =  false;
766 765
 
767
-    if( is_user_logged_in() && $user_taking_course ){
766
+	if( is_user_logged_in() && $user_taking_course ){
768 767
 
769
-        $user_can_access_lesson =  true;
768
+		$user_can_access_lesson =  true;
770 769
 
771
-    }
770
+	}
772 771
 
773 772
 
774
-    $access_permission = false;
773
+	$access_permission = false;
775 774
 
776
-    if ( ! Sensei()->settings->get('access_permission')  || sensei_all_access() ) {
775
+	if ( ! Sensei()->settings->get('access_permission')  || sensei_all_access() ) {
777 776
 
778
-        $access_permission = true;
777
+		$access_permission = true;
779 778
 
780
-    }
779
+	}
781 780
 
782
-    $can_user_view_lesson = $access_permission || ( $user_can_access_lesson && $pre_requisite_complete ) || $is_preview;
781
+	$can_user_view_lesson = $access_permission || ( $user_can_access_lesson && $pre_requisite_complete ) || $is_preview;
783 782
 
784
-    /**
785
-     * Filter the can user view lesson function
786
-     *
787
-     * @since 1.9.0
788
-     *
789
-     * @hooked Sensei_WC::alter_can_user_view_lesson
790
-     *
791
-     * @param bool $can_user_view_lesson
792
-     * @param string $lesson_id
793
-     * @param string $user_id
794
-     */
795
-    return apply_filters( 'sensei_can_user_view_lesson', $can_user_view_lesson, $lesson_id, $user_id );
783
+	/**
784
+	 * Filter the can user view lesson function
785
+	 *
786
+	 * @since 1.9.0
787
+	 *
788
+	 * @hooked Sensei_WC::alter_can_user_view_lesson
789
+	 *
790
+	 * @param bool $can_user_view_lesson
791
+	 * @param string $lesson_id
792
+	 * @param string $user_id
793
+	 */
794
+	return apply_filters( 'sensei_can_user_view_lesson', $can_user_view_lesson, $lesson_id, $user_id );
796 795
 
797 796
 } // end sensei_can_current_user_view_lesson
798 797
 
@@ -804,52 +803,52 @@  discard block
 block discarded – undo
804 803
  */
805 804
 function sensei_the_single_lesson_meta(){
806 805
 
807
-    // if the lesson meta is included within theme load that instead of the function content
808
-    $template = Sensei_Templates::locate_template( 'single-lesson/lesson-meta.php' );
809
-    if( ! empty( $template ) ){
806
+	// if the lesson meta is included within theme load that instead of the function content
807
+	$template = Sensei_Templates::locate_template( 'single-lesson/lesson-meta.php' );
808
+	if( ! empty( $template ) ){
810 809
 
811
-        Sensei_Templates::get_template( 'single-lesson/lesson-meta.php' );
812
-        return;
810
+		Sensei_Templates::get_template( 'single-lesson/lesson-meta.php' );
811
+		return;
813 812
 
814
-    }
813
+	}
815 814
 
816
-    // Get the meta info
817
-    $lesson_course_id = absint( get_post_meta( get_the_ID(), '_lesson_course', true ) );
818
-    $is_preview = Sensei_Utils::is_preview_lesson( get_the_ID() );
815
+	// Get the meta info
816
+	$lesson_course_id = absint( get_post_meta( get_the_ID(), '_lesson_course', true ) );
817
+	$is_preview = Sensei_Utils::is_preview_lesson( get_the_ID() );
819 818
 
820
-    // Get User Meta
821
-    get_currentuserinfo();
819
+	// Get User Meta
820
+	get_currentuserinfo();
822 821
 
823
-    // Complete Lesson Logic
824
-    do_action( 'sensei_complete_lesson' );
825
-    // Check that the course has been started
826
-    if ( Sensei()->access_settings()
827
-        || Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id())
828
-        || $is_preview ) {
829
-        ?>
822
+	// Complete Lesson Logic
823
+	do_action( 'sensei_complete_lesson' );
824
+	// Check that the course has been started
825
+	if ( Sensei()->access_settings()
826
+		|| Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id())
827
+		|| $is_preview ) {
828
+		?>
830 829
         <section class="lesson-meta">
831 830
             <?php
832
-            if( apply_filters( 'sensei_video_position', 'top', get_the_ID() ) == 'bottom' ) {
831
+			if( apply_filters( 'sensei_video_position', 'top', get_the_ID() ) == 'bottom' ) {
833 832
 
834
-                do_action( 'sensei_lesson_video', get_the_ID() );
833
+				do_action( 'sensei_lesson_video', get_the_ID() );
835 834
 
836
-            }
837
-            ?>
835
+			}
836
+			?>
838 837
             <?php do_action( 'sensei_frontend_messages' ); ?>
839 838
 
840 839
             <?php if ( ! $is_preview
841
-                || Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id()) ) {
840
+				|| Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id()) ) {
842 841
 
843
-                sensei_do_deprecated_action( 'sensei_lesson_quiz_meta','1.9.0', 'sensei_single_lesson_content_inside_before' ,array( get_the_ID(), get_current_user_id() )  );
842
+				sensei_do_deprecated_action( 'sensei_lesson_quiz_meta','1.9.0', 'sensei_single_lesson_content_inside_before' ,array( get_the_ID(), get_current_user_id() )  );
844 843
 
845
-            } ?>
844
+			} ?>
846 845
         </section>
847 846
 
848 847
         <?php do_action( 'sensei_lesson_back_link', $lesson_course_id ); ?>
849 848
 
850 849
     <?php }
851 850
 
852
-    do_action( 'sensei_lesson_meta_extra', get_the_ID() );
851
+	do_action( 'sensei_lesson_meta_extra', get_the_ID() );
853 852
 
854 853
 } // end the_single_lesson_meta
855 854
 
@@ -865,16 +864,16 @@  discard block
 block discarded – undo
865 864
  */
866 865
 function get_sensei_header(){
867 866
 
868
-    if ( ! defined( 'ABSPATH' ) ) exit;
867
+	if ( ! defined( 'ABSPATH' ) ) exit;
869 868
 
870
-    get_header();
869
+	get_header();
871 870
 
872
-    /**
873
-     * sensei_before_main_content hook
874
-     *
875
-     * @hooked sensei_output_content_wrapper - 10 (outputs opening divs for the content)
876
-     */
877
-    do_action( 'sensei_before_main_content' );
871
+	/**
872
+	 * sensei_before_main_content hook
873
+	 *
874
+	 * @hooked sensei_output_content_wrapper - 10 (outputs opening divs for the content)
875
+	 */
876
+	do_action( 'sensei_before_main_content' );
878 877
 
879 878
 }// end get_sensei_header
880 879
 
@@ -890,28 +889,28 @@  discard block
 block discarded – undo
890 889
  */
891 890
 function get_sensei_footer(){
892 891
 
893
-    /**
894
-     * sensei_pagination hook
895
-     *
896
-     * @hooked sensei_pagination - 10 (outputs pagination)
897
-     */
898
-    do_action( 'sensei_pagination' );
899
-
900
-    /**
901
-     * sensei_after_main_content hook
902
-     *
903
-     * @hooked sensei_output_content_wrapper_end - 10 (outputs closing divs for the content)
904
-     */
905
-    do_action( 'sensei_after_main_content' );
906
-
907
-    /**
908
-     * sensei_sidebar hook
909
-     *
910
-     * @hooked sensei_get_sidebar - 10
911
-     */
912
-    do_action( 'sensei_sidebar' );
913
-
914
-    get_footer();
892
+	/**
893
+	 * sensei_pagination hook
894
+	 *
895
+	 * @hooked sensei_pagination - 10 (outputs pagination)
896
+	 */
897
+	do_action( 'sensei_pagination' );
898
+
899
+	/**
900
+	 * sensei_after_main_content hook
901
+	 *
902
+	 * @hooked sensei_output_content_wrapper_end - 10 (outputs closing divs for the content)
903
+	 */
904
+	do_action( 'sensei_after_main_content' );
905
+
906
+	/**
907
+	 * sensei_sidebar hook
908
+	 *
909
+	 * @hooked sensei_get_sidebar - 10
910
+	 */
911
+	do_action( 'sensei_sidebar' );
912
+
913
+	get_footer();
915 914
 
916 915
 }// end get_sensei_header
917 916
 
@@ -923,14 +922,14 @@  discard block
 block discarded – undo
923 922
  */
924 923
 function the_no_permissions_title(){
925 924
 
926
-    /**
927
-     * Filter the no permissions title just before it is echo'd on the
928
-     * no-permissions.php file.
929
-     *
930
-     * @since 1.9.0
931
-     * @param $no_permissions_title
932
-     */
933
-    echo apply_filters( 'sensei_the_no_permissions_title', Sensei()->permissions_message['title'] );
925
+	/**
926
+	 * Filter the no permissions title just before it is echo'd on the
927
+	 * no-permissions.php file.
928
+	 *
929
+	 * @since 1.9.0
930
+	 * @param $no_permissions_title
931
+	 */
932
+	echo apply_filters( 'sensei_the_no_permissions_title', Sensei()->permissions_message['title'] );
934 933
 
935 934
 }
936 935
 
@@ -941,14 +940,14 @@  discard block
 block discarded – undo
941 940
  */
942 941
 function the_no_permissions_message( $post_id ){
943 942
 
944
-    /**
945
-     * Filter the no permissions message just before it is echo'd on the
946
-     * no-permissions.php file.
947
-     *
948
-     * @since 1.9.0
949
-     * @param $no_permissions_message
950
-     */
951
-    echo apply_filters( 'sensei_the_no_permissions_message', Sensei()->permissions_message['message'] , $post_id );
943
+	/**
944
+	 * Filter the no permissions message just before it is echo'd on the
945
+	 * no-permissions.php file.
946
+	 *
947
+	 * @since 1.9.0
948
+	 * @param $no_permissions_message
949
+	 */
950
+	echo apply_filters( 'sensei_the_no_permissions_message', Sensei()->permissions_message['message'] , $post_id );
952 951
 
953 952
 }
954 953
 
@@ -959,8 +958,8 @@  discard block
 block discarded – undo
959 958
  */
960 959
 function sensei_the_excerpt( $post_id ){
961 960
 
962
-    global $post;
963
-    the_excerpt( $post );
961
+	global $post;
962
+	the_excerpt( $post );
964 963
 
965 964
 }
966 965
 
@@ -974,9 +973,9 @@  discard block
 block discarded – undo
974 973
  */
975 974
  function sensei_get_current_page_url(){
976 975
 
977
-     global $wp;
978
-     $current_page_url =  home_url( $wp->request );
979
-     return $current_page_url;
976
+	 global $wp;
977
+	 $current_page_url =  home_url( $wp->request );
978
+	 return $current_page_url;
980 979
 
981 980
  }
982 981
 
@@ -988,7 +987,7 @@  discard block
 block discarded – undo
988 987
  */
989 988
 function sensei_the_my_courses_content(){
990 989
 
991
-    echo Sensei()->course->load_user_courses_content( wp_get_current_user() );
990
+	echo Sensei()->course->load_user_courses_content( wp_get_current_user() );
992 991
 
993 992
 } // sensei_the_my_courses_content
994 993
 
@@ -1003,7 +1002,7 @@  discard block
 block discarded – undo
1003 1002
  */
1004 1003
 function sensei_load_template( $template_name ){
1005 1004
 
1006
-    Sensei_Templates::get_template( $template_name );
1005
+	Sensei_Templates::get_template( $template_name );
1007 1006
 
1008 1007
 }
1009 1008
 
@@ -1017,7 +1016,7 @@  discard block
 block discarded – undo
1017 1016
  */
1018 1017
 function sensei_load_template_part( $slug, $name ){
1019 1018
 
1020
-    Sensei_Templates::get_part( $slug, $name );
1019
+	Sensei_Templates::get_part( $slug, $name );
1021 1020
 
1022 1021
 }
1023 1022
 
@@ -1036,17 +1035,17 @@  discard block
 block discarded – undo
1036 1035
  */
1037 1036
 function sensei_the_lesson_excerpt( $lesson_id = '' ) {
1038 1037
 
1039
-    if( empty( $lesson_id )){
1038
+	if( empty( $lesson_id )){
1040 1039
 
1041
-        $lesson_id = get_the_ID();
1040
+		$lesson_id = get_the_ID();
1042 1041
 
1043
-    }
1042
+	}
1044 1043
 
1045
-    if( 'lesson' != get_post_type( $lesson_id ) ){
1046
-        return;
1047
-    }
1044
+	if( 'lesson' != get_post_type( $lesson_id ) ){
1045
+		return;
1046
+	}
1048 1047
 
1049
-    echo Sensei_Lesson::lesson_excerpt( get_post( $lesson_id ), false );
1048
+	echo Sensei_Lesson::lesson_excerpt( get_post( $lesson_id ), false );
1050 1049
 
1051 1050
 }// End lesson_excerpt()
1052 1051
 
@@ -1056,16 +1055,16 @@  discard block
 block discarded – undo
1056 1055
  * @since 1.9.0
1057 1056
  */
1058 1057
 function sensei_the_course_results_lessons(){
1059
-    // load backwards compatible template name if it exists in the users theme
1060
-    $located_template= locate_template( Sensei()->template_url . 'course-results/course-lessons.php' );
1061
-    if( $located_template ){
1058
+	// load backwards compatible template name if it exists in the users theme
1059
+	$located_template= locate_template( Sensei()->template_url . 'course-results/course-lessons.php' );
1060
+	if( $located_template ){
1062 1061
 
1063
-        Sensei_Templates::get_template( 'course-results/course-lessons.php' );
1064
-        return;
1062
+		Sensei_Templates::get_template( 'course-results/course-lessons.php' );
1063
+		return;
1065 1064
 
1066
-    }
1065
+	}
1067 1066
 
1068
-    Sensei_Templates::get_template( 'course-results/lessons.php' );
1067
+	Sensei_Templates::get_template( 'course-results/lessons.php' );
1069 1068
 }
1070 1069
 
1071 1070
 /**
@@ -1077,7 +1076,7 @@  discard block
 block discarded – undo
1077 1076
  */
1078 1077
 function sensei_courses_per_row(){
1079 1078
 
1080
-    echo Sensei_Course::get_loop_number_of_columns();
1079
+	echo Sensei_Course::get_loop_number_of_columns();
1081 1080
 
1082 1081
 }
1083 1082
 
@@ -1091,6 +1090,6 @@  discard block
 block discarded – undo
1091 1090
  */
1092 1091
 function sensei_get_template( $template_name, $args, $path ){
1093 1092
 
1094
-    Sensei_Templates::get_template( $template_name, $args, $path );
1093
+	Sensei_Templates::get_template( $template_name, $args, $path );
1095 1094
 
1096 1095
 }
Please login to merge, or discard this patch.
includes/class-sensei-emails.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 		add_action( 'sensei_course_status_updated', array( $this, 'learner_completed_course' ), 10, 4 );
46 46
 		add_action( 'sensei_course_status_updated', array( $this, 'teacher_completed_course' ), 10, 4 );
47 47
 		add_action( 'sensei_user_course_start', array( $this, 'teacher_started_course' ), 10, 2 );
48
-        add_action( 'sensei_user_lesson_end', array( $this, 'teacher_completed_lesson' ), 10, 2 );
48
+		add_action( 'sensei_user_lesson_end', array( $this, 'teacher_completed_lesson' ), 10, 2 );
49 49
 		add_action( 'sensei_user_quiz_submitted', array( $this, 'teacher_quiz_submitted' ), 10, 5 );
50 50
 		add_action( 'sensei_new_private_message', array( $this, 'teacher_new_message' ), 10, 1 );
51 51
 		add_action( 'sensei_private_message_reply', array( $this, 'new_message_reply' ), 10, 2 );
@@ -62,9 +62,9 @@  discard block
 block discarded – undo
62 62
 		$this->emails['learner-graded-quiz'] = include( 'emails/class-woothemes-sensei-email-learner-graded-quiz.php' );
63 63
 		$this->emails['learner-completed-course'] = include( 'emails/class-woothemes-sensei-email-learner-completed-course.php' );
64 64
 		$this->emails['teacher-completed-course'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-course.php' );
65
-        $this->emails['teacher-started-course'] = include( 'emails/class-woothemes-sensei-email-teacher-started-course.php' );
66
-        $this->emails['teacher-completed-lesson'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-lesson.php' );
67
-        $this->emails['teacher-quiz-submitted'] = include( 'emails/class-woothemes-sensei-email-teacher-quiz-submitted.php' );
65
+		$this->emails['teacher-started-course'] = include( 'emails/class-woothemes-sensei-email-teacher-started-course.php' );
66
+		$this->emails['teacher-completed-lesson'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-lesson.php' );
67
+		$this->emails['teacher-quiz-submitted'] = include( 'emails/class-woothemes-sensei-email-teacher-quiz-submitted.php' );
68 68
 		$this->emails['teacher-new-message'] = include( 'emails/class-woothemes-sensei-email-teacher-new-message.php' );
69 69
 		$this->emails['new-message-reply'] = include( 'emails/class-woothemes-sensei-email-new-message-reply.php' );
70 70
 		$this->emails = apply_filters( 'sensei_email_classes', $this->emails );
@@ -171,20 +171,20 @@  discard block
 block discarded – undo
171 171
 		add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) );
172 172
 		add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) );
173 173
 
174
-        // Send
175
-        $send_email = true;
174
+		// Send
175
+		$send_email = true;
176 176
 
177
-        /**
178
-         * Filter Sensei's ability to send out emails.
179
-         *
180
-         * @since 1.8.0
181
-         * @param bool $send_email default true
182
-         */
183
-        if( apply_filters('sensei_send_emails', $send_email,$to, $subject, $message )  ){
177
+		/**
178
+		 * Filter Sensei's ability to send out emails.
179
+		 *
180
+		 * @since 1.8.0
181
+		 * @param bool $send_email default true
182
+		 */
183
+		if( apply_filters('sensei_send_emails', $send_email,$to, $subject, $message )  ){
184 184
 
185
-            wp_mail( $to, $subject, $message, $headers, $attachments );
185
+			wp_mail( $to, $subject, $message, $headers, $attachments );
186 186
 
187
-        }
187
+		}
188 188
 
189 189
 		// Unhook filters
190 190
 		remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ) );
@@ -326,44 +326,44 @@  discard block
 block discarded – undo
326 326
 		}
327 327
 	}
328 328
 
329
-    /**
330
-     * teacher_completed_lesson()
331
-     *
332
-     * Send email to teacher on student completing lesson
333
-     *
334
-     * @access public
335
-     * @return void
336
-     * @since 1.9.0
337
-     */
338
-    function teacher_completed_lesson( $learner_id = 0, $lesson_id = 0 ) {
339
-
340
-
341
-        $send = false;
342
-
343
-        if( isset( Sensei()->settings->settings[ 'email_teachers' ] ) ) {
344
-            if( in_array( 'teacher-completed-lesson', (array) Sensei()->settings->settings[ 'email_teachers' ]) ) {
345
-                $send = true;
346
-            }
347
-        } else {
348
-            $send = true;
349
-        }
350
-
351
-        if( $send ) {
352
-            $email = $this->emails['teacher-completed-lesson'];
353
-            $email->trigger( $learner_id, $lesson_id );
354
-        }
355
-    }
329
+	/**
330
+	 * teacher_completed_lesson()
331
+	 *
332
+	 * Send email to teacher on student completing lesson
333
+	 *
334
+	 * @access public
335
+	 * @return void
336
+	 * @since 1.9.0
337
+	 */
338
+	function teacher_completed_lesson( $learner_id = 0, $lesson_id = 0 ) {
339
+
340
+
341
+		$send = false;
342
+
343
+		if( isset( Sensei()->settings->settings[ 'email_teachers' ] ) ) {
344
+			if( in_array( 'teacher-completed-lesson', (array) Sensei()->settings->settings[ 'email_teachers' ]) ) {
345
+				$send = true;
346
+			}
347
+		} else {
348
+			$send = true;
349
+		}
350
+
351
+		if( $send ) {
352
+			$email = $this->emails['teacher-completed-lesson'];
353
+			$email->trigger( $learner_id, $lesson_id );
354
+		}
355
+	}
356 356
 
357 357
 	/**
358 358
 	 * Send email to teacher on quiz submission
359 359
 	 *
360 360
 	 *
361
-     * @param int $learner_id
362
-     * @param int $quiz_id
363
-     * @param int $grade
364
-     * @param int $passmark
365
-     * @param string $quiz_grade_type
366
-     */
361
+	 * @param int $learner_id
362
+	 * @param int $quiz_id
363
+	 * @param int $grade
364
+	 * @param int $passmark
365
+	 * @param string $quiz_grade_type
366
+	 */
367 367
 	function teacher_quiz_submitted( $learner_id = 0, $quiz_id = 0, $grade = 0, $passmark = 0, $quiz_grade_type = 'manual' ) {
368 368
 
369 369
 		$send = false;
Please login to merge, or discard this patch.
includes/emails/class-woothemes-sensei-email-new-message-reply.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -16,38 +16,38 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class WooThemes_Sensei_Email_New_Message_Reply {
18 18
 
19
-    /**
20
-     * @var string
21
-     */
22
-    var $template;
23
-
24
-    /**
25
-     * @var string
26
-     */
19
+	/**
20
+	 * @var string
21
+	 */
22
+	var $template;
23
+
24
+	/**
25
+	 * @var string
26
+	 */
27 27
 	var $subject;
28 28
 
29
-    /**
30
-     * @var string
31
-     */
32
-    var $heading;
29
+	/**
30
+	 * @var string
31
+	 */
32
+	var $heading;
33 33
 
34
-    /**
35
-     * @var string
36
-     */
34
+	/**
35
+	 * @var string
36
+	 */
37 37
 	var $recipient;
38 38
 
39 39
 	var $original_sender;
40 40
 	var $original_receiver;
41 41
 	var $commenter;
42 42
 
43
-    /**
44
-     * @var WP_Post
45
-     */
43
+	/**
44
+	 * @var WP_Post
45
+	 */
46 46
 	var $message;
47 47
 
48
-    /**
49
-     * @var WP_Comment
50
-     */
48
+	/**
49
+	 * @var WP_Comment
50
+	 */
51 51
 	var $comment;
52 52
 
53 53
 	/**
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
 	/**
65 65
 	 * trigger function.
66 66
 	 *
67
-     * @param WP_Comment $comment
68
-     * @param string $message
69
-     *
67
+	 * @param WP_Comment $comment
68
+	 * @param string $message
69
+	 *
70 70
 	 * @return void
71 71
 	 */
72 72
 	function trigger ( $comment, $message ) {
@@ -90,16 +90,16 @@  discard block
 block discarded – undo
90 90
 
91 91
 		$comment_link = get_comment_link( $comment );
92 92
 
93
-        // setup the post type parameter
94
-        $content_type = get_post_type( $content_id );
95
-        if( !$content_type ){
96
-            $content_type ='';
97
-        }
93
+		// setup the post type parameter
94
+		$content_type = get_post_type( $content_id );
95
+		if( !$content_type ){
96
+			$content_type ='';
97
+		}
98 98
 
99
-        // Construct data array
100
-        $sensei_email_data = apply_filters( 'sensei_email_data', array(
101
-            'template'			=> $this->template,
102
-            $content_type.'_id' => $content_id,
99
+		// Construct data array
100
+		$sensei_email_data = apply_filters( 'sensei_email_data', array(
101
+			'template'			=> $this->template,
102
+			$content_type.'_id' => $content_id,
103 103
 			'heading'			=> $this->heading,
104 104
 			'commenter_name'	=> $this->commenter->display_name,
105 105
 			'message'			=> $this->comment->comment_content,
Please login to merge, or discard this patch.
includes/emails/class-woothemes-sensei-email-teacher-new-message.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	 * trigger function.
38 38
 	 *
39 39
 	 * @access public
40
-     * @param integer $message_id
40
+	 * @param integer $message_id
41 41
 	 * @return void
42 42
 	 */
43 43
 	function trigger( $message_id = 0 ) {
@@ -55,16 +55,16 @@  discard block
 block discarded – undo
55 55
 		$content_id = get_post_meta( $message_id, '_post', true );
56 56
 		$content_title = get_the_title( $content_id );
57 57
 
58
-        // setup the post type parameter
59
-        $content_type = get_post_type( $content_id );
60
-        if( !$content_type ){
61
-            $content_type ='';
62
-        }
58
+		// setup the post type parameter
59
+		$content_type = get_post_type( $content_id );
60
+		if( !$content_type ){
61
+			$content_type ='';
62
+		}
63 63
 
64 64
 		// Construct data array
65 65
 		$sensei_email_data = apply_filters( 'sensei_email_data', array(
66 66
 			'template'			=> $this->template,
67
-            $content_type.'_id' => $content_id,
67
+			$content_type.'_id' => $content_id,
68 68
 			'heading'			=> $this->heading,
69 69
 			'teacher_id'		=> $this->teacher->ID,
70 70
 			'learner_id'		=> $this->learner->ID,
Please login to merge, or discard this patch.
includes/emails/class-woothemes-sensei-email-learner-graded-quiz.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -36,11 +36,11 @@
 block discarded – undo
36 36
 	/**
37 37
 	 * trigger function.
38 38
 	 *
39
-     * @param int $user_id
40
-     * @param int $quiz_id
41
-     * @param int $grade
42
-     * @param int $passmark
43
-     *
39
+	 * @param int $user_id
40
+	 * @param int $quiz_id
41
+	 * @param int $grade
42
+	 * @param int $passmark
43
+	 *
44 44
 	 * @return void
45 45
 	 */
46 46
 	function trigger ( $user_id = 0, $quiz_id = 0, $grade = 0, $passmark = 0 ) {
Please login to merge, or discard this patch.
includes/emails/class-woothemes-sensei-email-learner-completed-course.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -38,10 +38,10 @@
 block discarded – undo
38 38
 	 * trigger function.
39 39
 	 *
40 40
 	 * @access public
41
-     *
42
-     * @param int $user_id
43
-     * @param int $course_id
44
-     *
41
+	 *
42
+	 * @param int $user_id
43
+	 * @param int $course_id
44
+	 *
45 45
 	 * @return void
46 46
 	 */
47 47
 	function trigger( $user_id = 0, $course_id = 0 ) {
Please login to merge, or discard this patch.