Completed
Push — master ( 7d92ba...201c1b )
by Dwain
05:05
created
includes/class-sensei-modules.php 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -1942,6 +1942,7 @@
 block discarded – undo
1942 1942
      * Hooked into 'get_terms'
1943 1943
      *
1944 1944
      * @since 1.8.0
1945
+     * @param string[] $taxonomies
1945 1946
      */
1946 1947
     public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1947 1948
     {
Please login to merge, or discard this patch.
Indentation   +1881 added lines, -1881 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,1399 +335,1399 @@  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('WooThemes_Sensei_Utils', 'is_preview_lesson') && WooThemes_Sensei_Utils::is_preview_lesson($lesson_id)) {
461
-            $is_user_taking_course = WooThemes_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('WooThemes_Sensei_Utils', 'is_preview_lesson') && WooThemes_Sensei_Utils::is_preview_lesson($lesson_id)) {
461
+			$is_user_taking_course = WooThemes_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 = WooThemes_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 = WooThemes_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
-
1264
-
1265
-        wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1266
-        wp_enqueue_style($this->taxonomy . '-frontend');
1267
-    }
1268
-
1269
-    /**
1270
-     * Load admin Javascript
1271
-     *
1272
-     * @since 1.8.0
1273
-     *
1274
-     * @return void
1275
-     */
1276
-    public function admin_enqueue_scripts( $hook ) {
1277
-
1278
-        /**
1279
-         * Filter the page hooks where modules admin script can be loaded on.
1280
-         *
1281
-         * @param array $white_listed_pages
1282
-         */
1283
-        $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1284
-            'edit-tags.php',
1285
-            'course_page_module-order',
1286
-            'post-new.php',
1287
-            'post.php'
1288
-        ) );
1289
-
1290
-        if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1291
-            return;
1292
-        }
1293
-
1294
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1295
-
1296
-        wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1297
-        wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1298
-        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 );
1299
-
1300
-        // localized module data
1301
-        $localize_modulesAdmin = array(
1302
-            'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1303
-            'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1304
-        );
1305
-
1306
-        wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1307
-    }
1308
-
1309
-    /**
1310
-     * Load admin CSS
1311
-     *
1312
-     * @since 1.8.0
1313
-     *
1314
-     * @return void
1315
-     */
1316
-    public function admin_enqueue_styles() {
1317
-
1318
-
1319
-        wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1320
-        wp_enqueue_style($this->taxonomy . '-sortable');
1321
-
1322
-    }
1323
-
1324
-    /**
1325
-     * Show the title modules on the single course template.
1326
-     *
1327
-     * Function is hooked into sensei_single_course_modules_before.
1328
-     *
1329
-     * @since 1.8.0
1330
-     * @return void
1331
-     */
1332
-    public function course_modules_title( ) {
1333
-
1334
-       if( sensei_module_has_lessons() ){
1335
-
1336
-            echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1337
-
1338
-        }
1339
-
1340
-    }
1341
-
1342
-    /**
1343
-     * Display the single course modules content this will only show
1344
-     * if the course has modules.
1345
-     *
1346
-     * @since 1.8.0
1347
-     * @return void
1348
-     */
1349
-    public function load_course_module_content_template(){
1350
-
1351
-        // load backwards compatible template name if it exists in the users theme
1352
-        $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1353
-        if( $located_template ){
1354
-
1355
-            Sensei_Templates::get_template( 'single-course/course-modules.php' );
1356
-            return;
1357
-
1358
-        }
1359
-
1360
-        Sensei_Templates::get_template( 'single-course/modules.php' );
1361
-
1362
-    } // end course_module_content
1363
-
1364
-    /**
1365
-     * Returns all lessons for the given module ID
1366
-     *
1367
-     * @since 1.8.0
1368
-     *
1369
-     * @param $course_id
1370
-     * @param $term_id
1371
-     * @return array $lessons
1372
-     */
1373
-    public function get_lessons( $course_id , $term_id ){
1374
-
1375
-        $lesson_query = $this->get_lessons_query( $course_id, $term_id );
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
+
1264
+
1265
+		wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1266
+		wp_enqueue_style($this->taxonomy . '-frontend');
1267
+	}
1268
+
1269
+	/**
1270
+	 * Load admin Javascript
1271
+	 *
1272
+	 * @since 1.8.0
1273
+	 *
1274
+	 * @return void
1275
+	 */
1276
+	public function admin_enqueue_scripts( $hook ) {
1277
+
1278
+		/**
1279
+		 * Filter the page hooks where modules admin script can be loaded on.
1280
+		 *
1281
+		 * @param array $white_listed_pages
1282
+		 */
1283
+		$script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1284
+			'edit-tags.php',
1285
+			'course_page_module-order',
1286
+			'post-new.php',
1287
+			'post.php'
1288
+		) );
1289
+
1290
+		if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1291
+			return;
1292
+		}
1293
+
1294
+		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1295
+
1296
+		wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1297
+		wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1298
+		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 );
1299
+
1300
+		// localized module data
1301
+		$localize_modulesAdmin = array(
1302
+			'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1303
+			'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1304
+		);
1305
+
1306
+		wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1307
+	}
1308
+
1309
+	/**
1310
+	 * Load admin CSS
1311
+	 *
1312
+	 * @since 1.8.0
1313
+	 *
1314
+	 * @return void
1315
+	 */
1316
+	public function admin_enqueue_styles() {
1317
+
1318
+
1319
+		wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1320
+		wp_enqueue_style($this->taxonomy . '-sortable');
1321
+
1322
+	}
1323
+
1324
+	/**
1325
+	 * Show the title modules on the single course template.
1326
+	 *
1327
+	 * Function is hooked into sensei_single_course_modules_before.
1328
+	 *
1329
+	 * @since 1.8.0
1330
+	 * @return void
1331
+	 */
1332
+	public function course_modules_title( ) {
1333
+
1334
+	   if( sensei_module_has_lessons() ){
1335
+
1336
+			echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1337
+
1338
+		}
1339
+
1340
+	}
1341
+
1342
+	/**
1343
+	 * Display the single course modules content this will only show
1344
+	 * if the course has modules.
1345
+	 *
1346
+	 * @since 1.8.0
1347
+	 * @return void
1348
+	 */
1349
+	public function load_course_module_content_template(){
1350
+
1351
+		// load backwards compatible template name if it exists in the users theme
1352
+		$located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1353
+		if( $located_template ){
1354
+
1355
+			Sensei_Templates::get_template( 'single-course/course-modules.php' );
1356
+			return;
1357
+
1358
+		}
1359
+
1360
+		Sensei_Templates::get_template( 'single-course/modules.php' );
1361
+
1362
+	} // end course_module_content
1363
+
1364
+	/**
1365
+	 * Returns all lessons for the given module ID
1366
+	 *
1367
+	 * @since 1.8.0
1368
+	 *
1369
+	 * @param $course_id
1370
+	 * @param $term_id
1371
+	 * @return array $lessons
1372
+	 */
1373
+	public function get_lessons( $course_id , $term_id ){
1374
+
1375
+		$lesson_query = $this->get_lessons_query( $course_id, $term_id );
1376 1376
 
1377
-        if( isset( $lesson_query->posts ) ){
1377
+		if( isset( $lesson_query->posts ) ){
1378 1378
 
1379
-            return $lesson_query->posts;
1379
+			return $lesson_query->posts;
1380 1380
 
1381
-        }else{
1381
+		}else{
1382 1382
 
1383
-            return array();
1383
+			return array();
1384 1384
 
1385
-        }
1385
+		}
1386 1386
 
1387
-    } // end get lessons
1387
+	} // end get lessons
1388 1388
 
1389
-    /**
1390
-     * Returns all lessons for the given module ID
1391
-     *
1392
-     * @since 1.8.0
1393
-     *
1394
-     * @param $course_id
1395
-     * @param $term_id
1396
-     * @return WP_Query $lessons_query
1397
-     */
1398
-    public function get_lessons_query( $course_id , $term_id ){
1399
-
1400
-        if( empty( $term_id ) || empty( $course_id ) ){
1401
-
1402
-            return array();
1403
-
1404
-        }
1405
-
1406
-        $args = array(
1407
-            'post_type' => 'lesson',
1408
-            'post_status' => 'publish',
1409
-            'posts_per_page' => -1,
1410
-            'meta_query' => array(
1411
-                array(
1412
-                    'key' => '_lesson_course',
1413
-                    'value' => intval($course_id),
1414
-                    'compare' => '='
1415
-                )
1416
-            ),
1417
-            'tax_query' => array(
1418
-                array(
1419
-                    'taxonomy' => 'module',
1420
-                    'field' => 'id',
1421
-                    'terms' => intval( $term_id )
1422
-                )
1423
-            ),
1424
-            'orderby' => 'menu_order',
1425
-            'order' => 'ASC',
1426
-            'suppress_filters' => 0
1427
-        );
1428
-
1429
-        if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1430
-            $args['meta_key'] = '_order_module_' . intval( $term_id );
1431
-            $args['orderby'] = 'meta_value_num date';
1432
-        }
1433
-
1434
-        $lessons_query = new WP_Query( $args );
1435
-
1436
-        return $lessons_query;
1437
-
1438
-    } // end get lessons
1439
-
1440
-    /**
1441
-     * Find the lesson in the given course that doesn't belong
1442
-     * to any of the courses modules
1443
-     *
1444
-     *
1445
-     * @param $course_id
1446
-     *
1447
-     * @return array $non_module_lessons
1448
-     */
1449
-    public function get_none_module_lessons( $course_id ){
1450
-
1451
-        $non_module_lessons = array();
1452
-
1453
-        //exit if there is no course id passed in
1454
-        if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1455
-
1456
-            return $non_module_lessons;
1457
-        }
1458
-
1459
-        //save some time and check if we already have the saved
1460
-        if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1461
-
1462
-            return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1463
-
1464
-        }
1465
-
1466
-        // create terms array which must be excluded from other arrays
1467
-        $course_modules = $this->get_course_modules( $course_id );
1468
-
1469
-        //exit if there are no module on this course
1470
-        if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1471
-
1472
-            return  Sensei()->course->course_lessons( $course_id );
1473
-
1474
-        }
1475
-
1476
-        $terms = array();
1477
-        foreach( $course_modules as $module ){
1478
-
1479
-            array_push( $terms ,  $module->term_id );
1480
-
1481
-        }
1482
-
1483
-        $args = array(
1484
-            'post_type' => 'lesson',
1485
-            'post_status' => 'publish',
1486
-            'posts_per_page' => -1,
1487
-            'meta_query' => array(
1488
-                array(
1489
-                    'key' => '_lesson_course',
1490
-                    'value' => intval( $course_id ),
1491
-                    'compare' => '='
1492
-                )
1493
-            ),
1494
-            'tax_query' => array(
1495
-                array(
1496
-                    'taxonomy' => 'module',
1497
-                    'field' => 'id',
1498
-                    'terms' =>  $terms,
1499
-                    'operator' => 'NOT IN'
1500
-                )
1501
-            ),
1502
-            'orderby' => 'menu_order',
1503
-            'order' => 'ASC',
1504
-            'suppress_filters' => 0
1505
-        );
1506
-
1507
-        $wp_lessons_query = new WP_Query( $args );
1508
-
1509
-        if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1510
-            $non_module_lessons = $wp_lessons_query->get_posts();
1511
-            set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1512
-        }
1513
-
1514
-        return $non_module_lessons;
1515
-    } // end get_none_module_lessons
1516
-
1517
-    /**
1518
-     * Register the modules taxonomy
1519
-     *
1520
-     * @since 1.8.0
1521
-     */
1522
-    public function setup_modules_taxonomy(){
1523
-
1524
-        $labels = array(
1525
-            'name' => __('Modules', 'woothemes-sensei'),
1526
-            'singular_name' => __('Module', 'woothemes-sensei'),
1527
-            'search_items' => __('Search Modules', 'woothemes-sensei'),
1528
-            'all_items' => __('All Modules', 'woothemes-sensei'),
1529
-            'parent_item' => __('Parent Module', 'woothemes-sensei'),
1530
-            'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'),
1531
-            'edit_item' => __('Edit Module', 'woothemes-sensei'),
1532
-            'update_item' => __('Update Module', 'woothemes-sensei'),
1533
-            'add_new_item' => __('Add New Module', 'woothemes-sensei'),
1534
-            'new_item_name' => __('New Module Name', 'woothemes-sensei'),
1535
-            'menu_name' => __('Modules', 'woothemes-sensei'),
1536
-        );
1537
-
1538
-        /**
1539
-         * Filter to alter the Sensei Modules rewrite slug
1540
-         *
1541
-         * @since 1.8.0
1542
-         * @param string default 'modules'
1543
-         */
1544
-        $modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules');
1545
-
1546
-        $args = array(
1547
-            'public' => true,
1548
-            'hierarchical' => true,
1549
-            'show_admin_column' => true,
1550
-            'capabilities' => array(
1551
-                'manage_terms' => 'manage_categories',
1552
-                'edit_terms'   => 'edit_courses',
1553
-                'delete_terms' => 'manage_categories',
1554
-                'assign_terms' => 'edit_courses'
1555
-            ),
1556
-            'show_in_nav_menus' => false,
1557
-            'show_in_quick_edit' => false,
1558
-            'show_ui' => true,
1559
-            'rewrite' => array('slug' => $modules_rewrite_slug ),
1560
-            'labels' => $labels
1561
-        );
1562
-
1563
-        register_taxonomy( 'module' , array('course', 'lesson'), $args);
1564
-
1565
-    }// end setup_modules_taxonomy
1566
-
1567
-    /**
1568
-     * When the wants to edit the lesson modules redirect them to the course modules.
1569
-     *
1570
-     * This function is hooked into the admin_menu
1571
-     *
1572
-     * @since 1.8.0
1573
-     * @return void
1574
-     */
1575
-    function redirect_to_lesson_module_taxonomy_to_course( ){
1576
-
1577
-        global $typenow , $taxnow;
1578
-
1579
-        if( 'lesson'== $typenow && 'module'==$taxnow ){
1580
-            wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1581
-        }
1582
-
1583
-    }// end redirect to course taxonomy
1584
-
1585
-    /**
1586
-     * Completely remove the module menu item under lessons.
1587
-     *
1588
-     * This function is hooked into the admin_menu
1589
-     *
1590
-     * @since 1.8.0
1591
-     * @return void
1592
-     */
1593
-    public function remove_lessons_menu_model_taxonomy(){
1594
-        global $submenu;
1595
-
1596
-        if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1597
-            return; // exit
1598
-        }
1599
-
1600
-        $lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1601
-        foreach( $lesson_main_menu as $index => $sub_item ){
1602
-
1603
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1604
-                unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1605
-            }
1606
-        }
1607
-
1608
-    }// end remove lesson module tax
1609
-
1610
-    /**
1611
-     * Completely remove the second modules under courses
1612
-     *
1613
-     * This function is hooked into the admin_menu
1614
-     *
1615
-     * @since 1.8.0
1616
-     * @return void
1617
-     */
1618
-    public function remove_courses_menu_model_taxonomy(){
1619
-        global $submenu;
1620
-
1621
-        if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1622
-            return; // exit
1623
-        }
1624
-
1625
-        $course_main_menu = $submenu['edit.php?post_type=course'];
1626
-        foreach( $course_main_menu as $index => $sub_item ){
1627
-
1628
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1629
-                unset( $submenu['edit.php?post_type=course'][ $index ]);
1630
-            }
1631
-        }
1632
-
1633
-    }// end remove courses module tax
1634
-
1635
-    /**
1636
-     * Determine the author of a module term term by looking at
1637
-     * the prefixed author id. This function will query the full term object.
1638
-     * Will return the admin user author could not be determined.
1639
-     *
1640
-     * @since 1.8.0
1641
-     *
1642
-     * @param string $term_name
1643
-     * @return array $owners { type WP_User }. Empty array if none if found.
1644
-     */
1645
-    public static function get_term_authors( $term_name ){
1646
-
1647
-        $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1648
-
1649
-        $owners = array();
1650
-        if( empty( $terms ) ){
1651
-
1652
-            return $owners;
1389
+	/**
1390
+	 * Returns all lessons for the given module ID
1391
+	 *
1392
+	 * @since 1.8.0
1393
+	 *
1394
+	 * @param $course_id
1395
+	 * @param $term_id
1396
+	 * @return WP_Query $lessons_query
1397
+	 */
1398
+	public function get_lessons_query( $course_id , $term_id ){
1399
+
1400
+		if( empty( $term_id ) || empty( $course_id ) ){
1401
+
1402
+			return array();
1403
+
1404
+		}
1405
+
1406
+		$args = array(
1407
+			'post_type' => 'lesson',
1408
+			'post_status' => 'publish',
1409
+			'posts_per_page' => -1,
1410
+			'meta_query' => array(
1411
+				array(
1412
+					'key' => '_lesson_course',
1413
+					'value' => intval($course_id),
1414
+					'compare' => '='
1415
+				)
1416
+			),
1417
+			'tax_query' => array(
1418
+				array(
1419
+					'taxonomy' => 'module',
1420
+					'field' => 'id',
1421
+					'terms' => intval( $term_id )
1422
+				)
1423
+			),
1424
+			'orderby' => 'menu_order',
1425
+			'order' => 'ASC',
1426
+			'suppress_filters' => 0
1427
+		);
1428
+
1429
+		if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1430
+			$args['meta_key'] = '_order_module_' . intval( $term_id );
1431
+			$args['orderby'] = 'meta_value_num date';
1432
+		}
1433
+
1434
+		$lessons_query = new WP_Query( $args );
1435
+
1436
+		return $lessons_query;
1437
+
1438
+	} // end get lessons
1439
+
1440
+	/**
1441
+	 * Find the lesson in the given course that doesn't belong
1442
+	 * to any of the courses modules
1443
+	 *
1444
+	 *
1445
+	 * @param $course_id
1446
+	 *
1447
+	 * @return array $non_module_lessons
1448
+	 */
1449
+	public function get_none_module_lessons( $course_id ){
1450
+
1451
+		$non_module_lessons = array();
1452
+
1453
+		//exit if there is no course id passed in
1454
+		if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1455
+
1456
+			return $non_module_lessons;
1457
+		}
1458
+
1459
+		//save some time and check if we already have the saved
1460
+		if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1461
+
1462
+			return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1463
+
1464
+		}
1465
+
1466
+		// create terms array which must be excluded from other arrays
1467
+		$course_modules = $this->get_course_modules( $course_id );
1468
+
1469
+		//exit if there are no module on this course
1470
+		if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1471
+
1472
+			return  Sensei()->course->course_lessons( $course_id );
1473
+
1474
+		}
1475
+
1476
+		$terms = array();
1477
+		foreach( $course_modules as $module ){
1478
+
1479
+			array_push( $terms ,  $module->term_id );
1480
+
1481
+		}
1482
+
1483
+		$args = array(
1484
+			'post_type' => 'lesson',
1485
+			'post_status' => 'publish',
1486
+			'posts_per_page' => -1,
1487
+			'meta_query' => array(
1488
+				array(
1489
+					'key' => '_lesson_course',
1490
+					'value' => intval( $course_id ),
1491
+					'compare' => '='
1492
+				)
1493
+			),
1494
+			'tax_query' => array(
1495
+				array(
1496
+					'taxonomy' => 'module',
1497
+					'field' => 'id',
1498
+					'terms' =>  $terms,
1499
+					'operator' => 'NOT IN'
1500
+				)
1501
+			),
1502
+			'orderby' => 'menu_order',
1503
+			'order' => 'ASC',
1504
+			'suppress_filters' => 0
1505
+		);
1506
+
1507
+		$wp_lessons_query = new WP_Query( $args );
1508
+
1509
+		if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1510
+			$non_module_lessons = $wp_lessons_query->get_posts();
1511
+			set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1512
+		}
1513
+
1514
+		return $non_module_lessons;
1515
+	} // end get_none_module_lessons
1516
+
1517
+	/**
1518
+	 * Register the modules taxonomy
1519
+	 *
1520
+	 * @since 1.8.0
1521
+	 */
1522
+	public function setup_modules_taxonomy(){
1523
+
1524
+		$labels = array(
1525
+			'name' => __('Modules', 'woothemes-sensei'),
1526
+			'singular_name' => __('Module', 'woothemes-sensei'),
1527
+			'search_items' => __('Search Modules', 'woothemes-sensei'),
1528
+			'all_items' => __('All Modules', 'woothemes-sensei'),
1529
+			'parent_item' => __('Parent Module', 'woothemes-sensei'),
1530
+			'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'),
1531
+			'edit_item' => __('Edit Module', 'woothemes-sensei'),
1532
+			'update_item' => __('Update Module', 'woothemes-sensei'),
1533
+			'add_new_item' => __('Add New Module', 'woothemes-sensei'),
1534
+			'new_item_name' => __('New Module Name', 'woothemes-sensei'),
1535
+			'menu_name' => __('Modules', 'woothemes-sensei'),
1536
+		);
1537
+
1538
+		/**
1539
+		 * Filter to alter the Sensei Modules rewrite slug
1540
+		 *
1541
+		 * @since 1.8.0
1542
+		 * @param string default 'modules'
1543
+		 */
1544
+		$modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules');
1545
+
1546
+		$args = array(
1547
+			'public' => true,
1548
+			'hierarchical' => true,
1549
+			'show_admin_column' => true,
1550
+			'capabilities' => array(
1551
+				'manage_terms' => 'manage_categories',
1552
+				'edit_terms'   => 'edit_courses',
1553
+				'delete_terms' => 'manage_categories',
1554
+				'assign_terms' => 'edit_courses'
1555
+			),
1556
+			'show_in_nav_menus' => false,
1557
+			'show_in_quick_edit' => false,
1558
+			'show_ui' => true,
1559
+			'rewrite' => array('slug' => $modules_rewrite_slug ),
1560
+			'labels' => $labels
1561
+		);
1562
+
1563
+		register_taxonomy( 'module' , array('course', 'lesson'), $args);
1564
+
1565
+	}// end setup_modules_taxonomy
1566
+
1567
+	/**
1568
+	 * When the wants to edit the lesson modules redirect them to the course modules.
1569
+	 *
1570
+	 * This function is hooked into the admin_menu
1571
+	 *
1572
+	 * @since 1.8.0
1573
+	 * @return void
1574
+	 */
1575
+	function redirect_to_lesson_module_taxonomy_to_course( ){
1576
+
1577
+		global $typenow , $taxnow;
1578
+
1579
+		if( 'lesson'== $typenow && 'module'==$taxnow ){
1580
+			wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1581
+		}
1582
+
1583
+	}// end redirect to course taxonomy
1584
+
1585
+	/**
1586
+	 * Completely remove the module menu item under lessons.
1587
+	 *
1588
+	 * This function is hooked into the admin_menu
1589
+	 *
1590
+	 * @since 1.8.0
1591
+	 * @return void
1592
+	 */
1593
+	public function remove_lessons_menu_model_taxonomy(){
1594
+		global $submenu;
1595
+
1596
+		if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1597
+			return; // exit
1598
+		}
1599
+
1600
+		$lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1601
+		foreach( $lesson_main_menu as $index => $sub_item ){
1602
+
1603
+			if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1604
+				unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1605
+			}
1606
+		}
1607
+
1608
+	}// end remove lesson module tax
1609
+
1610
+	/**
1611
+	 * Completely remove the second modules under courses
1612
+	 *
1613
+	 * This function is hooked into the admin_menu
1614
+	 *
1615
+	 * @since 1.8.0
1616
+	 * @return void
1617
+	 */
1618
+	public function remove_courses_menu_model_taxonomy(){
1619
+		global $submenu;
1620
+
1621
+		if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1622
+			return; // exit
1623
+		}
1624
+
1625
+		$course_main_menu = $submenu['edit.php?post_type=course'];
1626
+		foreach( $course_main_menu as $index => $sub_item ){
1627
+
1628
+			if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1629
+				unset( $submenu['edit.php?post_type=course'][ $index ]);
1630
+			}
1631
+		}
1632
+
1633
+	}// end remove courses module tax
1634
+
1635
+	/**
1636
+	 * Determine the author of a module term term by looking at
1637
+	 * the prefixed author id. This function will query the full term object.
1638
+	 * Will return the admin user author could not be determined.
1639
+	 *
1640
+	 * @since 1.8.0
1641
+	 *
1642
+	 * @param string $term_name
1643
+	 * @return array $owners { type WP_User }. Empty array if none if found.
1644
+	 */
1645
+	public static function get_term_authors( $term_name ){
1646
+
1647
+		$terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1648
+
1649
+		$owners = array();
1650
+		if( empty( $terms ) ){
1651
+
1652
+			return $owners;
1653 1653
 
1654
-        }
1654
+		}
1655 1655
 
1656
-        // setup the admin user
1656
+		// setup the admin user
1657 1657
 
1658 1658
 
1659
-        //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1660
-        foreach( $terms as $term){
1661
-            if( $term->name == $term_name ){
1659
+		//if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1660
+		foreach( $terms as $term){
1661
+			if( $term->name == $term_name ){
1662 1662
 
1663
-                // look for the author in the slug
1664
-                $owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1663
+				// look for the author in the slug
1664
+				$owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1665 1665
 
1666
-            }// end if term name
1666
+			}// end if term name
1667 1667
 
1668
-        } // end for each
1668
+		} // end for each
1669 1669
 
1670
-        return $owners;
1670
+		return $owners;
1671 1671
 
1672
-    }// end get_term_author
1672
+	}// end get_term_author
1673 1673
 
1674
-    /**
1675
-     * Looks at a term slug and figures out
1676
-     * which author created the slug. The author was
1677
-     * appended when the user saved the module term in the course edit
1678
-     * screen.
1679
-     *
1680
-     * @since 1.8.0
1681
-     *
1682
-     * @param $slug
1683
-     * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1684
-     */
1685
-    public static function get_term_author( $slug='' ){
1674
+	/**
1675
+	 * Looks at a term slug and figures out
1676
+	 * which author created the slug. The author was
1677
+	 * appended when the user saved the module term in the course edit
1678
+	 * screen.
1679
+	 *
1680
+	 * @since 1.8.0
1681
+	 *
1682
+	 * @param $slug
1683
+	 * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1684
+	 */
1685
+	public static function get_term_author( $slug='' ){
1686 1686
 
1687
-        $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1687
+		$term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1688 1688
 
1689
-        if( empty( $slug ) ){
1689
+		if( empty( $slug ) ){
1690 1690
 
1691
-            return $term_owner;
1691
+			return $term_owner;
1692 1692
 
1693
-        }
1693
+		}
1694 1694
 
1695
-        // look for the author in the slug
1696
-        $slug_parts = explode( '-', $slug );
1695
+		// look for the author in the slug
1696
+		$slug_parts = explode( '-', $slug );
1697 1697
 
1698
-        if( count( $slug_parts ) > 1 ){
1698
+		if( count( $slug_parts ) > 1 ){
1699 1699
 
1700
-            // get the user data
1701
-            $possible_user_id = $slug_parts[0];
1702
-            $author = get_userdata( $possible_user_id );
1700
+			// get the user data
1701
+			$possible_user_id = $slug_parts[0];
1702
+			$author = get_userdata( $possible_user_id );
1703 1703
 
1704
-            // if the user doesnt exist for the first part of the slug
1705
-            // then this slug was also created by admin
1706
-            if( is_a( $author, 'WP_User' ) ){
1704
+			// if the user doesnt exist for the first part of the slug
1705
+			// then this slug was also created by admin
1706
+			if( is_a( $author, 'WP_User' ) ){
1707 1707
 
1708
-                $term_owner =  $author;
1708
+				$term_owner =  $author;
1709 1709
 
1710
-            }
1711
-        }
1710
+			}
1711
+		}
1712 1712
 
1713
-        return $term_owner;
1714
-    }
1713
+		return $term_owner;
1714
+	}
1715 1715
 
1716
-    /**
1717
-     * Display the Sensei modules taxonomy terms metabox
1718
-     *
1719
-     * @since 1.8.0
1720
-     *
1721
-     * @hooked into add_meta_box
1722
-     *
1723
-     * @param WP_Post $post Post object.
1724
-     */
1725
-    public function course_module_metabox( $post ) {
1716
+	/**
1717
+	 * Display the Sensei modules taxonomy terms metabox
1718
+	 *
1719
+	 * @since 1.8.0
1720
+	 *
1721
+	 * @hooked into add_meta_box
1722
+	 *
1723
+	 * @param WP_Post $post Post object.
1724
+	 */
1725
+	public function course_module_metabox( $post ) {
1726 1726
 
1727
-        $tax_name = 'module';
1728
-        $taxonomy = get_taxonomy( 'module' );
1727
+		$tax_name = 'module';
1728
+		$taxonomy = get_taxonomy( 'module' );
1729 1729
 
1730
-        ?>
1730
+		?>
1731 1731
         <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
1732 1732
             <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs">
1733 1733
                 <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li>
@@ -1742,9 +1742,9 @@  discard block
 block discarded – undo
1742 1742
 
1743 1743
             <div id="<?php echo $tax_name; ?>-all" class="tabs-panel">
1744 1744
                 <?php
1745
-                $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1746
-                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.
1747
-                ?>
1745
+				$name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1746
+				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.
1747
+				?>
1748 1748
                 <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">
1749 1749
                     <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?>
1750 1750
                 </ul>
@@ -1754,9 +1754,9 @@  discard block
 block discarded – undo
1754 1754
                     <h4>
1755 1755
                         <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js">
1756 1756
                             <?php
1757
-                            /* translators: %s: add new taxonomy label */
1758
-                            printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1759
-                            ?>
1757
+							/* translators: %s: add new taxonomy label */
1758
+							printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1759
+							?>
1760 1760
                         </a>
1761 1761
                     </h4>
1762 1762
                     <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">
@@ -1771,331 +1771,331 @@  discard block
 block discarded – undo
1771 1771
         </div>
1772 1772
     <?php
1773 1773
 
1774
-    } // end course_module_metabox
1774
+	} // end course_module_metabox
1775 1775
 
1776 1776
 
1777
-    /**
1778
-     * Submits a new module term prefixed with the
1779
-     * the current author id.
1780
-     *
1781
-     * @since 1.8.0
1782
-     */
1783
-    public static function add_new_module_term( ) {
1777
+	/**
1778
+	 * Submits a new module term prefixed with the
1779
+	 * the current author id.
1780
+	 *
1781
+	 * @since 1.8.0
1782
+	 */
1783
+	public static function add_new_module_term( ) {
1784 1784
 
1785 1785
 
1786
-        if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1787
-            wp_send_json_error( array('error'=> 'wrong security nonce') );
1788
-        }
1786
+		if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1787
+			wp_send_json_error( array('error'=> 'wrong security nonce') );
1788
+		}
1789 1789
 
1790
-        // get the term an create the new term storing infomration
1791
-        $term_name = sanitize_text_field( $_POST['newTerm'] );
1790
+		// get the term an create the new term storing infomration
1791
+		$term_name = sanitize_text_field( $_POST['newTerm'] );
1792 1792
 
1793
-        if( current_user_can('manage_options' ) ) {
1793
+		if( current_user_can('manage_options' ) ) {
1794 1794
 
1795
-            $term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1795
+			$term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1796 1796
 
1797
-        } else {
1797
+		} else {
1798 1798
 
1799
-            $term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1799
+			$term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1800 1800
 
1801
-        }
1801
+		}
1802 1802
 
1803
-        $course_id = sanitize_text_field( $_POST['course_id'] );
1803
+		$course_id = sanitize_text_field( $_POST['course_id'] );
1804 1804
 
1805
-        // save the term
1806
-        $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1805
+		// save the term
1806
+		$slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1807 1807
 
1808
-        // send error for all errors except term exits
1809
-        if( is_wp_error( $slug ) ){
1808
+		// send error for all errors except term exits
1809
+		if( is_wp_error( $slug ) ){
1810 1810
 
1811
-            // prepare for possible term name and id to be passed down if term exists
1812
-            $term_data = array();
1811
+			// prepare for possible term name and id to be passed down if term exists
1812
+			$term_data = array();
1813 1813
 
1814
-            // if term exists also send back the term name and id
1815
-            if( isset( $slug->errors['term_exists'] ) ){
1814
+			// if term exists also send back the term name and id
1815
+			if( isset( $slug->errors['term_exists'] ) ){
1816 1816
 
1817
-                $term = get_term_by( 'slug', $term_slug, 'module');
1818
-                $term_data['name'] = $term_name;
1819
-                $term_data['id'] = $term->term_id;
1817
+				$term = get_term_by( 'slug', $term_slug, 'module');
1818
+				$term_data['name'] = $term_name;
1819
+				$term_data['id'] = $term->term_id;
1820 1820
 
1821
-                // set the object terms
1822
-                wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1823
-            }
1821
+				// set the object terms
1822
+				wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1823
+			}
1824 1824
 
1825
-            wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1825
+			wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1826 1826
 
1827
-        }
1827
+		}
1828 1828
 
1829
-        //make sure the new term is checked for this course
1829
+		//make sure the new term is checked for this course
1830 1830
 
1831
-        wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1831
+		wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1832 1832
 
1833
-        // Handle request then generate response using WP_Ajax_Response
1834
-        wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1833
+		// Handle request then generate response using WP_Ajax_Response
1834
+		wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1835 1835
 
1836
-    }
1836
+	}
1837 1837
 
1838
-    /**
1839
-     * Limit the course module metabox
1840
-     * term list to only those on courses belonging to current teacher.
1841
-     *
1842
-     * Hooked into 'get_terms'
1843
-     *
1844
-     * @since 1.8.0
1845
-     */
1846
-    public function filter_module_terms( $terms, $taxonomies, $args ){
1838
+	/**
1839
+	 * Limit the course module metabox
1840
+	 * term list to only those on courses belonging to current teacher.
1841
+	 *
1842
+	 * Hooked into 'get_terms'
1843
+	 *
1844
+	 * @since 1.8.0
1845
+	 */
1846
+	public function filter_module_terms( $terms, $taxonomies, $args ){
1847 1847
 
1848
-        //dont limit for admins and other taxonomies. This should also only apply to admin
1849
-        if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1850
-            return $terms;
1851
-        }
1848
+		//dont limit for admins and other taxonomies. This should also only apply to admin
1849
+		if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1850
+			return $terms;
1851
+		}
1852 1852
 
1853
-        // avoid infinite call loop
1854
-        remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1853
+		// avoid infinite call loop
1854
+		remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1855 1855
 
1856
-        // in certain cases the array is passed in as reference to the parent term_id => parent_id
1857
-        if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1858
-            // change only scrub the terms ids form the array keys
1859
-            $terms = array_keys( $terms );
1860
-        }
1856
+		// in certain cases the array is passed in as reference to the parent term_id => parent_id
1857
+		if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1858
+			// change only scrub the terms ids form the array keys
1859
+			$terms = array_keys( $terms );
1860
+		}
1861 1861
 
1862
-        $teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1862
+		$teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1863 1863
 
1864
-        // add filter again as removed above
1865
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1864
+		// add filter again as removed above
1865
+		add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1866 1866
 
1867
-        return $teachers_terms;
1868
-    }// end filter_module_terms
1867
+		return $teachers_terms;
1868
+	}// end filter_module_terms
1869 1869
 
1870
-    /**
1871
-     * For the selected items on a course module only return those
1872
-     * for the current user. This does not apply to admin and super admin users.
1873
-     *
1874
-     * hooked into get_object_terms
1875
-     *
1876
-     * @since 1.8.0
1877
-     */
1878
-    public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1870
+	/**
1871
+	 * For the selected items on a course module only return those
1872
+	 * for the current user. This does not apply to admin and super admin users.
1873
+	 *
1874
+	 * hooked into get_object_terms
1875
+	 *
1876
+	 * @since 1.8.0
1877
+	 */
1878
+	public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1879 1879
 
1880
-        //dont limit for admins and other taxonomies. This should also only apply to admin
1881
-        if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1882
-            // only apply this to module only taxonomy queries so 1 taxonomy only:
1883
-            ||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1884
-            return $terms;
1885
-        }
1880
+		//dont limit for admins and other taxonomies. This should also only apply to admin
1881
+		if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1882
+			// only apply this to module only taxonomy queries so 1 taxonomy only:
1883
+			||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1884
+			return $terms;
1885
+		}
1886 1886
 
1887
-        $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1887
+		$term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1888 1888
 
1889
-        // if term objects were passed in send back objects
1890
-        // if term id were passed in send that back
1891
-        if( is_object( $terms[0] ) ){
1892
-            return $term_objects;
1893
-        }
1889
+		// if term objects were passed in send back objects
1890
+		// if term id were passed in send that back
1891
+		if( is_object( $terms[0] ) ){
1892
+			return $term_objects;
1893
+		}
1894 1894
 
1895
-        $terms = array();
1896
-        foreach( $term_objects as $term_object ){
1897
-            $terms[] = $term_object->term_id;
1898
-        }
1895
+		$terms = array();
1896
+		foreach( $term_objects as $term_object ){
1897
+			$terms[] = $term_object->term_id;
1898
+		}
1899 1899
 
1900
-        return $terms;
1900
+		return $terms;
1901 1901
 
1902 1902
 
1903
-    }// end filter_course_selected_terms
1903
+	}// end filter_course_selected_terms
1904 1904
 
1905
-    /**
1906
-     * Filter the given terms and only return the
1907
-     * terms that belong to the given user id.
1908
-     *
1909
-     * @since 1.8.0
1910
-     * @param $terms
1911
-     * @param $user_id
1912
-     * @return array
1913
-     */
1914
-    public function filter_terms_by_owner( $terms, $user_id ){
1905
+	/**
1906
+	 * Filter the given terms and only return the
1907
+	 * terms that belong to the given user id.
1908
+	 *
1909
+	 * @since 1.8.0
1910
+	 * @param $terms
1911
+	 * @param $user_id
1912
+	 * @return array
1913
+	 */
1914
+	public function filter_terms_by_owner( $terms, $user_id ){
1915 1915
 
1916
-        $users_terms = array();
1916
+		$users_terms = array();
1917 1917
 
1918
-        foreach( $terms as $index => $term ){
1918
+		foreach( $terms as $index => $term ){
1919 1919
 
1920
-            if( is_numeric( $term ) ){
1921
-                // the term id was given, get the term object
1922
-                $term = get_term( $term, 'module' );
1923
-            }
1920
+			if( is_numeric( $term ) ){
1921
+				// the term id was given, get the term object
1922
+				$term = get_term( $term, 'module' );
1923
+			}
1924 1924
 
1925
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1925
+			$author = Sensei_Core_Modules::get_term_author( $term->slug );
1926 1926
 
1927
-            if ( $user_id == $author->ID ) {
1928
-                // add the term to the teachers terms
1929
-                $users_terms[] = $term;
1930
-            }
1927
+			if ( $user_id == $author->ID ) {
1928
+				// add the term to the teachers terms
1929
+				$users_terms[] = $term;
1930
+			}
1931 1931
 
1932
-        }
1932
+		}
1933 1933
 
1934
-        return $users_terms;
1934
+		return $users_terms;
1935 1935
 
1936
-    } // end filter terms by owner
1936
+	} // end filter terms by owner
1937 1937
 
1938
-    /**
1939
-     * Add the teacher name next to modules. Only works in Admin for Admin users.
1940
-     * This will not add name to terms belonging to admin user.
1941
-     *
1942
-     * Hooked into 'get_terms'
1943
-     *
1944
-     * @since 1.8.0
1945
-     */
1946
-    public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1947
-    {
1938
+	/**
1939
+	 * Add the teacher name next to modules. Only works in Admin for Admin users.
1940
+	 * This will not add name to terms belonging to admin user.
1941
+	 *
1942
+	 * Hooked into 'get_terms'
1943
+	 *
1944
+	 * @since 1.8.0
1945
+	 */
1946
+	public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1947
+	{
1948 1948
 
1949
-        // only for admin users ont he module taxonomy
1950
-        if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1951
-            return $terms;
1952
-        }
1949
+		// only for admin users ont he module taxonomy
1950
+		if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1951
+			return $terms;
1952
+		}
1953 1953
 
1954
-        // in certain cases the array is passed in as reference to the parent term_id => parent_id
1955
-        // simply return this as wp doesn't need an array of stdObject Term
1956
-        if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1954
+		// in certain cases the array is passed in as reference to the parent term_id => parent_id
1955
+		// simply return this as wp doesn't need an array of stdObject Term
1956
+		if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1957 1957
 
1958
-            return $terms;
1958
+			return $terms;
1959 1959
 
1960
-        }
1960
+		}
1961 1961
 
1962
-        // loop through and update all terms adding the author name
1963
-        foreach( $terms as $index => $term ){
1962
+		// loop through and update all terms adding the author name
1963
+		foreach( $terms as $index => $term ){
1964 1964
 
1965
-            if( is_numeric( $term ) ){
1966
-                // the term id was given, get the term object
1967
-                $term = get_term( $term, 'module' );
1968
-            }
1965
+			if( is_numeric( $term ) ){
1966
+				// the term id was given, get the term object
1967
+				$term = get_term( $term, 'module' );
1968
+			}
1969 1969
 
1970
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1970
+			$author = Sensei_Core_Modules::get_term_author( $term->slug );
1971 1971
 
1972
-            if( ! user_can( $author, 'manage_options' ) ) {
1973
-                $term->name = $term->name . ' (' . $author->display_name . ') ';
1974
-            }
1972
+			if( ! user_can( $author, 'manage_options' ) ) {
1973
+				$term->name = $term->name . ' (' . $author->display_name . ') ';
1974
+			}
1975 1975
 
1976
-            // add the term to the teachers terms
1977
-            $users_terms[] = $term;
1976
+			// add the term to the teachers terms
1977
+			$users_terms[] = $term;
1978 1978
 
1979
-        }
1979
+		}
1980 1980
 
1981
-        return $users_terms;
1982
-    }
1981
+		return $users_terms;
1982
+	}
1983 1983
 
1984
-    /**
1985
-     * Remove modules metabox that come by default
1986
-     * with the modules taxonomy. We are removing this as
1987
-     * we have created our own custom meta box.
1988
-     */
1989
-    public static function remove_default_modules_box() {
1984
+	/**
1985
+	 * Remove modules metabox that come by default
1986
+	 * with the modules taxonomy. We are removing this as
1987
+	 * we have created our own custom meta box.
1988
+	 */
1989
+	public static function remove_default_modules_box() {
1990 1990
 
1991
-        remove_meta_box('modulediv', 'course', 'side');
1991
+		remove_meta_box('modulediv', 'course', 'side');
1992 1992
 
1993
-    }
1993
+	}
1994 1994
 
1995
-    /**
1996
-     * When a course is save make sure to reset the transient set
1997
-     * for it when determining the none module lessons.
1998
-     *
1999
-     * @sine 1.9.0
2000
-     * @param $post_id
2001
-     */
2002
-    public static function reset_none_modules_transient ( $post_id ){
1995
+	/**
1996
+	 * When a course is save make sure to reset the transient set
1997
+	 * for it when determining the none module lessons.
1998
+	 *
1999
+	 * @sine 1.9.0
2000
+	 * @param $post_id
2001
+	 */
2002
+	public static function reset_none_modules_transient ( $post_id ){
2003 2003
 
2004
-        // this should only apply to course and lesson post types
2005
-        if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2004
+		// this should only apply to course and lesson post types
2005
+		if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2006 2006
 
2007
-            $course_id = '';
2007
+			$course_id = '';
2008 2008
 
2009
-            if( 'lesson' == get_post_type( $post_id ) ){
2009
+			if( 'lesson' == get_post_type( $post_id ) ){
2010 2010
 
2011
-                $course_id = Sensei()->lesson->get_course_id( $post_id );
2011
+				$course_id = Sensei()->lesson->get_course_id( $post_id );
2012 2012
 
2013
-            }
2013
+			}
2014 2014
 
2015 2015
 
2016
-            if( !empty( $course_id ) ){
2016
+			if( !empty( $course_id ) ){
2017 2017
 
2018
-                delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2018
+				delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2019 2019
 
2020
-            }
2020
+			}
2021 2021
 
2022
-        } // end if is a course or a lesson
2022
+		} // end if is a course or a lesson
2023 2023
 
2024
-    } // end reset_none_modules_transient
2024
+	} // end reset_none_modules_transient
2025 2025
 
2026
-    /**
2027
-     * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire
2028
-     *
2029
-     * @since 1.9.0
2030
-     * @deprecated since 1.9.0
2031
-     *
2032
-     */
2033
-    public static function deprecate_sensei_single_course_modules_content(){
2026
+	/**
2027
+	 * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire
2028
+	 *
2029
+	 * @since 1.9.0
2030
+	 * @deprecated since 1.9.0
2031
+	 *
2032
+	 */
2033
+	public static function deprecate_sensei_single_course_modules_content(){
2034 2034
 
2035
-        sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2035
+		sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2036 2036
 
2037
-    }
2037
+	}
2038 2038
 
2039
-    /**
2040
-     * Setup the single course module loop.
2041
-     *
2042
-     * Setup the global $sensei_modules_loop
2043
-     *
2044
-     * @since 1.9.0
2045
-     */
2046
-    public static function setup_single_course_module_loop(){
2039
+	/**
2040
+	 * Setup the single course module loop.
2041
+	 *
2042
+	 * Setup the global $sensei_modules_loop
2043
+	 *
2044
+	 * @since 1.9.0
2045
+	 */
2046
+	public static function setup_single_course_module_loop(){
2047 2047
 
2048
-        global $sensei_modules_loop, $post;
2049
-        $course_id = $post->ID;
2048
+		global $sensei_modules_loop, $post;
2049
+		$course_id = $post->ID;
2050 2050
 
2051
-        $modules = Sensei()->modules->get_course_modules( $course_id );
2051
+		$modules = Sensei()->modules->get_course_modules( $course_id );
2052 2052
 
2053
-        //initial setup
2054
-        $sensei_modules_loop['total'] = 0;
2055
-        $sensei_modules_loop['modules'] = array();
2056
-        $sensei_modules_loop['current'] = -1;
2053
+		//initial setup
2054
+		$sensei_modules_loop['total'] = 0;
2055
+		$sensei_modules_loop['modules'] = array();
2056
+		$sensei_modules_loop['current'] = -1;
2057 2057
 
2058
-        // exit if this course doesn't have modules
2059
-        if( !$modules || empty( $modules )  ){
2060
-            return;
2061
-        }
2058
+		// exit if this course doesn't have modules
2059
+		if( !$modules || empty( $modules )  ){
2060
+			return;
2061
+		}
2062 2062
 
2063 2063
 
2064
-        $lessons_in_all_modules = array();
2065
-        foreach( $modules as $term ){
2064
+		$lessons_in_all_modules = array();
2065
+		foreach( $modules as $term ){
2066 2066
 
2067
-            $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2068
-            $lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2067
+			$lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2068
+			$lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2069 2069
 
2070
-        }
2070
+		}
2071 2071
 
2072 2072
 
2073
-        //setup all of the modules loop variables
2074
-        $sensei_modules_loop['total'] = count( $modules );
2075
-        $sensei_modules_loop['modules'] = $modules;
2076
-        $sensei_modules_loop['current'] = -1;
2077
-        $sensei_modules_loop['course_id'] = $course_id;
2073
+		//setup all of the modules loop variables
2074
+		$sensei_modules_loop['total'] = count( $modules );
2075
+		$sensei_modules_loop['modules'] = $modules;
2076
+		$sensei_modules_loop['current'] = -1;
2077
+		$sensei_modules_loop['course_id'] = $course_id;
2078 2078
 
2079
-    }// end setup_single_course_module_loop
2079
+	}// end setup_single_course_module_loop
2080 2080
 
2081
-    /**
2082
-     * Tear down the course module loop.
2083
-     *
2084
-     * @since 1.9.0
2085
-     *
2086
-     */
2087
-    public static function teardown_single_course_module_loop(){
2081
+	/**
2082
+	 * Tear down the course module loop.
2083
+	 *
2084
+	 * @since 1.9.0
2085
+	 *
2086
+	 */
2087
+	public static function teardown_single_course_module_loop(){
2088 2088
 
2089
-        global $sensei_modules_loop, $wp_query, $post;
2089
+		global $sensei_modules_loop, $wp_query, $post;
2090 2090
 
2091
-        //reset all of the modules loop variables
2092
-        $sensei_modules_loop['total'] = 0;
2093
-        $sensei_modules_loop['modules'] = array();
2094
-        $sensei_modules_loop['current'] = -1;
2091
+		//reset all of the modules loop variables
2092
+		$sensei_modules_loop['total'] = 0;
2093
+		$sensei_modules_loop['modules'] = array();
2094
+		$sensei_modules_loop['current'] = -1;
2095 2095
 
2096
-        // set the current course to be the global post again
2097
-        wp_reset_query();
2098
-        $post = $wp_query->post;
2099
-    }// end teardown_single_course_module_loop
2096
+		// set the current course to be the global post again
2097
+		wp_reset_query();
2098
+		$post = $wp_query->post;
2099
+	}// end teardown_single_course_module_loop
2100 2100
 
2101 2101
 } // end modules class
Please login to merge, or discard this patch.
Spacing   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if ( ! defined('ABSPATH')) exit;
4 4
 
5 5
 /**
6 6
  * Sensei Modules Class
@@ -21,33 +21,33 @@  discard block
 block discarded – undo
21 21
     private $order_page_slug;
22 22
     public $taxonomy;
23 23
 
24
-    public function __construct( $file )
24
+    public function __construct($file)
25 25
     {
26 26
         $this->file = $file;
27 27
         $this->dir = dirname($this->file);
28
-        $this->assets_dir = trailingslashit($this->dir) . 'assets';
28
+        $this->assets_dir = trailingslashit($this->dir).'assets';
29 29
         $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file)));
30 30
         $this->taxonomy = 'module';
31 31
         $this->order_page_slug = 'module-order';
32 32
 
33 33
         // setup taxonomy
34
-        add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 );
34
+        add_action('init', array($this, 'setup_modules_taxonomy'), 10);
35 35
 
36 36
         // Manage lesson meta boxes for taxonomy
37
-        add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 );
37
+        add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2);
38 38
 
39 39
         // Save lesson meta box
40 40
         add_action('save_post', array($this, 'save_lesson_module'), 10, 1);
41 41
 
42 42
         //Reset the none modules lessons transient
43
-        add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) );
43
+        add_action('save_post', array('Sensei_Core_Modules', 'reset_none_modules_transient'));
44 44
 
45 45
         // Frontend styling
46 46
         add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
47 47
 
48 48
         // Admin styling
49 49
         add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles'));
50
-        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'),  20 , 2 );
50
+        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 20, 2);
51 51
 
52 52
         // Handle module completion record
53 53
         add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3);
@@ -55,20 +55,20 @@  discard block
 block discarded – undo
55 55
         add_action('wp', array($this, 'save_module_progress'), 10);
56 56
 
57 57
         // Handle module ordering
58
-        add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 );
58
+        add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30);
59 59
         add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1);
60 60
         add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2);
61 61
 
62 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 );
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 66
 
67 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);
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 72
         add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json'));
73 73
 
74 74
         // Manage module taxonomy archive page
@@ -80,10 +80,10 @@  discard block
 block discarded – undo
80 80
         add_filter('body_class', array($this, 'module_archive_body_class'));
81 81
 
82 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 );
83
+        add_action('sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template'), 8);
84 84
 
85 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);
86
+        add_action('sensei_single_course_modules_before', array($this, 'course_modules_title'), 20);
87 87
 
88 88
         // Set up display on single lesson page
89 89
         add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2);
@@ -95,22 +95,22 @@  discard block
 block discarded – undo
95 95
         add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3);
96 96
 
97 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);
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 100
         add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2);
101 101
 
102 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' ) );
103
+        add_action('wp_ajax_sensei_add_new_module_term', array('Sensei_Core_Modules', 'add_new_module_term'));
104 104
 
105 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 );
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 108
 
109 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 );
110
+        add_filter('get_terms', array($this, 'append_teacher_name_to_module'), 70, 3);
111 111
 
112 112
         // remove the default modules  metabox
113
-        add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' ));
113
+        add_action('admin_init', array('Sensei_Core_Modules', 'remove_default_modules_box'));
114 114
 
115 115
     } // end constructor
116 116
 
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
      * @return void
128 128
      * @deprecated since 1.9.0
129 129
      */
130
-    public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){
130
+    public function change_module_term_slug($term_id, $tt_id, $taxonomy) {
131 131
 
132
-        _deprecated_function('change_module_term_slug', '1.9.0' );
132
+        _deprecated_function('change_module_term_slug', '1.9.0');
133 133
 
134 134
     }// end add_module_term_group
135 135
 
@@ -143,20 +143,20 @@  discard block
 block discarded – undo
143 143
      *
144 144
      * @return void
145 145
      */
146
-    public function modules_metaboxes( $post_type, $post )
146
+    public function modules_metaboxes($post_type, $post)
147 147
     {
148
-        if ('lesson' == $post_type ) {
148
+        if ('lesson' == $post_type) {
149 149
 
150 150
             // Remove default taxonomy meta box from Lesson edit screen
151
-            remove_meta_box($this->taxonomy . 'div', 'lesson', 'side');
151
+            remove_meta_box($this->taxonomy.'div', 'lesson', 'side');
152 152
 
153 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');
154
+            add_meta_box($this->taxonomy.'_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default');
155 155
         }
156 156
 
157
-        if( 'course' == $post_type ){
157
+        if ('course' == $post_type) {
158 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');
159
+            add_meta_box($this->taxonomy.'_course_mb', __('Course Modules', 'woothemes-sensei'), array($this, 'course_module_metabox'), 'course', 'side', 'core');
160 160
         }
161 161
     }
162 162
 
@@ -192,21 +192,21 @@  discard block
 block discarded – undo
192 192
             $modules = $this->get_course_modules($lesson_course);
193 193
 
194 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))) . '" />';
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 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>';
197
+                $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">'."\n";
198
+                $html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
199 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";
200
+                    $html .= '<option value="'.esc_attr(absint($module->term_id)).'"'.selected($module->term_id, $lesson_module, false).'>'.esc_html($module->name).'</option>'."\n";
201 201
                 }
202
-                $html .= '</select>' . "\n";
202
+                $html .= '</select>'."\n";
203 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>';
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 206
             } // End If Statement
207 207
 
208 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>';
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 210
         } // End If Statement
211 211
 
212 212
         // Output the HTML
@@ -225,38 +225,38 @@  discard block
 block discarded – undo
225 225
         global $post;
226 226
 
227 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))) {
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 230
             return $post_id;
231 231
         }
232 232
 
233 233
         // Check if user has permissions to edit lessons
234 234
         $post_type = get_post_type_object($post->post_type);
235
-        if (!current_user_can($post_type->cap->edit_post, $post_id)) {
235
+        if ( ! current_user_can($post_type->cap->edit_post, $post_id)) {
236 236
             return $post_id;
237 237
         }
238 238
 
239 239
         // Check if user has permissions to edit this specific post
240
-        if (!current_user_can('edit_post', $post_id)) {
240
+        if ( ! current_user_can('edit_post', $post_id)) {
241 241
             return $post_id;
242 242
         }
243 243
 
244 244
         // Cast module ID as an integer if selected, otherwise leave as empty string
245
-        if ( isset( $_POST['lesson_module'] ) ) {
245
+        if (isset($_POST['lesson_module'])) {
246 246
 
247
-            if( empty ( $_POST['lesson_module'] ) ){
248
-                wp_delete_object_term_relationships($post_id, $this->taxonomy  );
247
+            if (empty ($_POST['lesson_module'])) {
248
+                wp_delete_object_term_relationships($post_id, $this->taxonomy);
249 249
                 return true;
250 250
             }
251 251
 
252
-            $module_id = intval( $_POST['lesson_module'] );
252
+            $module_id = intval($_POST['lesson_module']);
253 253
 
254 254
             // Assign lesson to selected module
255 255
             wp_set_object_terms($post_id, $module_id, $this->taxonomy, false);
256 256
 
257 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);
258
+            if ( ! get_post_meta($post_id, '_order_module_'.$module_id, true)) {
259
+                update_post_meta($post_id, '_order_module_'.$module_id, 0);
260 260
             }
261 261
         }
262 262
 
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
         $module_courses = array();
315 315
         if (isset($courses) && is_array($courses)) {
316 316
             foreach ($courses as $course) {
317
-                $module_courses[] =   array( 'id' =>$course->ID, 'details'=>$course->post_title );
317
+                $module_courses[] = array('id' =>$course->ID, 'details'=>$course->post_title);
318 318
             }
319 319
         }
320 320
 
@@ -324,8 +324,8 @@  discard block
 block discarded – undo
324 324
                     for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label></th>
325 325
             <td>
326 326
                 <input type="hidden"
327
-                       data-defaults="<?php echo esc_attr( json_encode($module_courses)); ?>"
328
-                       value="<?php echo esc_attr( json_encode($module_courses) ); ?>"
327
+                       data-defaults="<?php echo esc_attr(json_encode($module_courses)); ?>"
328
+                       value="<?php echo esc_attr(json_encode($module_courses)); ?>"
329 329
                        id="module_courses" name="module_courses"
330 330
                        class="ajax_chosen_select_courses"
331 331
                        placeholder="<?php esc_attr_e('Search for courses...', 'woothemes-sensei'); ?>"
@@ -370,11 +370,11 @@  discard block
 block discarded – undo
370 370
         }
371 371
 
372 372
         // Add module to selected courses
373
-        if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) {
373
+        if (isset($_POST['module_courses']) && ! empty($_POST['module_courses'])) {
374 374
 
375
-            $course_ids = explode( ",", $_POST['module_courses'] );
375
+            $course_ids = explode(",", $_POST['module_courses']);
376 376
 
377
-            foreach ( $course_ids as $course_id ) {
377
+            foreach ($course_ids as $course_id) {
378 378
 
379 379
                 wp_set_object_terms($course_id, $module_id, $this->taxonomy, true);
380 380
 
@@ -438,11 +438,11 @@  discard block
 block discarded – undo
438 438
      * @since 1.8.0
439 439
      * @return void
440 440
      */
441
-    public function single_course_modules(){
441
+    public function single_course_modules() {
442 442
 
443
-        _deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
443
+        _deprecated_function('Sensei_Modules->single_course_modules', 'Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
444 444
         // only show modules on the course that has modules
445
-        if( is_singular( 'course' ) && has_term( '', 'module' )  )  {
445
+        if (is_singular('course') && has_term('', 'module')) {
446 446
 
447 447
             $this->load_course_module_content_template();
448 448
 
@@ -459,15 +459,15 @@  discard block
 block discarded – undo
459 459
 
460 460
         if (method_exists('WooThemes_Sensei_Utils', 'is_preview_lesson') && WooThemes_Sensei_Utils::is_preview_lesson($lesson_id)) {
461 461
             $is_user_taking_course = WooThemes_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) {
462
+            if ( ! $is_user_taking_course) {
463 463
                 if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) {
464 464
                     $title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id);
465 465
                     // Remove brackets for display here
466 466
                     $title_text = str_replace('(', '', $title_text);
467 467
                     $title_text = str_replace(')', '', $title_text);
468
-                    $title_text = '<span class="preview-label">' . $title_text . '</span>';
468
+                    $title_text = '<span class="preview-label">'.$title_text.'</span>';
469 469
                 }
470
-                $title .= ' ' . $title_text;
470
+                $title .= ' '.$title_text;
471 471
             }
472 472
         }
473 473
 
@@ -481,8 +481,8 @@  discard block
 block discarded – undo
481 481
         if (is_singular('lesson')) {
482 482
             if (has_term('', $this->taxonomy, $post->ID)) {
483 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>';
484
+                if ($module) {
485
+                    $html .= ' '.$separator.' <a href="'.esc_url($module->url).'" title="'.__('Back to the module', 'woothemes-sensei').'">'.$module->name.'</a>';
486 486
                 }
487 487
             }
488 488
         }
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
         if (is_tax($this->taxonomy)) {
491 491
             if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
492 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>';
493
+                $html .= '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Back to the course', 'woothemes-sensei').'">'.get_the_title($course_id).'</a>';
494 494
             }
495 495
         }
496 496
         return $html;
@@ -505,18 +505,18 @@  discard block
 block discarded – undo
505 505
      */
506 506
     public function module_archive_template($template) {
507 507
 
508
-        if ( ! is_tax($this->taxonomy) ) {
508
+        if ( ! is_tax($this->taxonomy)) {
509 509
             return $template;
510 510
         }
511 511
 
512 512
         $file = 'archive-lesson.php';
513
-        $find = array( $file, Sensei()->template_url . $file );
513
+        $find = array($file, Sensei()->template_url.$file);
514 514
 
515 515
         // locate the template file
516 516
         $template = locate_template($find);
517
-        if (!$template) {
517
+        if ( ! $template) {
518 518
 
519
-            $template = Sensei()->plugin_path() . 'templates/' . $file;
519
+            $template = Sensei()->plugin_path().'templates/'.$file;
520 520
 
521 521
         }
522 522
 
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
             // Set order of lessons
543 543
             if (version_compare(Sensei()->version, '1.6.0', '>=')) {
544 544
                 $module_id = $query->queried_object_id;
545
-                $query->set('meta_key', '_order_module_' . $module_id);
545
+                $query->set('meta_key', '_order_module_'.$module_id);
546 546
                 $query->set('orderby', 'meta_value_num date');
547 547
             } else {
548 548
                 $query->set('orderby', 'menu_order');
@@ -603,10 +603,10 @@  discard block
 block discarded – undo
603 603
                     $status = __('In progress', 'woothemes-sensei');
604 604
                     $class = 'in-progress';
605 605
                 }
606
-                echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>';
606
+                echo '<p class="status '.esc_attr($class).'">'.$status.'</p>';
607 607
             }
608 608
 
609
-            echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>';
609
+            echo '<p class="archive-description module-description">'.apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id).'</p>';
610 610
         }
611 611
     }
612 612
 
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
     public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
732 732
     {
733 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));
734
+        update_user_meta(intval($user_id), '_module_progress_'.intval($course_id).'_'.intval($module_id), intval($module_progress));
735 735
 
736 736
         do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress);
737 737
     }
@@ -748,9 +748,9 @@  discard block
 block discarded – undo
748 748
      */
749 749
     public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
750 750
     {
751
-        $module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true);
751
+        $module_progress = get_user_meta(intval($user_id), '_module_progress_'.intval($course_id).'_'.intval($module_id), true);
752 752
         if ($module_progress) {
753
-            return (float)$module_progress;
753
+            return (float) $module_progress;
754 754
         }
755 755
         return false;
756 756
     }
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
         }
804 804
         $module_progress = ($completed_count / $lesson_count) * 100;
805 805
 
806
-        return (float)$module_progress;
806
+        return (float) $module_progress;
807 807
     }
808 808
 
809 809
     /**
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
     public function register_modules_admin_menu_items()
817 817
     {
818 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','' );
819
+        add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module', '');
820 820
 
821 821
         // Regsiter new admin page for module ordering
822 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'));
@@ -843,19 +843,19 @@  discard block
 block discarded – undo
843 843
             $ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id']));
844 844
 
845 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";
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 849
             }
850 850
         }
851 851
 
852 852
         $courses = Sensei()->course->get_all_courses();
853 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";
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 859
 
860 860
         foreach ($courses as $course) {
861 861
             if (has_term('', $this->taxonomy, $course->ID)) {
@@ -863,30 +863,30 @@  discard block
 block discarded – undo
863 863
                 if (isset($_GET['course_id'])) {
864 864
                     $course_id = intval($_GET['course_id']);
865 865
                 }
866
-                $html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n";
866
+                $html .= '<option value="'.esc_attr(intval($course->ID)).'" '.selected($course->ID, $course_id, false).'>'.get_the_title($course->ID).'</option>'."\n";
867 867
             }
868 868
         }
869 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";
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 873
 
874 874
         if (isset($_GET['course_id'])) {
875 875
             $course_id = intval($_GET['course_id']);
876 876
             if ($course_id > 0) {
877 877
                 $modules = $this->get_course_modules($course_id);
878
-                $modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() );
878
+                $modules = $this->append_teacher_name_to_module($modules, array('module'), array());
879 879
                 if ($modules) {
880 880
 
881 881
                     $order = $this->get_course_module_order($course_id);
882 882
 
883
-                    $order_string='';
883
+                    $order_string = '';
884 884
                     if ($order) {
885 885
                         $order_string = implode(',', $order);
886 886
                     }
887 887
 
888
-                    $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
889
-                    $html .= '<ul class="sortable-module-list">' . "\n";
888
+                    $html .= '<form id="editgrouping" method="post" action="" class="validate">'."\n";
889
+                    $html .= '<ul class="sortable-module-list">'."\n";
890 890
                     $count = 0;
891 891
                     foreach ($modules as $module) {
892 892
                         $count++;
@@ -900,14 +900,14 @@  discard block
 block discarded – undo
900 900
                         if ($count % 2 != 0) {
901 901
                             $class .= ' alternate';
902 902
                         }
903
-                        $html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n";
903
+                        $html .= '<li class="'.esc_attr($class).'"><span rel="'.esc_attr($module->term_id).'" style="width: 100%;"> '.$module->name.'</span></li>'."\n";
904 904
                     }
905
-                    $html .= '</ul>' . "\n";
905
+                    $html .= '</ul>'."\n";
906 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";
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 911
                 }
912 912
             }
913 913
         }
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
     {
945 945
         if ($column == 'module_order') {
946 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>';
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 948
             }
949 949
         }
950 950
     }
@@ -1036,7 +1036,7 @@  discard block
 block discarded – undo
1036 1036
                 $args['post_type'] = 'lesson';
1037 1037
                 $lessons = get_posts($args);
1038 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>';
1039
+                $column_data = '<a href="'.admin_url('edit.php?module='.urlencode($module->slug).'&post_type=lesson').'">'.intval($total_lessons).'</a>';
1040 1040
                 break;
1041 1041
         }
1042 1042
 
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
     public function analysis_overview_column_title($columns)
1055 1055
     {
1056 1056
 
1057
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1057
+        if (isset($_GET['view']) && 'lessons' == $_GET['view']) {
1058 1058
             $new_columns = array();
1059 1059
             if (is_array($columns) && 0 < count($columns)) {
1060 1060
                 foreach ($columns as $column => $title) {
@@ -1082,15 +1082,15 @@  discard block
 block discarded – undo
1082 1082
      * @param  WP_Post $lesson
1083 1083
      * @return array              Updated column data
1084 1084
      */
1085
-    public function analysis_overview_column_data($columns, $lesson )
1085
+    public function analysis_overview_column_data($columns, $lesson)
1086 1086
     {
1087 1087
 
1088
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1088
+        if (isset($_GET['view']) && 'lessons' == $_GET['view']) {
1089 1089
             $lesson_module = '';
1090 1090
             $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1091 1091
             if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1092 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>';
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 1094
                     break;
1095 1095
                 }
1096 1096
             }
@@ -1111,7 +1111,7 @@  discard block
 block discarded – undo
1111 1111
      */
1112 1112
     public function analysis_course_column_title($columns)
1113 1113
     {
1114
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1114
+        if (isset($_GET['view']) && 'lessons' == $_GET['view']) {
1115 1115
             $columns['lesson_module'] = __('Module', 'woothemes-sensei');
1116 1116
         }
1117 1117
         return $columns;
@@ -1126,15 +1126,15 @@  discard block
 block discarded – undo
1126 1126
      * @param  WP_Post $lesson
1127 1127
      * @return array              Updated columns data
1128 1128
      */
1129
-    public function analysis_course_column_data($columns, $lesson )
1129
+    public function analysis_course_column_data($columns, $lesson)
1130 1130
     {
1131 1131
 
1132
-        if ( isset( $_GET['course_id'] ) ) {
1132
+        if (isset($_GET['course_id'])) {
1133 1133
             $lesson_module = '';
1134 1134
             $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1135 1135
             if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1136 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>';
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 1138
                     break;
1139 1139
                 }
1140 1140
             }
@@ -1161,7 +1161,7 @@  discard block
 block discarded – undo
1161 1161
     public function get_lesson_module($lesson_id = 0)
1162 1162
     {
1163 1163
         $lesson_id = intval($lesson_id);
1164
-        if ( ! ( intval( $lesson_id > 0) ) ) {
1164
+        if ( ! (intval($lesson_id > 0))) {
1165 1165
             return false;
1166 1166
         }
1167 1167
 
@@ -1169,13 +1169,13 @@  discard block
 block discarded – undo
1169 1169
         $modules = wp_get_post_terms($lesson_id, $this->taxonomy);
1170 1170
 
1171 1171
         //check if error returned
1172
-        if( empty( $modules ) || isset( $modules['errors']  ) ){
1172
+        if (empty($modules) || isset($modules['errors'])) {
1173 1173
             return false;
1174 1174
         }
1175 1175
 
1176 1176
        // get the last item in the array there should be only be 1 really.
1177 1177
        // this method works for all php versions.
1178
-       foreach( $modules as $module ){
1178
+       foreach ($modules as $module) {
1179 1179
            break;
1180 1180
        }
1181 1181
 
@@ -1188,7 +1188,7 @@  discard block
 block discarded – undo
1188 1188
         if (isset($course_id) && 0 < $course_id) {
1189 1189
 
1190 1190
             // the course should contain the same module taxonomy term for this to be valid
1191
-            if( ! has_term( $module, $this->taxonomy, $course_id)){
1191
+            if ( ! has_term($module, $this->taxonomy, $course_id)) {
1192 1192
                 return false;
1193 1193
             }
1194 1194
 
@@ -1262,8 +1262,8 @@  discard block
 block discarded – undo
1262 1262
     {
1263 1263
 
1264 1264
 
1265
-        wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1266
-        wp_enqueue_style($this->taxonomy . '-frontend');
1265
+        wp_register_style($this->taxonomy.'-frontend', esc_url($this->assets_url).'css/modules-frontend.css', Sensei()->version);
1266
+        wp_enqueue_style($this->taxonomy.'-frontend');
1267 1267
     }
1268 1268
 
1269 1269
     /**
@@ -1273,37 +1273,37 @@  discard block
 block discarded – undo
1273 1273
      *
1274 1274
      * @return void
1275 1275
      */
1276
-    public function admin_enqueue_scripts( $hook ) {
1276
+    public function admin_enqueue_scripts($hook) {
1277 1277
 
1278 1278
         /**
1279 1279
          * Filter the page hooks where modules admin script can be loaded on.
1280 1280
          *
1281 1281
          * @param array $white_listed_pages
1282 1282
          */
1283
-        $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1283
+        $script_on_pages_white_list = apply_filters('sensei_module_admin_script_page_white_lists', array(
1284 1284
             'edit-tags.php',
1285 1285
             'course_page_module-order',
1286 1286
             'post-new.php',
1287 1287
             'post.php'
1288
-        ) );
1288
+        ));
1289 1289
 
1290
-        if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1290
+        if ( ! in_array($hook, $script_on_pages_white_list)) {
1291 1291
             return;
1292 1292
         }
1293 1293
 
1294
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1294
+        $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
1295 1295
 
1296
-        wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1297
-        wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1298
-        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 );
1296
+        wp_enqueue_script('sensei-chosen', Sensei()->plugin_url.'assets/chosen/chosen.jquery'.$suffix.'.js', array('jquery'), Sensei()->version, true);
1297
+        wp_enqueue_script('sensei-chosen-ajax', Sensei()->plugin_url.'assets/chosen/ajax-chosen.jquery'.$suffix.'.js', array('jquery', 'sensei-chosen'), Sensei()->version, true);
1298
+        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);
1299 1299
 
1300 1300
         // localized module data
1301 1301
         $localize_modulesAdmin = array(
1302
-            'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1303
-            'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1302
+            'search_courses_nonce' => wp_create_nonce('search-courses'),
1303
+            'selectPlaceholder'    => __('Search for courses', 'woothemes-sensei')
1304 1304
         );
1305 1305
 
1306
-        wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1306
+        wp_localize_script($this->taxonomy.'-admin', 'modulesAdmin', $localize_modulesAdmin);
1307 1307
     }
1308 1308
 
1309 1309
     /**
@@ -1316,8 +1316,8 @@  discard block
 block discarded – undo
1316 1316
     public function admin_enqueue_styles() {
1317 1317
 
1318 1318
 
1319
-        wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1320
-        wp_enqueue_style($this->taxonomy . '-sortable');
1319
+        wp_register_style($this->taxonomy.'-sortable', esc_url($this->assets_url).'css/modules-admin.css', '', Sensei()->version);
1320
+        wp_enqueue_style($this->taxonomy.'-sortable');
1321 1321
 
1322 1322
     }
1323 1323
 
@@ -1331,9 +1331,9 @@  discard block
 block discarded – undo
1331 1331
      */
1332 1332
     public function course_modules_title( ) {
1333 1333
 
1334
-       if( sensei_module_has_lessons() ){
1334
+       if (sensei_module_has_lessons()) {
1335 1335
 
1336
-            echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1336
+            echo '<header><h2>'.__('Modules', 'woothemes-sensei').'</h2></header>';
1337 1337
 
1338 1338
         }
1339 1339
 
@@ -1346,18 +1346,18 @@  discard block
 block discarded – undo
1346 1346
      * @since 1.8.0
1347 1347
      * @return void
1348 1348
      */
1349
-    public function load_course_module_content_template(){
1349
+    public function load_course_module_content_template() {
1350 1350
 
1351 1351
         // load backwards compatible template name if it exists in the users theme
1352
-        $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1353
-        if( $located_template ){
1352
+        $located_template = locate_template(Sensei()->template_url.'single-course/course-modules.php');
1353
+        if ($located_template) {
1354 1354
 
1355
-            Sensei_Templates::get_template( 'single-course/course-modules.php' );
1355
+            Sensei_Templates::get_template('single-course/course-modules.php');
1356 1356
             return;
1357 1357
 
1358 1358
         }
1359 1359
 
1360
-        Sensei_Templates::get_template( 'single-course/modules.php' );
1360
+        Sensei_Templates::get_template('single-course/modules.php');
1361 1361
 
1362 1362
     } // end course_module_content
1363 1363
 
@@ -1370,15 +1370,15 @@  discard block
 block discarded – undo
1370 1370
      * @param $term_id
1371 1371
      * @return array $lessons
1372 1372
      */
1373
-    public function get_lessons( $course_id , $term_id ){
1373
+    public function get_lessons($course_id, $term_id) {
1374 1374
 
1375
-        $lesson_query = $this->get_lessons_query( $course_id, $term_id );
1375
+        $lesson_query = $this->get_lessons_query($course_id, $term_id);
1376 1376
 
1377
-        if( isset( $lesson_query->posts ) ){
1377
+        if (isset($lesson_query->posts)) {
1378 1378
 
1379 1379
             return $lesson_query->posts;
1380 1380
 
1381
-        }else{
1381
+        } else {
1382 1382
 
1383 1383
             return array();
1384 1384
 
@@ -1395,9 +1395,9 @@  discard block
 block discarded – undo
1395 1395
      * @param $term_id
1396 1396
      * @return WP_Query $lessons_query
1397 1397
      */
1398
-    public function get_lessons_query( $course_id , $term_id ){
1398
+    public function get_lessons_query($course_id, $term_id) {
1399 1399
 
1400
-        if( empty( $term_id ) || empty( $course_id ) ){
1400
+        if (empty($term_id) || empty($course_id)) {
1401 1401
 
1402 1402
             return array();
1403 1403
 
@@ -1418,7 +1418,7 @@  discard block
 block discarded – undo
1418 1418
                 array(
1419 1419
                     'taxonomy' => 'module',
1420 1420
                     'field' => 'id',
1421
-                    'terms' => intval( $term_id )
1421
+                    'terms' => intval($term_id)
1422 1422
                 )
1423 1423
             ),
1424 1424
             'orderby' => 'menu_order',
@@ -1426,12 +1426,12 @@  discard block
 block discarded – undo
1426 1426
             'suppress_filters' => 0
1427 1427
         );
1428 1428
 
1429
-        if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1430
-            $args['meta_key'] = '_order_module_' . intval( $term_id );
1429
+        if (version_compare(Sensei()->version, '1.6.0', '>=')) {
1430
+            $args['meta_key'] = '_order_module_'.intval($term_id);
1431 1431
             $args['orderby'] = 'meta_value_num date';
1432 1432
         }
1433 1433
 
1434
-        $lessons_query = new WP_Query( $args );
1434
+        $lessons_query = new WP_Query($args);
1435 1435
 
1436 1436
         return $lessons_query;
1437 1437
 
@@ -1446,37 +1446,37 @@  discard block
 block discarded – undo
1446 1446
      *
1447 1447
      * @return array $non_module_lessons
1448 1448
      */
1449
-    public function get_none_module_lessons( $course_id ){
1449
+    public function get_none_module_lessons($course_id) {
1450 1450
 
1451 1451
         $non_module_lessons = array();
1452 1452
 
1453 1453
         //exit if there is no course id passed in
1454
-        if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1454
+        if (empty($course_id) || 'course' != get_post_type($course_id)) {
1455 1455
 
1456 1456
             return $non_module_lessons;
1457 1457
         }
1458 1458
 
1459 1459
         //save some time and check if we already have the saved
1460
-        if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1460
+        if (get_transient('sensei_'.$course_id.'_none_module_lessons')) {
1461 1461
 
1462
-            return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1462
+            return get_transient('sensei_'.$course_id.'_none_module_lessons');
1463 1463
 
1464 1464
         }
1465 1465
 
1466 1466
         // create terms array which must be excluded from other arrays
1467
-        $course_modules = $this->get_course_modules( $course_id );
1467
+        $course_modules = $this->get_course_modules($course_id);
1468 1468
 
1469 1469
         //exit if there are no module on this course
1470
-        if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1470
+        if (empty($course_modules) || ! is_array($course_modules)) {
1471 1471
 
1472
-            return  Sensei()->course->course_lessons( $course_id );
1472
+            return  Sensei()->course->course_lessons($course_id);
1473 1473
 
1474 1474
         }
1475 1475
 
1476 1476
         $terms = array();
1477
-        foreach( $course_modules as $module ){
1477
+        foreach ($course_modules as $module) {
1478 1478
 
1479
-            array_push( $terms ,  $module->term_id );
1479
+            array_push($terms, $module->term_id);
1480 1480
 
1481 1481
         }
1482 1482
 
@@ -1487,7 +1487,7 @@  discard block
 block discarded – undo
1487 1487
             'meta_query' => array(
1488 1488
                 array(
1489 1489
                     'key' => '_lesson_course',
1490
-                    'value' => intval( $course_id ),
1490
+                    'value' => intval($course_id),
1491 1491
                     'compare' => '='
1492 1492
                 )
1493 1493
             ),
@@ -1504,11 +1504,11 @@  discard block
 block discarded – undo
1504 1504
             'suppress_filters' => 0
1505 1505
         );
1506 1506
 
1507
-        $wp_lessons_query = new WP_Query( $args );
1507
+        $wp_lessons_query = new WP_Query($args);
1508 1508
 
1509
-        if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1509
+        if (isset($wp_lessons_query->posts) && count($wp_lessons_query->posts) > 0) {
1510 1510
             $non_module_lessons = $wp_lessons_query->get_posts();
1511
-            set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1511
+            set_transient('sensei_'.$course_id.'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS);
1512 1512
         }
1513 1513
 
1514 1514
         return $non_module_lessons;
@@ -1519,7 +1519,7 @@  discard block
 block discarded – undo
1519 1519
      *
1520 1520
      * @since 1.8.0
1521 1521
      */
1522
-    public function setup_modules_taxonomy(){
1522
+    public function setup_modules_taxonomy() {
1523 1523
 
1524 1524
         $labels = array(
1525 1525
             'name' => __('Modules', 'woothemes-sensei'),
@@ -1556,11 +1556,11 @@  discard block
 block discarded – undo
1556 1556
             'show_in_nav_menus' => false,
1557 1557
             'show_in_quick_edit' => false,
1558 1558
             'show_ui' => true,
1559
-            'rewrite' => array('slug' => $modules_rewrite_slug ),
1559
+            'rewrite' => array('slug' => $modules_rewrite_slug),
1560 1560
             'labels' => $labels
1561 1561
         );
1562 1562
 
1563
-        register_taxonomy( 'module' , array('course', 'lesson'), $args);
1563
+        register_taxonomy('module', array('course', 'lesson'), $args);
1564 1564
 
1565 1565
     }// end setup_modules_taxonomy
1566 1566
 
@@ -1572,12 +1572,12 @@  discard block
 block discarded – undo
1572 1572
      * @since 1.8.0
1573 1573
      * @return void
1574 1574
      */
1575
-    function redirect_to_lesson_module_taxonomy_to_course( ){
1575
+    function redirect_to_lesson_module_taxonomy_to_course( ) {
1576 1576
 
1577
-        global $typenow , $taxnow;
1577
+        global $typenow, $taxnow;
1578 1578
 
1579
-        if( 'lesson'== $typenow && 'module'==$taxnow ){
1580
-            wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1579
+        if ('lesson' == $typenow && 'module' == $taxnow) {
1580
+            wp_safe_redirect(esc_url_raw('edit-tags.php?taxonomy=module&post_type=course'));
1581 1581
         }
1582 1582
 
1583 1583
     }// end redirect to course taxonomy
@@ -1590,18 +1590,18 @@  discard block
 block discarded – undo
1590 1590
      * @since 1.8.0
1591 1591
      * @return void
1592 1592
      */
1593
-    public function remove_lessons_menu_model_taxonomy(){
1593
+    public function remove_lessons_menu_model_taxonomy() {
1594 1594
         global $submenu;
1595 1595
 
1596
-        if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1596
+        if ( ! isset($submenu['edit.php?post_type=lesson']) || ! is_array($submenu['edit.php?post_type=lesson'])) {
1597 1597
             return; // exit
1598 1598
         }
1599 1599
 
1600 1600
         $lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1601
-        foreach( $lesson_main_menu as $index => $sub_item ){
1601
+        foreach ($lesson_main_menu as $index => $sub_item) {
1602 1602
 
1603
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1604
-                unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1603
+            if ('edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2]) {
1604
+                unset($submenu['edit.php?post_type=lesson'][$index]);
1605 1605
             }
1606 1606
         }
1607 1607
 
@@ -1615,18 +1615,18 @@  discard block
 block discarded – undo
1615 1615
      * @since 1.8.0
1616 1616
      * @return void
1617 1617
      */
1618
-    public function remove_courses_menu_model_taxonomy(){
1618
+    public function remove_courses_menu_model_taxonomy() {
1619 1619
         global $submenu;
1620 1620
 
1621
-        if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1621
+        if ( ! isset($submenu['edit.php?post_type=course']) || ! is_array($submenu['edit.php?post_type=course'])) {
1622 1622
             return; // exit
1623 1623
         }
1624 1624
 
1625 1625
         $course_main_menu = $submenu['edit.php?post_type=course'];
1626
-        foreach( $course_main_menu as $index => $sub_item ){
1626
+        foreach ($course_main_menu as $index => $sub_item) {
1627 1627
 
1628
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1629
-                unset( $submenu['edit.php?post_type=course'][ $index ]);
1628
+            if ('edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2]) {
1629
+                unset($submenu['edit.php?post_type=course'][$index]);
1630 1630
             }
1631 1631
         }
1632 1632
 
@@ -1642,12 +1642,12 @@  discard block
 block discarded – undo
1642 1642
      * @param string $term_name
1643 1643
      * @return array $owners { type WP_User }. Empty array if none if found.
1644 1644
      */
1645
-    public static function get_term_authors( $term_name ){
1645
+    public static function get_term_authors($term_name) {
1646 1646
 
1647
-        $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1647
+        $terms = get_terms(array('module'), array('name__like'=>$term_name, 'hide_empty' => false));
1648 1648
 
1649 1649
         $owners = array();
1650
-        if( empty( $terms ) ){
1650
+        if (empty($terms)) {
1651 1651
 
1652 1652
             return $owners;
1653 1653
 
@@ -1657,11 +1657,11 @@  discard block
 block discarded – undo
1657 1657
 
1658 1658
 
1659 1659
         //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1660
-        foreach( $terms as $term){
1661
-            if( $term->name == $term_name ){
1660
+        foreach ($terms as $term) {
1661
+            if ($term->name == $term_name) {
1662 1662
 
1663 1663
                 // look for the author in the slug
1664
-                $owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1664
+                $owners[] = Sensei_Core_Modules::get_term_author($term->slug);
1665 1665
 
1666 1666
             }// end if term name
1667 1667
 
@@ -1682,30 +1682,30 @@  discard block
 block discarded – undo
1682 1682
      * @param $slug
1683 1683
      * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1684 1684
      */
1685
-    public static function get_term_author( $slug='' ){
1685
+    public static function get_term_author($slug = '') {
1686 1686
 
1687
-        $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1687
+        $term_owner = get_user_by('email', get_bloginfo('admin_email'));
1688 1688
 
1689
-        if( empty( $slug ) ){
1689
+        if (empty($slug)) {
1690 1690
 
1691 1691
             return $term_owner;
1692 1692
 
1693 1693
         }
1694 1694
 
1695 1695
         // look for the author in the slug
1696
-        $slug_parts = explode( '-', $slug );
1696
+        $slug_parts = explode('-', $slug);
1697 1697
 
1698
-        if( count( $slug_parts ) > 1 ){
1698
+        if (count($slug_parts) > 1) {
1699 1699
 
1700 1700
             // get the user data
1701 1701
             $possible_user_id = $slug_parts[0];
1702
-            $author = get_userdata( $possible_user_id );
1702
+            $author = get_userdata($possible_user_id);
1703 1703
 
1704 1704
             // if the user doesnt exist for the first part of the slug
1705 1705
             // then this slug was also created by admin
1706
-            if( is_a( $author, 'WP_User' ) ){
1706
+            if (is_a($author, 'WP_User')) {
1707 1707
 
1708
-                $term_owner =  $author;
1708
+                $term_owner = $author;
1709 1709
 
1710 1710
             }
1711 1711
         }
@@ -1722,48 +1722,48 @@  discard block
 block discarded – undo
1722 1722
      *
1723 1723
      * @param WP_Post $post Post object.
1724 1724
      */
1725
-    public function course_module_metabox( $post ) {
1725
+    public function course_module_metabox($post) {
1726 1726
 
1727 1727
         $tax_name = 'module';
1728
-        $taxonomy = get_taxonomy( 'module' );
1728
+        $taxonomy = get_taxonomy('module');
1729 1729
 
1730 1730
         ?>
1731 1731
         <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
1732 1732
             <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs">
1733 1733
                 <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li>
1734
-                <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php _e( 'Most Used' ); ?></a></li>
1734
+                <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php _e('Most Used'); ?></a></li>
1735 1735
             </ul>
1736 1736
 
1737 1737
             <div id="<?php echo $tax_name; ?>-pop" class="tabs-panel" style="display: none;">
1738 1738
                 <ul id="<?php echo $tax_name; ?>checklist-pop" class="categorychecklist form-no-clear" >
1739
-                    <?php $popular_ids = wp_popular_terms_checklist( $tax_name ); ?>
1739
+                    <?php $popular_ids = wp_popular_terms_checklist($tax_name); ?>
1740 1740
                 </ul>
1741 1741
             </div>
1742 1742
 
1743 1743
             <div id="<?php echo $tax_name; ?>-all" class="tabs-panel">
1744 1744
                 <?php
1745
-                $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1745
+                $name = ($tax_name == 'category') ? 'post_category' : 'tax_input['.$tax_name.']';
1746 1746
                 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.
1747 1747
                 ?>
1748 1748
                 <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">
1749
-                    <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?>
1749
+                    <?php wp_terms_checklist($post->ID, array('taxonomy'=>$tax_name, 'popular_cats' => $popular_ids)); ?>
1750 1750
                 </ul>
1751 1751
             </div>
1752
-            <?php if ( current_user_can( $taxonomy->cap->edit_terms ) ) : ?>
1752
+            <?php if (current_user_can($taxonomy->cap->edit_terms)) : ?>
1753 1753
                 <div id="<?php echo $tax_name; ?>-adder" class="wp-hidden-children">
1754 1754
                     <h4>
1755 1755
                         <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js">
1756 1756
                             <?php
1757 1757
                             /* translators: %s: add new taxonomy label */
1758
-                            printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1758
+                            printf(__('+ %s'), $taxonomy->labels->add_new_item);
1759 1759
                             ?>
1760 1760
                         </a>
1761 1761
                     </h4>
1762 1762
                     <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">
1763 1763
                         <label class="screen-reader-text" for="new<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label>
1764
-                        <input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $taxonomy->labels->new_item_name ); ?>" aria-required="true"/>
1765
-                        <a class="button" id="sensei-<?php echo $tax_name; ?>-add-submit" class="button category-add-submit"><?php echo esc_attr( $taxonomy->labels->add_new_item ); ?></a>
1766
-                        <?php wp_nonce_field( '_ajax_nonce-add-' . $tax_name, 'add_module_nonce' ); ?>
1764
+                        <input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr($taxonomy->labels->new_item_name); ?>" aria-required="true"/>
1765
+                        <a class="button" id="sensei-<?php echo $tax_name; ?>-add-submit" class="button category-add-submit"><?php echo esc_attr($taxonomy->labels->add_new_item); ?></a>
1766
+                        <?php wp_nonce_field('_ajax_nonce-add-'.$tax_name, 'add_module_nonce'); ?>
1767 1767
                         <span id="<?php echo $tax_name; ?>-ajax-response"></span>
1768 1768
                     </p>
1769 1769
                 </div>
@@ -1783,55 +1783,55 @@  discard block
 block discarded – undo
1783 1783
     public static function add_new_module_term( ) {
1784 1784
 
1785 1785
 
1786
-        if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1787
-            wp_send_json_error( array('error'=> 'wrong security nonce') );
1786
+        if ( ! isset($_POST['security']) || ! wp_verify_nonce($_POST['security'], '_ajax_nonce-add-module')) {
1787
+            wp_send_json_error(array('error'=> 'wrong security nonce'));
1788 1788
         }
1789 1789
 
1790 1790
         // get the term an create the new term storing infomration
1791
-        $term_name = sanitize_text_field( $_POST['newTerm'] );
1791
+        $term_name = sanitize_text_field($_POST['newTerm']);
1792 1792
 
1793
-        if( current_user_can('manage_options' ) ) {
1793
+        if (current_user_can('manage_options')) {
1794 1794
 
1795
-            $term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1795
+            $term_slug = str_ireplace(' ', '-', trim($term_name));
1796 1796
 
1797 1797
         } else {
1798 1798
 
1799
-            $term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1799
+            $term_slug = get_current_user_id().'-'.str_ireplace(' ', '-', trim($term_name));
1800 1800
 
1801 1801
         }
1802 1802
 
1803
-        $course_id = sanitize_text_field( $_POST['course_id'] );
1803
+        $course_id = sanitize_text_field($_POST['course_id']);
1804 1804
 
1805 1805
         // save the term
1806
-        $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1806
+        $slug = wp_insert_term($term_name, 'module', array('slug'=> $term_slug));
1807 1807
 
1808 1808
         // send error for all errors except term exits
1809
-        if( is_wp_error( $slug ) ){
1809
+        if (is_wp_error($slug)) {
1810 1810
 
1811 1811
             // prepare for possible term name and id to be passed down if term exists
1812 1812
             $term_data = array();
1813 1813
 
1814 1814
             // if term exists also send back the term name and id
1815
-            if( isset( $slug->errors['term_exists'] ) ){
1815
+            if (isset($slug->errors['term_exists'])) {
1816 1816
 
1817
-                $term = get_term_by( 'slug', $term_slug, 'module');
1817
+                $term = get_term_by('slug', $term_slug, 'module');
1818 1818
                 $term_data['name'] = $term_name;
1819 1819
                 $term_data['id'] = $term->term_id;
1820 1820
 
1821 1821
                 // set the object terms
1822
-                wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1822
+                wp_set_object_terms($course_id, $term->term_id, 'module', true);
1823 1823
             }
1824 1824
 
1825
-            wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1825
+            wp_send_json_error(array('errors'=>$slug->errors, 'term'=> $term_data));
1826 1826
 
1827 1827
         }
1828 1828
 
1829 1829
         //make sure the new term is checked for this course
1830 1830
 
1831
-        wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1831
+        wp_set_object_terms($course_id, $slug['term_id'], 'module', true);
1832 1832
 
1833 1833
         // Handle request then generate response using WP_Ajax_Response
1834
-        wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1834
+        wp_send_json_success(array('termId' => $slug['term_id'], 'termName' => $term_name));
1835 1835
 
1836 1836
     }
1837 1837
 
@@ -1843,26 +1843,26 @@  discard block
 block discarded – undo
1843 1843
      *
1844 1844
      * @since 1.8.0
1845 1845
      */
1846
-    public function filter_module_terms( $terms, $taxonomies, $args ){
1846
+    public function filter_module_terms($terms, $taxonomies, $args) {
1847 1847
 
1848 1848
         //dont limit for admins and other taxonomies. This should also only apply to admin
1849
-        if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1849
+        if (current_user_can('manage_options') || ! in_array('module', $taxonomies) || ! is_admin()) {
1850 1850
             return $terms;
1851 1851
         }
1852 1852
 
1853 1853
         // avoid infinite call loop
1854
-        remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1854
+        remove_filter('get_terms', array($this, 'filter_module_terms'), 20, 3);
1855 1855
 
1856 1856
         // in certain cases the array is passed in as reference to the parent term_id => parent_id
1857
-        if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1857
+        if (isset($args['fields']) && 'id=>parent' == $args['fields']) {
1858 1858
             // change only scrub the terms ids form the array keys
1859
-            $terms = array_keys( $terms );
1859
+            $terms = array_keys($terms);
1860 1860
         }
1861 1861
 
1862
-        $teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1862
+        $teachers_terms = $this->filter_terms_by_owner($terms, get_current_user_id());
1863 1863
 
1864 1864
         // add filter again as removed above
1865
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1865
+        add_filter('get_terms', array($this, 'filter_module_terms'), 20, 3);
1866 1866
 
1867 1867
         return $teachers_terms;
1868 1868
     }// end filter_module_terms
@@ -1875,25 +1875,25 @@  discard block
 block discarded – undo
1875 1875
      *
1876 1876
      * @since 1.8.0
1877 1877
      */
1878
-    public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1878
+    public function filter_course_selected_terms($terms, $course_ids_array, $taxonomies) {
1879 1879
 
1880 1880
         //dont limit for admins and other taxonomies. This should also only apply to admin
1881
-        if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1881
+        if (current_user_can('manage_options') || ! is_admin() || empty($terms)
1882 1882
             // only apply this to module only taxonomy queries so 1 taxonomy only:
1883
-            ||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1883
+            ||  count($taxonomies) > 1 || ! in_array('module', $taxonomies)) {
1884 1884
             return $terms;
1885 1885
         }
1886 1886
 
1887
-        $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1887
+        $term_objects = $this->filter_terms_by_owner($terms, get_current_user_id());
1888 1888
 
1889 1889
         // if term objects were passed in send back objects
1890 1890
         // if term id were passed in send that back
1891
-        if( is_object( $terms[0] ) ){
1891
+        if (is_object($terms[0])) {
1892 1892
             return $term_objects;
1893 1893
         }
1894 1894
 
1895 1895
         $terms = array();
1896
-        foreach( $term_objects as $term_object ){
1896
+        foreach ($term_objects as $term_object) {
1897 1897
             $terms[] = $term_object->term_id;
1898 1898
         }
1899 1899
 
@@ -1911,20 +1911,20 @@  discard block
 block discarded – undo
1911 1911
      * @param $user_id
1912 1912
      * @return array
1913 1913
      */
1914
-    public function filter_terms_by_owner( $terms, $user_id ){
1914
+    public function filter_terms_by_owner($terms, $user_id) {
1915 1915
 
1916 1916
         $users_terms = array();
1917 1917
 
1918
-        foreach( $terms as $index => $term ){
1918
+        foreach ($terms as $index => $term) {
1919 1919
 
1920
-            if( is_numeric( $term ) ){
1920
+            if (is_numeric($term)) {
1921 1921
                 // the term id was given, get the term object
1922
-                $term = get_term( $term, 'module' );
1922
+                $term = get_term($term, 'module');
1923 1923
             }
1924 1924
 
1925
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1925
+            $author = Sensei_Core_Modules::get_term_author($term->slug);
1926 1926
 
1927
-            if ( $user_id == $author->ID ) {
1927
+            if ($user_id == $author->ID) {
1928 1928
                 // add the term to the teachers terms
1929 1929
                 $users_terms[] = $term;
1930 1930
             }
@@ -1943,34 +1943,34 @@  discard block
 block discarded – undo
1943 1943
      *
1944 1944
      * @since 1.8.0
1945 1945
      */
1946
-    public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1946
+    public function append_teacher_name_to_module($terms, $taxonomies, $args)
1947 1947
     {
1948 1948
 
1949 1949
         // only for admin users ont he module taxonomy
1950
-        if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1950
+        if (empty($terms) || ! current_user_can('manage_options') || ! in_array('module', $taxonomies) || ! is_admin()) {
1951 1951
             return $terms;
1952 1952
         }
1953 1953
 
1954 1954
         // in certain cases the array is passed in as reference to the parent term_id => parent_id
1955 1955
         // simply return this as wp doesn't need an array of stdObject Term
1956
-        if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1956
+        if (isset($args['fields']) && 'id=>parent' == $args['fields']) {
1957 1957
 
1958 1958
             return $terms;
1959 1959
 
1960 1960
         }
1961 1961
 
1962 1962
         // loop through and update all terms adding the author name
1963
-        foreach( $terms as $index => $term ){
1963
+        foreach ($terms as $index => $term) {
1964 1964
 
1965
-            if( is_numeric( $term ) ){
1965
+            if (is_numeric($term)) {
1966 1966
                 // the term id was given, get the term object
1967
-                $term = get_term( $term, 'module' );
1967
+                $term = get_term($term, 'module');
1968 1968
             }
1969 1969
 
1970
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1970
+            $author = Sensei_Core_Modules::get_term_author($term->slug);
1971 1971
 
1972
-            if( ! user_can( $author, 'manage_options' ) ) {
1973
-                $term->name = $term->name . ' (' . $author->display_name . ') ';
1972
+            if ( ! user_can($author, 'manage_options')) {
1973
+                $term->name = $term->name.' ('.$author->display_name.') ';
1974 1974
             }
1975 1975
 
1976 1976
             // add the term to the teachers terms
@@ -1999,23 +1999,23 @@  discard block
 block discarded – undo
1999 1999
      * @sine 1.9.0
2000 2000
      * @param $post_id
2001 2001
      */
2002
-    public static function reset_none_modules_transient ( $post_id ){
2002
+    public static function reset_none_modules_transient($post_id) {
2003 2003
 
2004 2004
         // this should only apply to course and lesson post types
2005
-        if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2005
+        if (in_array(get_post_type($post_id), array('course', 'lesson'))) {
2006 2006
 
2007 2007
             $course_id = '';
2008 2008
 
2009
-            if( 'lesson' == get_post_type( $post_id ) ){
2009
+            if ('lesson' == get_post_type($post_id)) {
2010 2010
 
2011
-                $course_id = Sensei()->lesson->get_course_id( $post_id );
2011
+                $course_id = Sensei()->lesson->get_course_id($post_id);
2012 2012
 
2013 2013
             }
2014 2014
 
2015 2015
 
2016
-            if( !empty( $course_id ) ){
2016
+            if ( ! empty($course_id)) {
2017 2017
 
2018
-                delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2018
+                delete_transient('sensei_'.$course_id.'_none_module_lessons');
2019 2019
 
2020 2020
             }
2021 2021
 
@@ -2030,9 +2030,9 @@  discard block
 block discarded – undo
2030 2030
      * @deprecated since 1.9.0
2031 2031
      *
2032 2032
      */
2033
-    public static function deprecate_sensei_single_course_modules_content(){
2033
+    public static function deprecate_sensei_single_course_modules_content() {
2034 2034
 
2035
-        sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2035
+        sensei_do_deprecated_action('sensei_single_course_modules_content', '1.9.0', 'sensei_single_course_modules_before or sensei_single_course_modules_after');
2036 2036
 
2037 2037
     }
2038 2038
 
@@ -2043,12 +2043,12 @@  discard block
 block discarded – undo
2043 2043
      *
2044 2044
      * @since 1.9.0
2045 2045
      */
2046
-    public static function setup_single_course_module_loop(){
2046
+    public static function setup_single_course_module_loop() {
2047 2047
 
2048 2048
         global $sensei_modules_loop, $post;
2049 2049
         $course_id = $post->ID;
2050 2050
 
2051
-        $modules = Sensei()->modules->get_course_modules( $course_id );
2051
+        $modules = Sensei()->modules->get_course_modules($course_id);
2052 2052
 
2053 2053
         //initial setup
2054 2054
         $sensei_modules_loop['total'] = 0;
@@ -2056,22 +2056,22 @@  discard block
 block discarded – undo
2056 2056
         $sensei_modules_loop['current'] = -1;
2057 2057
 
2058 2058
         // exit if this course doesn't have modules
2059
-        if( !$modules || empty( $modules )  ){
2059
+        if ( ! $modules || empty($modules)) {
2060 2060
             return;
2061 2061
         }
2062 2062
 
2063 2063
 
2064 2064
         $lessons_in_all_modules = array();
2065
-        foreach( $modules as $term ){
2065
+        foreach ($modules as $term) {
2066 2066
 
2067
-            $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2068
-            $lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2067
+            $lessons_in_this_module = Sensei()->modules->get_lessons($course_id, $term->term_id);
2068
+            $lessons_in_all_modules = array_merge($lessons_in_all_modules, $lessons_in_this_module);
2069 2069
 
2070 2070
         }
2071 2071
 
2072 2072
 
2073 2073
         //setup all of the modules loop variables
2074
-        $sensei_modules_loop['total'] = count( $modules );
2074
+        $sensei_modules_loop['total'] = count($modules);
2075 2075
         $sensei_modules_loop['modules'] = $modules;
2076 2076
         $sensei_modules_loop['current'] = -1;
2077 2077
         $sensei_modules_loop['course_id'] = $course_id;
@@ -2084,7 +2084,7 @@  discard block
 block discarded – undo
2084 2084
      * @since 1.9.0
2085 2085
      *
2086 2086
      */
2087
-    public static function teardown_single_course_module_loop(){
2087
+    public static function teardown_single_course_module_loop() {
2088 2088
 
2089 2089
         global $sensei_modules_loop, $wp_query, $post;
2090 2090
 
Please login to merge, or discard this patch.
Braces   +10 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if ( ! defined( 'ABSPATH' ) ) {
4
+	exit;
5
+}
4 6
 
5 7
 /**
6 8
  * Sensei Modules Class
@@ -401,8 +403,9 @@  discard block
 block discarded – undo
401 403
         $term = urldecode(stripslashes($_GET['term']));
402 404
 
403 405
         // Return nothing if term is empty
404
-        if (empty($term))
405
-            die();
406
+        if (empty($term)) {
407
+                    die();
408
+        }
406 409
 
407 410
         // Set a default if none is given
408 411
         $default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei');
@@ -789,7 +792,9 @@  discard block
 block discarded – undo
789 792
         );
790 793
         $lessons = get_posts($args);
791 794
 
792
-        if (is_wp_error($lessons) || 0 >= count($lessons)) return 0;
795
+        if (is_wp_error($lessons) || 0 >= count($lessons)) {
796
+        	return 0;
797
+        }
793 798
 
794 799
         $completed = false;
795 800
         $lesson_count = 0;
@@ -1378,7 +1383,7 @@  discard block
 block discarded – undo
1378 1383
 
1379 1384
             return $lesson_query->posts;
1380 1385
 
1381
-        }else{
1386
+        } else{
1382 1387
 
1383 1388
             return array();
1384 1389
 
Please login to merge, or discard this patch.
includes/class-sensei-notices.php 4 patches
Doc Comments   -8 removed lines patch added patch discarded remove patch
@@ -33,10 +33,6 @@  discard block
 block discarded – undo
33 33
 	* 
34 34
 	*
35 35
 	* 
36
-	* @param string $message 
37
-	* @param string $type defaults to alert options( alert, tick , download , note   )
38
-	*
39
-	* @return void
40 36
 	*/
41 37
 
42 38
 	public function add_notice( $content ,  $type = 'alert'   ){
@@ -47,10 +43,6 @@  discard block
 block discarded – undo
47 43
 	/**
48 44
 	*  Output all notices added 
49 45
 	* 
50
-	* @param string $message 
51
-	* @param string $type
52
-	*
53
-	* @return void
54 46
 	*/
55 47
 
56 48
 	public function print_notices(){
Please login to merge, or discard this patch.
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -16,28 +16,28 @@  discard block
 block discarded – undo
16 16
 class Sensei_Notices{
17 17
 
18 18
 	/**
19
-	*  @var $notices
20
-	*/
19
+	 *  @var $notices
20
+	 */
21 21
 	protected $notices;
22 22
 
23 23
 	/**
24
-	*  constructor 
25
- 	*/
24
+	 *  constructor 
25
+	 */
26 26
 	public function __construct(){
27 27
 		//initialize the notices variable
28 28
 		$this->notices = array();
29 29
 	}
30 30
 
31 31
 	/**
32
-	*  Add a notice to the array of notices for display at a later stage.
33
-	* 
34
-	*
35
-	* 
36
-	* @param string $message 
37
-	* @param string $type defaults to alert options( alert, tick , download , note   )
38
-	*
39
-	* @return void
40
-	*/
32
+	 *  Add a notice to the array of notices for display at a later stage.
33
+	 * 
34
+	 *
35
+	 * 
36
+	 * @param string $message 
37
+	 * @param string $type defaults to alert options( alert, tick , download , note   )
38
+	 *
39
+	 * @return void
40
+	 */
41 41
 
42 42
 	public function add_notice( $content ,  $type = 'alert'   ){
43 43
 		// append the new notice
@@ -45,13 +45,13 @@  discard block
 block discarded – undo
45 45
 	} // end add_notice()
46 46
 
47 47
 	/**
48
-	*  Output all notices added 
49
-	* 
50
-	* @param string $message 
51
-	* @param string $type
52
-	*
53
-	* @return void
54
-	*/
48
+	 *  Output all notices added 
49
+	 * 
50
+	 * @param string $message 
51
+	 * @param string $type
52
+	 *
53
+	 * @return void
54
+	 */
55 55
 
56 56
 	public function print_notices(){
57 57
 		if(  count( $this->notices ) > 0  ){
@@ -68,10 +68,10 @@  discard block
 block discarded – undo
68 68
 	} // end print_notice()
69 69
 
70 70
 	/**
71
-	*  Clear all notices  
72
-	* 
73
-	* @return void
74
-	*/
71
+	 *  Clear all notices  
72
+	 * 
73
+	 * @return void
74
+	 */
75 75
 
76 76
 	public function clear_notices(){
77 77
 		// assign an empty array to clear all existing notices
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Notices Class
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * @since 1.6.3
14 14
  */
15 15
 
16
-class Sensei_Notices{
16
+class Sensei_Notices {
17 17
 
18 18
 	/**
19 19
 	*  @var $notices
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	/**
24 24
 	*  constructor 
25 25
  	*/
26
-	public function __construct(){
26
+	public function __construct() {
27 27
 		//initialize the notices variable
28 28
 		$this->notices = array();
29 29
 	}
@@ -39,9 +39,9 @@  discard block
 block discarded – undo
39 39
 	* @return void
40 40
 	*/
41 41
 
42
-	public function add_notice( $content ,  $type = 'alert'   ){
42
+	public function add_notice($content, $type = 'alert') {
43 43
 		// append the new notice
44
-		$this->notices[] = array('content' => $content , 'type'=> $type );
44
+		$this->notices[] = array('content' => $content, 'type'=> $type);
45 45
 	} // end add_notice()
46 46
 
47 47
 	/**
@@ -53,12 +53,12 @@  discard block
 block discarded – undo
53 53
 	* @return void
54 54
 	*/
55 55
 
56
-	public function print_notices(){
57
-		if(  count( $this->notices ) > 0  ){
56
+	public function print_notices() {
57
+		if (count($this->notices) > 0) {
58 58
 			foreach ($this->notices  as  $notice) {
59 59
 
60
-				$classes = 'sensei-message '. $notice['type'];
61
-				$html = '<div class="'. $classes . '">'. $notice['content'] . '</div>';
60
+				$classes = 'sensei-message '.$notice['type'];
61
+				$html = '<div class="'.$classes.'">'.$notice['content'].'</div>';
62 62
 
63 63
 				echo $html; 
64 64
 			}
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	* @return void
74 74
 	*/
75 75
 
76
-	public function clear_notices(){
76
+	public function clear_notices() {
77 77
 		// assign an empty array to clear all existing notices
78 78
 		$this->notices = array();
79 79
 	} // end clear_notices()
@@ -85,4 +85,4 @@  discard block
 block discarded – undo
85 85
  * for backward compatibility
86 86
  * @since 1.9.0
87 87
  */
88
-class Woothemes_Sensei_Notices extends Sensei_Notices{}
88
+class Woothemes_Sensei_Notices extends Sensei_Notices {}
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Analysis User Profile List Table Class
Please login to merge, or discard this patch.
includes/class-sensei-question.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
      * This function simply loads the question type template
403 403
      *
404 404
      * @since 1.9.0
405
-     * @param $question_type
405
+     * @param string $question_type
406 406
      */
407 407
     public static function load_question_template( $question_type ){
408 408
 
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
      * Get the questions media markup
488 488
      *
489 489
      * @since 1.9.0
490
-     * @param $question_id
490
+     * @param string $question_id
491 491
      * @return string
492 492
      */
493 493
     public static function get_the_question_media( $question_id ){
Please login to merge, or discard this patch.
Indentation   +566 added lines, -566 removed lines patch added patch discarded remove patch
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 
118 118
 			if( isset( $post->ID ) ) {
119 119
 
120
-                $question_type = Sensei()->question->get_question_type( $post->ID );
120
+				$question_type = Sensei()->question->get_question_type( $post->ID );
121 121
 
122 122
 				if( $question_type ) {
123 123
 					$type = $this->question_types[ $question_type ];
@@ -237,15 +237,15 @@  discard block
 block discarded – undo
237 237
 	public function save_question( $post_id = 0 ) {
238 238
 
239 239
 		if( ! isset( $_POST['post_type']
240
-            ) || 'question' != $_POST['post_type'] ) {
241
-            return;
242
-        }
240
+			) || 'question' != $_POST['post_type'] ) {
241
+			return;
242
+		}
243 243
 
244 244
 
245 245
 
246
-        //setup the data for saving
246
+		//setup the data for saving
247 247
 		$data = $_POST ;
248
-        $data['quiz_id'] = 0;
248
+		$data['quiz_id'] = 0;
249 249
 		$data['question_id'] = $post_id;
250 250
 
251 251
 		if ( ! wp_is_post_revision( $post_id ) ){
@@ -339,34 +339,34 @@  discard block
 block discarded – undo
339 339
 		return $request;
340 340
 	}
341 341
 
342
-    /**
343
-     * Get the type of question by id
344
-     *
345
-     * This function uses the post terms to determine which question type
346
-     * the passed question id belongs to.
347
-     *
348
-     * @since 1.7.4
349
-     *
350
-     * @param int $question_id
351
-     *
352
-     * @return string $question_type | bool
353
-     */
354
-    public function get_question_type( $question_id ){
355
-
356
-        if( empty( $question_id ) || ! intval( $question_id ) > 0
357
-            || 'question' != get_post_type( $question_id )   ){
358
-            return false;
359
-        }
360
-
361
-        $question_type = 'multiple-choice';
362
-        $question_types = wp_get_post_terms( $question_id, 'question-type' );
363
-        foreach( $question_types as $type ) {
364
-            $question_type = $type->slug;
365
-        }
366
-
367
-        return $question_type;
368
-
369
-    }// end get_question_type
342
+	/**
343
+	 * Get the type of question by id
344
+	 *
345
+	 * This function uses the post terms to determine which question type
346
+	 * the passed question id belongs to.
347
+	 *
348
+	 * @since 1.7.4
349
+	 *
350
+	 * @param int $question_id
351
+	 *
352
+	 * @return string $question_type | bool
353
+	 */
354
+	public function get_question_type( $question_id ){
355
+
356
+		if( empty( $question_id ) || ! intval( $question_id ) > 0
357
+			|| 'question' != get_post_type( $question_id )   ){
358
+			return false;
359
+		}
360
+
361
+		$question_type = 'multiple-choice';
362
+		$question_types = wp_get_post_terms( $question_id, 'question-type' );
363
+		foreach( $question_types as $type ) {
364
+			$question_type = $type->slug;
365
+		}
366
+
367
+		return $question_type;
368
+
369
+	}// end get_question_type
370 370
 
371 371
 	/**
372 372
 	 * Given a question ID, return the grade that can be achieved.
@@ -398,317 +398,317 @@  discard block
 block discarded – undo
398 398
 	} // end get_question_grade
399 399
 
400 400
 
401
-    /**
402
-     * This function simply loads the question type template
403
-     *
404
-     * @since 1.9.0
405
-     * @param $question_type
406
-     */
407
-    public static function load_question_template( $question_type ){
408
-
409
-        Sensei_Templates::get_template  ( 'single-quiz/question_type-' . $question_type . '.php' );
410
-    }
411
-
412
-    /**
413
-     * Echo the sensei question title.
414
-     *
415
-     * @uses WooThemes_Sensei_Question::get_the_question_title
416
-     *
417
-     * @since 1.9.0
418
-     * @param $question_id
419
-     */
420
-    public static function the_question_title( $question_id ){
421
-
422
-        echo self::get_the_question_title( $question_id );
423
-
424
-    }// end the_question_title
425
-
426
-    /**
427
-     * Generate the question title with it's grade.
428
-     *
429
-     * @since 1.9.0
430
-     *
431
-     * @param $question_id
432
-     * @return string
433
-     */
434
-    public static function get_the_question_title( $question_id ){
435
-
436
-        /**
437
-         * Filter the sensei question title
438
-         *
439
-         * @since 1.3.0
440
-         * @param $question_title
441
-         */
442
-        $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) );
443
-
444
-        /**
445
-         * hook document in class-woothemes-sensei-message.php the_title()
446
-         */
447
-        $title = apply_filters( 'sensei_single_title', $title, 'question');
448
-
449
-        $title_html  = '<span class="question question-title">';
450
-        $title_html .= $title;
451
-        $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>';
452
-        $title_html .='</span>';
453
-
454
-        return $title_html;
455
-    }
456
-
457
-    /**
458
-     * Tech the question description
459
-     *
460
-     * @param $question_id
461
-     * @return string
462
-     */
463
-    public static function get_the_question_description( $question_id ){
464
-
465
-        $question = get_post( $question_id );
466
-
467
-        /**
468
-         * Already documented within WordPress Core
469
-         */
470
-        return apply_filters( 'the_content', $question->post_content );
471
-
472
-    }
473
-
474
-    /**
475
-     * Output the question description
476
-     *
477
-     * @since 1.9.0
478
-     * @param $question_id
479
-     */
480
-    public static function the_question_description( $question_id  ){
481
-
482
-        echo self::get_the_question_description( $question_id );
483
-
484
-    }
485
-
486
-    /**
487
-     * Get the questions media markup
488
-     *
489
-     * @since 1.9.0
490
-     * @param $question_id
491
-     * @return string
492
-     */
493
-    public static function get_the_question_media( $question_id ){
494
-
495
-        $question_media = get_post_meta( $question_id, '_question_media', true );
496
-        $question_media_link = '';
497
-        if( 0 < intval( $question_media ) ) {
498
-            $mimetype = get_post_mime_type( $question_media );
499
-            if( $mimetype ) {
500
-                $mimetype_array = explode( '/', $mimetype);
501
-                if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) {
502
-                    $question_media_type = $mimetype_array[0];
503
-                    $question_media_url = wp_get_attachment_url( $question_media );
504
-                    $attachment = get_post( $question_media );
505
-                    $question_media_title = $attachment->post_title;
506
-                    $question_media_description = $attachment->post_content;
507
-                    switch( $question_media_type ) {
508
-                        case 'image':
509
-                            $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id );
510
-                            $attachment_src = wp_get_attachment_image_src( $question_media, $image_size );
511
-                            $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>';
512
-                            break;
513
-
514
-                        case 'audio':
515
-                            $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) );
516
-                            break;
517
-
518
-                        case 'video':
519
-                            $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) );
520
-                            break;
521
-
522
-                        default:
523
-                            $question_media_filename = basename( $question_media_url );
524
-                            $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>';
525
-                            break;
526
-                    }
527
-                }
528
-            }
529
-        }
530
-
531
-        $output = '';
532
-        if( $question_media_link ) {
533
-
534
-                $output .= '<div class="question_media_display">';
535
-                $output .=      $question_media_link;
536
-                $output .= '<dl>';
537
-
538
-                if( $question_media_title ) {
539
-
540
-                   $output .= '<dt>'. $question_media_title. '</dt>';
541
-
542
-                 }
543
-
544
-                if( $question_media_description ) {
545
-
546
-                    $output .= '<dd>' . $question_media_description . '</dd>';
547
-
548
-                }
549
-
550
-                $output .= '</dl>';
551
-                $output .= '</div>';
401
+	/**
402
+	 * This function simply loads the question type template
403
+	 *
404
+	 * @since 1.9.0
405
+	 * @param $question_type
406
+	 */
407
+	public static function load_question_template( $question_type ){
408
+
409
+		Sensei_Templates::get_template  ( 'single-quiz/question_type-' . $question_type . '.php' );
410
+	}
411
+
412
+	/**
413
+	 * Echo the sensei question title.
414
+	 *
415
+	 * @uses WooThemes_Sensei_Question::get_the_question_title
416
+	 *
417
+	 * @since 1.9.0
418
+	 * @param $question_id
419
+	 */
420
+	public static function the_question_title( $question_id ){
421
+
422
+		echo self::get_the_question_title( $question_id );
423
+
424
+	}// end the_question_title
425
+
426
+	/**
427
+	 * Generate the question title with it's grade.
428
+	 *
429
+	 * @since 1.9.0
430
+	 *
431
+	 * @param $question_id
432
+	 * @return string
433
+	 */
434
+	public static function get_the_question_title( $question_id ){
435
+
436
+		/**
437
+		 * Filter the sensei question title
438
+		 *
439
+		 * @since 1.3.0
440
+		 * @param $question_title
441
+		 */
442
+		$title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) );
443
+
444
+		/**
445
+		 * hook document in class-woothemes-sensei-message.php the_title()
446
+		 */
447
+		$title = apply_filters( 'sensei_single_title', $title, 'question');
448
+
449
+		$title_html  = '<span class="question question-title">';
450
+		$title_html .= $title;
451
+		$title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>';
452
+		$title_html .='</span>';
453
+
454
+		return $title_html;
455
+	}
456
+
457
+	/**
458
+	 * Tech the question description
459
+	 *
460
+	 * @param $question_id
461
+	 * @return string
462
+	 */
463
+	public static function get_the_question_description( $question_id ){
464
+
465
+		$question = get_post( $question_id );
466
+
467
+		/**
468
+		 * Already documented within WordPress Core
469
+		 */
470
+		return apply_filters( 'the_content', $question->post_content );
471
+
472
+	}
473
+
474
+	/**
475
+	 * Output the question description
476
+	 *
477
+	 * @since 1.9.0
478
+	 * @param $question_id
479
+	 */
480
+	public static function the_question_description( $question_id  ){
481
+
482
+		echo self::get_the_question_description( $question_id );
483
+
484
+	}
485
+
486
+	/**
487
+	 * Get the questions media markup
488
+	 *
489
+	 * @since 1.9.0
490
+	 * @param $question_id
491
+	 * @return string
492
+	 */
493
+	public static function get_the_question_media( $question_id ){
494
+
495
+		$question_media = get_post_meta( $question_id, '_question_media', true );
496
+		$question_media_link = '';
497
+		if( 0 < intval( $question_media ) ) {
498
+			$mimetype = get_post_mime_type( $question_media );
499
+			if( $mimetype ) {
500
+				$mimetype_array = explode( '/', $mimetype);
501
+				if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) {
502
+					$question_media_type = $mimetype_array[0];
503
+					$question_media_url = wp_get_attachment_url( $question_media );
504
+					$attachment = get_post( $question_media );
505
+					$question_media_title = $attachment->post_title;
506
+					$question_media_description = $attachment->post_content;
507
+					switch( $question_media_type ) {
508
+						case 'image':
509
+							$image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id );
510
+							$attachment_src = wp_get_attachment_image_src( $question_media, $image_size );
511
+							$question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>';
512
+							break;
513
+
514
+						case 'audio':
515
+							$question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) );
516
+							break;
517
+
518
+						case 'video':
519
+							$question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) );
520
+							break;
521
+
522
+						default:
523
+							$question_media_filename = basename( $question_media_url );
524
+							$question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>';
525
+							break;
526
+					}
527
+				}
528
+			}
529
+		}
530
+
531
+		$output = '';
532
+		if( $question_media_link ) {
552 533
 
534
+				$output .= '<div class="question_media_display">';
535
+				$output .=      $question_media_link;
536
+				$output .= '<dl>';
553 537
 
554
-         }
555
-
556
-        return $output;
557
-
558
-    } // end get_the_question_media
559
-
538
+				if( $question_media_title ) {
560 539
 
561
-    /**
562
-     * Output the question media
563
-     *
564
-     * @since 1.9.0
565
-     * @param string $question_id
566
-     */
567
-    public static function the_question_media( $question_id ){
540
+				   $output .= '<dt>'. $question_media_title. '</dt>';
568 541
 
569
-        echo self::get_the_question_media( $question_id );
542
+				 }
570 543
 
571
-    }
544
+				if( $question_media_description ) {
572 545
 
573
-    /**
574
-     * Output a special field for the question needed for question submission.
575
-     *
576
-     * @since 1.9.0
577
-     *
578
-     * @param $question_id
579
-     */
580
-    public static function the_question_hidden_fields( $question_id ){
581
-        ?>
546
+					$output .= '<dd>' . $question_media_description . '</dd>';
547
+
548
+				}
549
+
550
+				$output .= '</dl>';
551
+				$output .= '</div>';
552
+
553
+
554
+		 }
555
+
556
+		return $output;
557
+
558
+	} // end get_the_question_media
559
+
560
+
561
+	/**
562
+	 * Output the question media
563
+	 *
564
+	 * @since 1.9.0
565
+	 * @param string $question_id
566
+	 */
567
+	public static function the_question_media( $question_id ){
568
+
569
+		echo self::get_the_question_media( $question_id );
570
+
571
+	}
572
+
573
+	/**
574
+	 * Output a special field for the question needed for question submission.
575
+	 *
576
+	 * @since 1.9.0
577
+	 *
578
+	 * @param $question_id
579
+	 */
580
+	public static function the_question_hidden_fields( $question_id ){
581
+		?>
582 582
 
583 583
             <input type="hidden" name="question_id_<?php $question_id;?>" value="<?php $question_id;?>" />
584 584
             <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e( $question_id ); ?>" />
585 585
 
586 586
         <?php
587
-    }
587
+	}
588 588
 
589
-    /**
590
-     * This function can only be run withing the single quiz question loop
591
-     *
592
-     * @since 1.9.0
593
-     * @param $question_id
594
-     */
595
-    public static function answer_feedback_notes( $question_id ){
589
+	/**
590
+	 * This function can only be run withing the single quiz question loop
591
+	 *
592
+	 * @since 1.9.0
593
+	 * @param $question_id
594
+	 */
595
+	public static function answer_feedback_notes( $question_id ){
596 596
 
597
-        //IDS
598
-        $quiz_id = get_the_ID();
599
-        $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
597
+		//IDS
598
+		$quiz_id = get_the_ID();
599
+		$lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
600 600
 
601
-        // Data to check before showing feedback
602
-        $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() );
603
-        $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
604
-        $not_empty_user_quiz_grade = !empty( $user_quiz_grade );
605
-        $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id );
606
-        $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id );
607
-        $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true );
601
+		// Data to check before showing feedback
602
+		$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() );
603
+		$user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
604
+		$not_empty_user_quiz_grade = !empty( $user_quiz_grade );
605
+		$reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id );
606
+		$lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id );
607
+		$quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true );
608 608
 
609
-        if( ( $lesson_completed  && $not_empty_user_quiz_grade  )
610
-            ||  ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type )
611
-            || ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) {
609
+		if( ( $lesson_completed  && $not_empty_user_quiz_grade  )
610
+			||  ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type )
611
+			|| ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) {
612 612
 
613
-            $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() );
613
+			$answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() );
614 614
 
615
-            if( $answer_notes ) { ?>
615
+			if( $answer_notes ) { ?>
616 616
 
617 617
                 <div class="sensei-message info info-special answer-feedback">
618 618
 
619 619
                     <?php
620 620
 
621
-                        /**
622
-                         * Filter the answer feedback
623
-                         * Since 1.9.0
624
-                         *
625
-                         * @param string $answer_notes
626
-                         * @param string $question_id
627
-                         * @param string $lesson_id
628
-                         */
629
-                        echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id );
621
+						/**
622
+						 * Filter the answer feedback
623
+						 * Since 1.9.0
624
+						 *
625
+						 * @param string $answer_notes
626
+						 * @param string $question_id
627
+						 * @param string $lesson_id
628
+						 */
629
+						echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id );
630 630
 
631
-                    ?>
631
+					?>
632 632
 
633 633
                 </div>
634 634
 
635 635
             <?php }
636 636
 
637
-        }// end if we can show answer feedback
637
+		}// end if we can show answer feedback
638 638
 
639
-    }// end answer_feedback_notes
639
+	}// end answer_feedback_notes
640 640
 
641
-    /**
642
-     * This function has to be run inside the quiz question loop on the single quiz page.
643
-     *
644
-     *
645
-     * @since 1.9.0
646
-     * @param string $question_id
647
-     */
648
-    public static function the_answer_result_indication( $question_id ){
641
+	/**
642
+	 * This function has to be run inside the quiz question loop on the single quiz page.
643
+	 *
644
+	 *
645
+	 * @since 1.9.0
646
+	 * @param string $question_id
647
+	 */
648
+	public static function the_answer_result_indication( $question_id ){
649 649
 
650
-        global $post,  $current_user, $sensei_question_loop;
650
+		global $post,  $current_user, $sensei_question_loop;
651 651
 
652
-        // Post Data
653
-        $quiz_id = $sensei_question_loop['quiz_id'];
654
-        $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
655
-        $question_item = $sensei_question_loop['current_question'];
652
+		// Post Data
653
+		$quiz_id = $sensei_question_loop['quiz_id'];
654
+		$lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
655
+		$question_item = $sensei_question_loop['current_question'];
656 656
 
657
-        // Setup variable needed to determine if the message should show and what it should show
658
-        $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
659
-        $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() );
660
-        $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id );
661
-        $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true );
657
+		// Setup variable needed to determine if the message should show and what it should show
658
+		$user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
659
+		$lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() );
660
+		$reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id );
661
+		$quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true );
662 662
 
663
-        // retrieve the question total grade
664
-        $question_grade = Sensei()->question->get_question_grade( $question_id );
663
+		// retrieve the question total grade
664
+		$question_grade = Sensei()->question->get_question_grade( $question_id );
665 665
 
666
-        // retrieve grade the user achieved
667
-        $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() );
666
+		// retrieve grade the user achieved
667
+		$user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() );
668 668
 
669
-        // Question ID
670
-        $question_id = $question_item->ID;
669
+		// Question ID
670
+		$question_id = $question_item->ID;
671 671
 
672
-        // conditions to check
673
-        $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ;
674
-        $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete &&  $user_quiz_grade != '' && ! $reset_quiz_allowed ;
675
-        $grade_type_auto_a_valid_grade_and_reset_not_allowed =  'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ;
672
+		// conditions to check
673
+		$completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ;
674
+		$completed_with_valid_grade_and_reset_not_allowed = $lesson_complete &&  $user_quiz_grade != '' && ! $reset_quiz_allowed ;
675
+		$grade_type_auto_a_valid_grade_and_reset_not_allowed =  'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ;
676 676
 
677
-        if (  $completed_with_valid_grade
678
-            || $completed_with_valid_grade_and_reset_not_allowed
679
-            || $grade_type_auto_a_valid_grade_and_reset_not_allowed  ) {
677
+		if (  $completed_with_valid_grade
678
+			|| $completed_with_valid_grade_and_reset_not_allowed
679
+			|| $grade_type_auto_a_valid_grade_and_reset_not_allowed  ) {
680 680
 
681
-            $user_correct = false;
682
-            $answer_message = __( 'Incorrect', 'woothemes-sensei' );
683
-            $answer_message_class = 'user_wrong';
684
-            // For zero grade mark as 'correct' but add no classes
685
-            if ( 0 == $question_grade ) {
681
+			$user_correct = false;
682
+			$answer_message = __( 'Incorrect', 'woothemes-sensei' );
683
+			$answer_message_class = 'user_wrong';
684
+			// For zero grade mark as 'correct' but add no classes
685
+			if ( 0 == $question_grade ) {
686 686
 
687
-                $user_correct = true;
688
-                $answer_message = '';
689
-                $answer_message_class = '';
687
+				$user_correct = true;
688
+				$answer_message = '';
689
+				$answer_message_class = '';
690 690
 
691
-            } else if( $user_question_grade > 0 ) {
691
+			} else if( $user_question_grade > 0 ) {
692 692
 
693
-                $user_correct = true;
694
-                $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade );
695
-                $answer_message_class = 'user_right';
693
+				$user_correct = true;
694
+				$answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade );
695
+				$answer_message_class = 'user_right';
696 696
 
697
-            }
697
+			}
698 698
 
699
-            // attach the correct answer if the question is auto gradable and user got it wrong
700
-            if( !$reset_quiz_allowed && !$user_correct ){
699
+			// attach the correct answer if the question is auto gradable and user got it wrong
700
+			if( !$reset_quiz_allowed && !$user_correct ){
701 701
 
702
-                $answer_message .=  ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID );
702
+				$answer_message .=  ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID );
703 703
 
704
-            }
704
+			}
705 705
 
706
-            // answer feedback
707
-            $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID );
708
-            if( $answer_notes ) {
709
-                $answer_message_class .= ' has_notes';
710
-            }
711
-            ?>
706
+			// answer feedback
707
+			$answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID );
708
+			if( $answer_notes ) {
709
+				$answer_message_class .= ' has_notes';
710
+			}
711
+			?>
712 712
 
713 713
             <div class="answer_message <?php esc_attr_e( $answer_message_class ); ?>">
714 714
 
@@ -718,387 +718,387 @@  discard block
 block discarded – undo
718 718
 
719 719
             <?php
720 720
 
721
-        } // end if user can see all the goodies
722
-
723
-    }// end the_answer_result_indication
724
-
725
-    /**
726
-     * Generate the question template data and return it as an array.
727
-     *
728
-     * @since 1.9.0
729
-     *
730
-     * @param string $question_id
731
-     * @param $quiz_id
732
-     * @return array $question_data
733
-     */
734
-    public static function get_template_data( $question_id, $quiz_id ){
735
-
736
-        $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id  );
737
-
738
-        $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true );
739
-        //backwards compatibility
740
-        if( 'on' == $reset_allowed ) {
741
-            $reset_allowed = 1;
742
-        }
743
-
744
-        // Check again that the lesson is complete
745
-        $user_lesson_end = WooThemes_Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() );
746
-        $user_lesson_complete = false;
747
-        if ( $user_lesson_end ) {
748
-            $user_lesson_complete = true;
749
-        }
750
-
751
-        //setup the question data
752
-        $data[ 'ID' ]                     = $question_id;
753
-        $data[ 'title' ]                  = get_the_title( $question_id );
754
-        $data[ 'content' ]                = get_post( $question_id )->post_content;
755
-        $data[ 'quiz_id' ]                = $quiz_id;
756
-        $data[ 'lesson_id' ]              = Sensei()->quiz->get_lesson_id( $quiz_id );
757
-        $data[ 'type' ]                   = Sensei()->question->get_question_type( $question_id );
758
-        $data[ 'question_grade' ]         = Sensei()->question->get_question_grade(  $question_id  );
759
-        $data[ 'user_question_grade' ]    = Sensei()->quiz->get_user_question_grade( $lesson_id,  $question_id , get_current_user_id());
760
-        $data[ 'question_right_answer' ]  = get_post_meta( $question_id , '_question_right_answer', true );
761
-        $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true );
762
-        $data[ 'user_answer_entry' ]      = Sensei()->quiz->get_user_question_answer( $lesson_id,  $question_id , get_current_user_id() );
763
-        $data[ 'lesson_completed' ]       = WooThemes_Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) );
764
-        $data[ 'quiz_grade_type' ]        = get_post_meta( $quiz_id , '_quiz_grade_type', true );
765
-        $data[ 'reset_quiz_allowed' ]     = $reset_allowed;
766
-        $data[ 'lesson_complete' ]        = $user_lesson_complete;
767
-
768
-        /**
769
-         * Filter the question template data. This filter fires  in
770
-         * the get_template_data function
771
-         *
772
-         * @hooked self::boolean_load_question_data
773
-         *
774
-         * @since 1.9.0
775
-         *
776
-         * @param array $data
777
-         * @param string $question_id
778
-         * @param string $quiz_id
779
-         */
780
-        return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id );
721
+		} // end if user can see all the goodies
781 722
 
782
-    }
723
+	}// end the_answer_result_indication
783 724
 
784
-    /**
785
-     * Load multiple choice question data on the sensei_get_question_template_data
786
-     * filter.
787
-     *
788
-     * @since 1.9.0
789
-     *
790
-     * @param $question_data
791
-     * @param $question_id
792
-     * @param $quiz_id
793
-     *
794
-     * @return array()
795
-     */
796
-    public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){
725
+	/**
726
+	 * Generate the question template data and return it as an array.
727
+	 *
728
+	 * @since 1.9.0
729
+	 *
730
+	 * @param string $question_id
731
+	 * @param $quiz_id
732
+	 * @return array $question_data
733
+	 */
734
+	public static function get_template_data( $question_id, $quiz_id ){
797 735
 
736
+		$lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id  );
798 737
 
799
-        if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) {
738
+		$reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true );
739
+		//backwards compatibility
740
+		if( 'on' == $reset_allowed ) {
741
+			$reset_allowed = 1;
742
+		}
800 743
 
801
-            // Get uploaded file
802
-            $attachment_id = $question_data[ 'user_answer_entry' ];
803
-            $answer_media_url = $answer_media_filename = '';
744
+		// Check again that the lesson is complete
745
+		$user_lesson_end = WooThemes_Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() );
746
+		$user_lesson_complete = false;
747
+		if ( $user_lesson_end ) {
748
+			$user_lesson_complete = true;
749
+		}
804 750
 
751
+		//setup the question data
752
+		$data[ 'ID' ]                     = $question_id;
753
+		$data[ 'title' ]                  = get_the_title( $question_id );
754
+		$data[ 'content' ]                = get_post( $question_id )->post_content;
755
+		$data[ 'quiz_id' ]                = $quiz_id;
756
+		$data[ 'lesson_id' ]              = Sensei()->quiz->get_lesson_id( $quiz_id );
757
+		$data[ 'type' ]                   = Sensei()->question->get_question_type( $question_id );
758
+		$data[ 'question_grade' ]         = Sensei()->question->get_question_grade(  $question_id  );
759
+		$data[ 'user_question_grade' ]    = Sensei()->quiz->get_user_question_grade( $lesson_id,  $question_id , get_current_user_id());
760
+		$data[ 'question_right_answer' ]  = get_post_meta( $question_id , '_question_right_answer', true );
761
+		$data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true );
762
+		$data[ 'user_answer_entry' ]      = Sensei()->quiz->get_user_question_answer( $lesson_id,  $question_id , get_current_user_id() );
763
+		$data[ 'lesson_completed' ]       = WooThemes_Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) );
764
+		$data[ 'quiz_grade_type' ]        = get_post_meta( $quiz_id , '_quiz_grade_type', true );
765
+		$data[ 'reset_quiz_allowed' ]     = $reset_allowed;
766
+		$data[ 'lesson_complete' ]        = $user_lesson_complete;
767
+
768
+		/**
769
+		 * Filter the question template data. This filter fires  in
770
+		 * the get_template_data function
771
+		 *
772
+		 * @hooked self::boolean_load_question_data
773
+		 *
774
+		 * @since 1.9.0
775
+		 *
776
+		 * @param array $data
777
+		 * @param string $question_id
778
+		 * @param string $quiz_id
779
+		 */
780
+		return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id );
805 781
 
806
-            $question_helptext = '';
807
-            if( isset( $question_data['question_wrong_answers'][0] ) ) {
782
+	}
808 783
 
809
-                $question_helptext =  $question_data['question_wrong_answers'][0];
784
+	/**
785
+	 * Load multiple choice question data on the sensei_get_question_template_data
786
+	 * filter.
787
+	 *
788
+	 * @since 1.9.0
789
+	 *
790
+	 * @param $question_data
791
+	 * @param $question_id
792
+	 * @param $quiz_id
793
+	 *
794
+	 * @return array()
795
+	 */
796
+	public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){
810 797
 
811
-            }
812 798
 
799
+		if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) {
813 800
 
814
-            if( 0 < intval( $attachment_id ) ) {
801
+			// Get uploaded file
802
+			$attachment_id = $question_data[ 'user_answer_entry' ];
803
+			$answer_media_url = $answer_media_filename = '';
815 804
 
816
-                $answer_media_url = wp_get_attachment_url( $attachment_id );
817
-                $answer_media_filename = basename( $answer_media_url );
818 805
 
819
-            }
806
+			$question_helptext = '';
807
+			if( isset( $question_data['question_wrong_answers'][0] ) ) {
820 808
 
809
+				$question_helptext =  $question_data['question_wrong_answers'][0];
821 810
 
822
-            // Get max upload file size, formatted for display
823
-            // Code copied from wp-admin/includes/media.php:1515
824
-            $upload_size_unit = $max_upload_size = wp_max_upload_size();
825
-            $sizes = array( 'KB', 'MB', 'GB' );
826
-            for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) {
827
-                $upload_size_unit /= 1024;
828
-            }
829
-            if ( $u < 0 ) {
811
+			}
830 812
 
831
-                $upload_size_unit = 0;
832
-                $u = 0;
833 813
 
834
-            } else {
814
+			if( 0 < intval( $attachment_id ) ) {
835 815
 
836
-                $upload_size_unit = (int) $upload_size_unit;
816
+				$answer_media_url = wp_get_attachment_url( $attachment_id );
817
+				$answer_media_filename = basename( $answer_media_url );
837 818
 
838
-            }
839
-            $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) );
819
+			}
840 820
 
841
-            // Assemble all the data needed by the file upload template
842
-            $question_data[ 'answer_media_url' ]      = $answer_media_url;
843
-            $question_data[ 'answer_media_filename' ] = $answer_media_filename;
844
-            $question_data[ 'max_upload_size' ]       = $max_upload_size;
845 821
 
846
-            $question_data[ 'question_helptext' ]     = $question_helptext;
822
+			// Get max upload file size, formatted for display
823
+			// Code copied from wp-admin/includes/media.php:1515
824
+			$upload_size_unit = $max_upload_size = wp_max_upload_size();
825
+			$sizes = array( 'KB', 'MB', 'GB' );
826
+			for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) {
827
+				$upload_size_unit /= 1024;
828
+			}
829
+			if ( $u < 0 ) {
847 830
 
848
-        }// end if is file upload type
831
+				$upload_size_unit = 0;
832
+				$u = 0;
849 833
 
850
-        return $question_data;
834
+			} else {
851 835
 
852
-    }// end file_upload_load_question_data
836
+				$upload_size_unit = (int) $upload_size_unit;
853 837
 
854
-    /**
855
-     * Load multiple choice question data on the sensei_get_question_template_data
856
-     * filter.
857
-     *
858
-     * @since 1.9.0
859
-     *
860
-     * @param $question_data
861
-     * @param $question_id
862
-     * @param $quiz_id
863
-     *
864
-     * @return array()
865
-     */
866
-    public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){
838
+			}
839
+			$max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) );
867 840
 
868
-        if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) {
841
+			// Assemble all the data needed by the file upload template
842
+			$question_data[ 'answer_media_url' ]      = $answer_media_url;
843
+			$question_data[ 'answer_media_filename' ] = $answer_media_filename;
844
+			$question_data[ 'max_upload_size' ]       = $max_upload_size;
869 845
 
846
+			$question_data[ 'question_helptext' ]     = $question_helptext;
870 847
 
871
-            $answer_type = 'radio';
872
-            if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) {
848
+		}// end if is file upload type
873 849
 
874
-                $answer_type = 'checkbox';
850
+		return $question_data;
875 851
 
876
-            }
852
+	}// end file_upload_load_question_data
877 853
 
878
-            // Merge right and wrong answers
879
-            if ( is_array( $question_data[ 'question_right_answer' ] ) ) {
854
+	/**
855
+	 * Load multiple choice question data on the sensei_get_question_template_data
856
+	 * filter.
857
+	 *
858
+	 * @since 1.9.0
859
+	 *
860
+	 * @param $question_data
861
+	 * @param $question_id
862
+	 * @param $quiz_id
863
+	 *
864
+	 * @return array()
865
+	 */
866
+	public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){
880 867
 
881
-                $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] );
868
+		if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) {
882 869
 
883
-            }  else {
884 870
 
885
-                array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] );
886
-                $merged_options = $question_data[ 'question_wrong_answers' ];
871
+			$answer_type = 'radio';
872
+			if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) {
887 873
 
888
-            }
874
+				$answer_type = 'checkbox';
889 875
 
890
-            // Setup answer options array.
891
-            $question_answers_options = array();
892
-            $count = 0;
876
+			}
893 877
 
894
-            foreach( $merged_options as $answer ) {
878
+			// Merge right and wrong answers
879
+			if ( is_array( $question_data[ 'question_right_answer' ] ) ) {
895 880
 
896
-                $count++;
897
-                $question_option = array();
881
+				$merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] );
898 882
 
899
-                if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' )
900
-                    || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' )
901
-                    || ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ]  && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) {
883
+			}  else {
902 884
 
903
-                    $user_correct = false;
885
+				array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] );
886
+				$merged_options = $question_data[ 'question_wrong_answers' ];
904 887
 
888
+			}
905 889
 
906
-                    // For zero grade mark as 'correct' but add no classes
907
-                    if ( 0 == $question_data[ 'question_grade' ] ) {
890
+			// Setup answer options array.
891
+			$question_answers_options = array();
892
+			$count = 0;
908 893
 
909
-                        $user_correct = true;
894
+			foreach( $merged_options as $answer ) {
910 895
 
911
-                    }  else if( $question_data[ 'user_question_grade' ] > 0 ) {
896
+				$count++;
897
+				$question_option = array();
912 898
 
913
-                        $user_correct = true;
899
+				if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' )
900
+					|| ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' )
901
+					|| ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ]  && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) {
914 902
 
915
-                    }
903
+					$user_correct = false;
916 904
 
917
-                }
918 905
 
919
-                // setup the option specific classes
920
-                $answer_class = '';
921
-                if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) {
922
-                    if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) {
906
+					// For zero grade mark as 'correct' but add no classes
907
+					if ( 0 == $question_data[ 'question_grade' ] ) {
923 908
 
924
-                        $answer_class .= ' right_answer';
909
+						$user_correct = true;
925 910
 
926
-                    }  elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) {
911
+					}  else if( $question_data[ 'user_question_grade' ] > 0 ) {
927 912
 
928
-                        $answer_class .= ' right_answer';
913
+						$user_correct = true;
929 914
 
930
-                    } elseif( ( is_array( $question_data['user_answer_entry']  ) && in_array($answer, $question_data['user_answer_entry'] ) )
931
-                        ||  ( !  $question_data['user_answer_entry'] &&  $question_data['user_answer_entry'] == $answer ) ) {
915
+					}
932 916
 
933
-                        $answer_class = 'user_wrong';
934
-                        if( $user_correct ) {
917
+				}
935 918
 
936
-                            $answer_class = 'user_right';
919
+				// setup the option specific classes
920
+				$answer_class = '';
921
+				if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) {
922
+					if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) {
937 923
 
938
-                        }
924
+						$answer_class .= ' right_answer';
939 925
 
940
-                    }
926
+					}  elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) {
941 927
 
942
-                }
928
+						$answer_class .= ' right_answer';
943 929
 
944
-                // determine if the current option must be checked
945
-                $checked = '';
946
-                if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) {
947
-                    if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) {
930
+					} elseif( ( is_array( $question_data['user_answer_entry']  ) && in_array($answer, $question_data['user_answer_entry'] ) )
931
+						||  ( !  $question_data['user_answer_entry'] &&  $question_data['user_answer_entry'] == $answer ) ) {
948 932
 
949
-                        $checked = 'checked="checked"';
933
+						$answer_class = 'user_wrong';
934
+						if( $user_correct ) {
950 935
 
951
-                    } elseif ( !is_array( $question_data['user_answer_entry'] ) ) {
936
+							$answer_class = 'user_right';
952 937
 
953
-                        $checked = checked( $answer, $question_data['user_answer_entry'] , false );
938
+						}
954 939
 
955
-                    }
940
+					}
956 941
 
957
-                } // End If Statement
942
+				}
958 943
 
959
-                //Load the answer option data
960
-                $question_option[ 'ID' ]          = Sensei()->lesson->get_answer_id( $answer );
961
-                $question_option[ 'answer' ]      = $answer;
962
-                $question_option[ 'option_class'] = $answer_class;
963
-                $question_option[ 'checked']      = $checked;
964
-                $question_option[ 'count' ]       = $count;
965
-                $question_option[ 'type' ] = $answer_type;
944
+				// determine if the current option must be checked
945
+				$checked = '';
946
+				if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) {
947
+					if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) {
966 948
 
967
-                // add the speci  fic option to the list of options for this question
968
-                $question_answers_options[] = $question_option;
949
+						$checked = 'checked="checked"';
969 950
 
970
-            } // end for each option
951
+					} elseif ( !is_array( $question_data['user_answer_entry'] ) ) {
971 952
 
953
+						$checked = checked( $answer, $question_data['user_answer_entry'] , false );
972 954
 
973
-            // Shuffle the array depending on the settings
974
-            $answer_options_sorted = array();
975
-            $random_order = get_post_meta( $question_data['ID'], '_random_order', true );
976
-            if(  $random_order && $random_order == 'yes' ) {
955
+					}
977 956
 
978
-                $answer_options_sorted = $question_answers_options;
979
-                shuffle( $answer_options_sorted );
957
+				} // End If Statement
980 958
 
981
-            } else {
959
+				//Load the answer option data
960
+				$question_option[ 'ID' ]          = Sensei()->lesson->get_answer_id( $answer );
961
+				$question_option[ 'answer' ]      = $answer;
962
+				$question_option[ 'option_class'] = $answer_class;
963
+				$question_option[ 'checked']      = $checked;
964
+				$question_option[ 'count' ]       = $count;
965
+				$question_option[ 'type' ] = $answer_type;
982 966
 
983
-                $answer_order = array();
984
-                $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true );
985
-                if( $answer_order_string ) {
967
+				// add the speci  fic option to the list of options for this question
968
+				$question_answers_options[] = $question_option;
986 969
 
987
-                    $answer_order = array_filter( explode( ',', $answer_order_string ) );
988
-                    if( count( $answer_order ) > 0 ) {
970
+			} // end for each option
989 971
 
990
-                        foreach( $answer_order as $answer_id ) {
991 972
 
992
-                            if( isset( $question_answers_options[ $answer_id ] ) ) {
973
+			// Shuffle the array depending on the settings
974
+			$answer_options_sorted = array();
975
+			$random_order = get_post_meta( $question_data['ID'], '_random_order', true );
976
+			if(  $random_order && $random_order == 'yes' ) {
993 977
 
994
-                                $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ];
995
-                                unset( $question_answers_options[ $answer_id ] );
978
+				$answer_options_sorted = $question_answers_options;
979
+				shuffle( $answer_options_sorted );
996 980
 
997
-                            }
981
+			} else {
998 982
 
999
-                        }
983
+				$answer_order = array();
984
+				$answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true );
985
+				if( $answer_order_string ) {
1000 986
 
1001
-                        if( count( $question_answers_options ) > 0 ) {
1002
-                            foreach( $question_answers_options as $id => $answer ) {
987
+					$answer_order = array_filter( explode( ',', $answer_order_string ) );
988
+					if( count( $answer_order ) > 0 ) {
1003 989
 
1004
-                                $answer_options_sorted[ $id ] = $answer;
990
+						foreach( $answer_order as $answer_id ) {
1005 991
 
1006
-                            }
1007
-                        }
992
+							if( isset( $question_answers_options[ $answer_id ] ) ) {
1008 993
 
1009
-                    }else{
994
+								$answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ];
995
+								unset( $question_answers_options[ $answer_id ] );
1010 996
 
1011
-                        $answer_options_sorted = $question_answers_options;
997
+							}
1012 998
 
1013
-                    }
999
+						}
1014 1000
 
1015
-                }else{
1001
+						if( count( $question_answers_options ) > 0 ) {
1002
+							foreach( $question_answers_options as $id => $answer ) {
1016 1003
 
1017
-                    $answer_options_sorted = $question_answers_options;
1004
+								$answer_options_sorted[ $id ] = $answer;
1018 1005
 
1019
-                } // end if $answer_order_string
1006
+							}
1007
+						}
1020 1008
 
1021
-            } // end if random order
1009
+					}else{
1022 1010
 
1011
+						$answer_options_sorted = $question_answers_options;
1023 1012
 
1024
-            // assemble and setup the data for the templates data array
1025
-            $question_data[ 'answer_options' ]    =  $answer_options_sorted;
1013
+					}
1026 1014
 
1027
-        }
1015
+				}else{
1028 1016
 
1029
-        return $question_data;
1017
+					$answer_options_sorted = $question_answers_options;
1030 1018
 
1031
-    }//  end multiple_choice_load_question_data
1019
+				} // end if $answer_order_string
1032 1020
 
1033
-    /**
1034
-     * Load the gap fill question data on the sensei_get_question_template_data
1035
-     * filter.
1036
-     *
1037
-     * @since 1.9.0
1038
-     *
1039
-     * @param $question_data
1040
-     * @param $question_id
1041
-     * @param $quiz_id
1042
-     *
1043
-     * @return array()
1044
-     */
1045
-    public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){
1021
+			} // end if random order
1046 1022
 
1047
-        if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) {
1048 1023
 
1049
-            $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] );
1050
-            $question_data[ 'gapfill_pre' ]  = isset( $gapfill_array[0] ) ? $gapfill_array[0] : '';
1051
-            $question_data[ 'gapfill_gap' ]  = isset( $gapfill_array[1] ) ? $gapfill_array[1] : '';
1052
-            $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : '';
1024
+			// assemble and setup the data for the templates data array
1025
+			$question_data[ 'answer_options' ]    =  $answer_options_sorted;
1053 1026
 
1054
-        }
1027
+		}
1055 1028
 
1056
-        return $question_data;
1029
+		return $question_data;
1057 1030
 
1058
-    }//  end gap_fill_load_question_data
1031
+	}//  end multiple_choice_load_question_data
1032
+
1033
+	/**
1034
+	 * Load the gap fill question data on the sensei_get_question_template_data
1035
+	 * filter.
1036
+	 *
1037
+	 * @since 1.9.0
1038
+	 *
1039
+	 * @param $question_data
1040
+	 * @param $question_id
1041
+	 * @param $quiz_id
1042
+	 *
1043
+	 * @return array()
1044
+	 */
1045
+	public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){
1046
+
1047
+		if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) {
1048
+
1049
+			$gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] );
1050
+			$question_data[ 'gapfill_pre' ]  = isset( $gapfill_array[0] ) ? $gapfill_array[0] : '';
1051
+			$question_data[ 'gapfill_gap' ]  = isset( $gapfill_array[1] ) ? $gapfill_array[1] : '';
1052
+			$question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : '';
1053
+
1054
+		}
1055
+
1056
+		return $question_data;
1057
+
1058
+	}//  end gap_fill_load_question_data
1059 1059
 
1060 1060
 
1061
-    /**
1062
-     * Get the correct answer for a question
1063
-     *
1064
-     * @param $question_id
1065
-     * @return string $correct_answer or empty
1066
-     */
1067
-    public static function get_correct_answer( $question_id ){
1061
+	/**
1062
+	 * Get the correct answer for a question
1063
+	 *
1064
+	 * @param $question_id
1065
+	 * @return string $correct_answer or empty
1066
+	 */
1067
+	public static function get_correct_answer( $question_id ){
1068 1068
 
1069
-        $right_answer = get_post_meta( $question_id, '_question_right_answer', true );
1070
-        $type = Sensei()->question->get_question_type( $question_id );
1071
-        $type_name = __( 'Multiple Choice', 'woothemes-sensei' );
1072
-        $grade_type = 'manual-grade';
1069
+		$right_answer = get_post_meta( $question_id, '_question_right_answer', true );
1070
+		$type = Sensei()->question->get_question_type( $question_id );
1071
+		$type_name = __( 'Multiple Choice', 'woothemes-sensei' );
1072
+		$grade_type = 'manual-grade';
1073 1073
 
1074
-        if ('boolean'== $type ) {
1074
+		if ('boolean'== $type ) {
1075 1075
 
1076
-            $right_answer = ucfirst($right_answer);
1076
+			$right_answer = ucfirst($right_answer);
1077 1077
 
1078
-        }elseif( 'multiple-choice' == $type ) {
1078
+		}elseif( 'multiple-choice' == $type ) {
1079 1079
 
1080
-            $right_answer = (array) $right_answer;
1081
-            $right_answer = implode( ', ', $right_answer );
1080
+			$right_answer = (array) $right_answer;
1081
+			$right_answer = implode( ', ', $right_answer );
1082 1082
 
1083
-        }elseif( 'gap-fill' == $type ) {
1083
+		}elseif( 'gap-fill' == $type ) {
1084 1084
 
1085
-            $right_answer_array = explode( '||', $right_answer );
1086
-            if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; }
1087
-            if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; }
1088
-            if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; }
1085
+			$right_answer_array = explode( '||', $right_answer );
1086
+			if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; }
1087
+			if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; }
1088
+			if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; }
1089 1089
 
1090
-            $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post;
1090
+			$right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post;
1091 1091
 
1092
-        }else{
1092
+		}else{
1093 1093
 
1094
-            // for non auto gradable question types no answer should be returned.
1095
-            $right_answer = '';
1094
+			// for non auto gradable question types no answer should be returned.
1095
+			$right_answer = '';
1096 1096
 
1097
-        }
1097
+		}
1098 1098
 
1099
-        return $right_answer;
1099
+		return $right_answer;
1100 1100
 
1101
-    } // get_correct_answer
1101
+	} // get_correct_answer
1102 1102
 
1103 1103
 } // End Class
1104 1104
 
Please login to merge, or discard this patch.
Spacing   +286 added lines, -286 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Question Class
@@ -20,34 +20,34 @@  discard block
 block discarded – undo
20 20
 	 * Constructor.
21 21
 	 * @since  1.0.0
22 22
 	 */
23
-	public function __construct () {
23
+	public function __construct() {
24 24
 		$this->question_types = $this->question_types();
25
-		$this->meta_fields = array( 'question_right_answer', 'question_wrong_answers' );
26
-		if ( is_admin() ) {
25
+		$this->meta_fields = array('question_right_answer', 'question_wrong_answers');
26
+		if (is_admin()) {
27 27
 			// Custom Write Panel Columns
28
-			add_filter( 'manage_edit-question_columns', array( $this, 'add_column_headings' ), 10, 1 );
29
-			add_action( 'manage_posts_custom_column', array( $this, 'add_column_data' ), 10, 2 );
30
-			add_action( 'add_meta_boxes', array( $this, 'question_edit_panel_metabox' ), 10, 2 );
28
+			add_filter('manage_edit-question_columns', array($this, 'add_column_headings'), 10, 1);
29
+			add_action('manage_posts_custom_column', array($this, 'add_column_data'), 10, 2);
30
+			add_action('add_meta_boxes', array($this, 'question_edit_panel_metabox'), 10, 2);
31 31
 
32 32
 			// Quesitno list table filters
33
-			add_action( 'restrict_manage_posts', array( $this, 'filter_options' ) );
34
-			add_filter( 'request', array( $this, 'filter_actions' ) );
33
+			add_action('restrict_manage_posts', array($this, 'filter_options'));
34
+			add_filter('request', array($this, 'filter_actions'));
35 35
 
36
-			add_action( 'save_post', array( $this, 'save_question' ), 10, 1 );
36
+			add_action('save_post', array($this, 'save_question'), 10, 1);
37 37
 		} // End If Statement
38 38
 	} // End __construct()
39 39
 
40 40
 	public function question_types() {
41 41
 		$types = array(
42
-			'multiple-choice' => __( 'Multiple Choice', 'woothemes-sensei' ),
43
-			'boolean' => __( 'True/False', 'woothemes-sensei' ),
44
-			'gap-fill' => __( 'Gap Fill', 'woothemes-sensei' ),
45
-			'single-line' => __( 'Single Line', 'woothemes-sensei' ),
46
-			'multi-line' => __( 'Multi Line', 'woothemes-sensei' ),
47
-			'file-upload' => __( 'File Upload', 'woothemes-sensei' ),
42
+			'multiple-choice' => __('Multiple Choice', 'woothemes-sensei'),
43
+			'boolean' => __('True/False', 'woothemes-sensei'),
44
+			'gap-fill' => __('Gap Fill', 'woothemes-sensei'),
45
+			'single-line' => __('Single Line', 'woothemes-sensei'),
46
+			'multi-line' => __('Multi Line', 'woothemes-sensei'),
47
+			'file-upload' => __('File Upload', 'woothemes-sensei'),
48 48
 		);
49 49
 
50
-		return apply_filters( 'sensei_question_types', $types );
50
+		return apply_filters('sensei_question_types', $types);
51 51
 	}
52 52
 
53 53
 	/**
@@ -57,12 +57,12 @@  discard block
 block discarded – undo
57 57
 	 * @param  array $defaults
58 58
 	 * @return array $new_columns
59 59
 	 */
60
-	public function add_column_headings ( $defaults ) {
60
+	public function add_column_headings($defaults) {
61 61
 		$new_columns['cb'] = '<input type="checkbox" />';
62
-		$new_columns['title'] = _x( 'Question', 'column name', 'woothemes-sensei' );
63
-		$new_columns['question-type'] = _x( 'Type', 'column name', 'woothemes-sensei' );
64
-		$new_columns['question-category'] = _x( 'Categories', 'column name', 'woothemes-sensei' );
65
-		if ( isset( $defaults['date'] ) ) {
62
+		$new_columns['title'] = _x('Question', 'column name', 'woothemes-sensei');
63
+		$new_columns['question-type'] = _x('Type', 'column name', 'woothemes-sensei');
64
+		$new_columns['question-category'] = _x('Categories', 'column name', 'woothemes-sensei');
65
+		if (isset($defaults['date'])) {
66 66
 			$new_columns['date'] = $defaults['date'];
67 67
 		}
68 68
 
@@ -77,27 +77,27 @@  discard block
 block discarded – undo
77 77
 	 * @param  int $id
78 78
 	 * @return void
79 79
 	 */
80
-	public function add_column_data ( $column_name, $id ) {
80
+	public function add_column_data($column_name, $id) {
81 81
 		global $wpdb, $post;
82 82
 
83
-		switch ( $column_name ) {
83
+		switch ($column_name) {
84 84
 
85 85
 			case 'id':
86 86
 				echo $id;
87 87
 			break;
88 88
 
89 89
 			case 'question-type':
90
-				$question_type = strip_tags( get_the_term_list( $id, 'question-type', '', ', ', '' ) );
90
+				$question_type = strip_tags(get_the_term_list($id, 'question-type', '', ', ', ''));
91 91
 				$output = '&mdash;';
92
-				if( isset( $this->question_types[ $question_type ] ) ) {
93
-					$output = $this->question_types[ $question_type ];
92
+				if (isset($this->question_types[$question_type])) {
93
+					$output = $this->question_types[$question_type];
94 94
 				}
95 95
 				echo $output;
96 96
 			break;
97 97
 
98 98
 			case 'question-category':
99
-				$output = strip_tags( get_the_term_list( $id, 'question-category', '', ', ', '' ) );
100
-				if( ! $output ) {
99
+				$output = strip_tags(get_the_term_list($id, 'question-category', '', ', ', ''));
100
+				if ( ! $output) {
101 101
 					$output = '&mdash;';
102 102
 				}
103 103
 				echo $output;
@@ -110,49 +110,49 @@  discard block
 block discarded – undo
110 110
 
111 111
 	} // End add_column_data()
112 112
 
113
-	public function question_edit_panel_metabox( $post_type, $post ) {
114
-		if( in_array( $post_type, array( 'question', 'multiple_question' ) ) ) {
113
+	public function question_edit_panel_metabox($post_type, $post) {
114
+		if (in_array($post_type, array('question', 'multiple_question'))) {
115 115
 
116
-			$metabox_title = __( 'Question', 'woothemes-sensei' );
116
+			$metabox_title = __('Question', 'woothemes-sensei');
117 117
 
118
-			if( isset( $post->ID ) ) {
118
+			if (isset($post->ID)) {
119 119
 
120
-                $question_type = Sensei()->question->get_question_type( $post->ID );
120
+                $question_type = Sensei()->question->get_question_type($post->ID);
121 121
 
122
-				if( $question_type ) {
123
-					$type = $this->question_types[ $question_type ];
124
-					if( $type ) {
122
+				if ($question_type) {
123
+					$type = $this->question_types[$question_type];
124
+					if ($type) {
125 125
 						$metabox_title = $type;
126 126
 					}
127 127
 				}
128 128
 			}
129
-			add_meta_box( 'question-edit-panel', $metabox_title, array( $this, 'question_edit_panel' ), 'question', 'normal', 'high' );
130
-			add_meta_box( 'question-lessons-panel', __( 'Quizzes', 'woothemes-sensei' ), array( $this, 'question_lessons_panel' ), 'question', 'side', 'default' );
131
-			add_meta_box( 'multiple-question-lessons-panel', __( 'Quizzes', 'woothemes-sensei' ), array( $this, 'question_lessons_panel' ), 'multiple_question', 'side', 'default' );
129
+			add_meta_box('question-edit-panel', $metabox_title, array($this, 'question_edit_panel'), 'question', 'normal', 'high');
130
+			add_meta_box('question-lessons-panel', __('Quizzes', 'woothemes-sensei'), array($this, 'question_lessons_panel'), 'question', 'side', 'default');
131
+			add_meta_box('multiple-question-lessons-panel', __('Quizzes', 'woothemes-sensei'), array($this, 'question_lessons_panel'), 'multiple_question', 'side', 'default');
132 132
 		}
133 133
 	}
134 134
 
135 135
 	public function question_edit_panel() {
136 136
 		global  $post, $pagenow;
137 137
 
138
-		add_action( 'admin_enqueue_scripts', array( Sensei()->lesson, 'enqueue_scripts' ) );
139
-		add_action( 'admin_enqueue_scripts', array( Sensei()->lesson, 'enqueue_styles' ) );
138
+		add_action('admin_enqueue_scripts', array(Sensei()->lesson, 'enqueue_scripts'));
139
+		add_action('admin_enqueue_scripts', array(Sensei()->lesson, 'enqueue_styles'));
140 140
 
141 141
 		$html = '<div id="lesson-quiz" class="single-question"><div id="add-question-main">';
142 142
 
143
-		if( 'post-new.php' == $pagenow ) {
143
+		if ('post-new.php' == $pagenow) {
144 144
 
145 145
 			$html .= '<div id="add-question-actions">';
146
-				$html .= Sensei()->lesson->quiz_panel_add( 'question' );
146
+				$html .= Sensei()->lesson->quiz_panel_add('question');
147 147
 			$html .= '</div>';
148 148
 
149 149
 		} else {
150 150
 			$question_id = $post->ID;
151 151
 
152
-			$question_type =  Sensei()->question->get_question_type( $post->ID );
152
+			$question_type = Sensei()->question->get_question_type($post->ID);
153 153
 
154 154
 			$html .= '<div id="add-question-metadata"><table class="widefat">';
155
-				$html .= Sensei()->lesson->quiz_panel_question( $question_type, 0, $question_id, 'question' );
155
+				$html .= Sensei()->lesson->quiz_panel_question($question_type, 0, $question_id, 'question');
156 156
 			$html .= '</table></div>';
157 157
 		}
158 158
 
@@ -164,20 +164,20 @@  discard block
 block discarded – undo
164 164
 	public function question_lessons_panel() {
165 165
 		global $post;
166 166
 
167
-		$no_lessons = sprintf( __( '%1$sThis question does not appear in any quizzes yet.%2$s', 'woothemes-sensei' ), '<em>', '</em>' );
167
+		$no_lessons = sprintf(__('%1$sThis question does not appear in any quizzes yet.%2$s', 'woothemes-sensei'), '<em>', '</em>');
168 168
 
169
-		if( ! isset( $post->ID ) ) {
169
+		if ( ! isset($post->ID)) {
170 170
 			echo $no_lessons;
171 171
 			return;
172 172
 		}
173 173
 
174 174
 		// This retrieves those quizzes the question is directly connected to.
175
-		$quizzes = get_post_meta( $post->ID, '_quiz_id', false );
175
+		$quizzes = get_post_meta($post->ID, '_quiz_id', false);
176 176
 
177 177
 		// Collate all 'multiple_question' quizzes the question is part of.
178
-		$categories_of_question = wp_get_post_terms( $post->ID, 'question-category', array( 'fields' => 'ids' ) );
179
-		if ( ! empty( $categories_of_question ) ) {
180
-			foreach ( $categories_of_question as $term_id ) {
178
+		$categories_of_question = wp_get_post_terms($post->ID, 'question-category', array('fields' => 'ids'));
179
+		if ( ! empty($categories_of_question)) {
180
+			foreach ($categories_of_question as $term_id) {
181 181
 				$qargs = array(
182 182
 					'fields'           => 'ids',
183 183
 					'post_type'        => 'multiple_question',
@@ -191,41 +191,41 @@  discard block
 block discarded – undo
191 191
 					'post_status'      => 'any',
192 192
 					'suppress_filters' => 0,
193 193
 				);
194
-				$cat_question_ids = get_posts( $qargs );
195
-				foreach( $cat_question_ids as $cat_question_id ) {
196
-					$cat_quizzes = get_post_meta( $cat_question_id, '_quiz_id', false );
197
-					$quizzes = array_merge( $quizzes, $cat_quizzes );
194
+				$cat_question_ids = get_posts($qargs);
195
+				foreach ($cat_question_ids as $cat_question_id) {
196
+					$cat_quizzes = get_post_meta($cat_question_id, '_quiz_id', false);
197
+					$quizzes = array_merge($quizzes, $cat_quizzes);
198 198
 				}
199 199
 			}
200
-			$quizzes = array_unique( array_filter( $quizzes ) );
200
+			$quizzes = array_unique(array_filter($quizzes));
201 201
 		}
202 202
 
203
-		if( 0 == count( $quizzes ) ) {
203
+		if (0 == count($quizzes)) {
204 204
 			echo $no_lessons;
205 205
 			return;
206 206
 		}
207 207
 
208 208
 		$lessons = false;
209 209
 
210
-		foreach( $quizzes as $quiz ) {
210
+		foreach ($quizzes as $quiz) {
211 211
 
212
-			$lesson_id = get_post_meta( $quiz, '_quiz_lesson', true );
212
+			$lesson_id = get_post_meta($quiz, '_quiz_lesson', true);
213 213
 
214
-			if( ! $lesson_id ) continue;
214
+			if ( ! $lesson_id) continue;
215 215
 
216
-			$lessons[ $lesson_id ]['title'] = get_the_title( $lesson_id );
217
-			$lessons[ $lesson_id ]['link'] = admin_url( 'post.php?post=' . $lesson_id . '&action=edit' );
216
+			$lessons[$lesson_id]['title'] = get_the_title($lesson_id);
217
+			$lessons[$lesson_id]['link'] = admin_url('post.php?post='.$lesson_id.'&action=edit');
218 218
 		}
219 219
 
220
-		if( ! $lessons ) {
220
+		if ( ! $lessons) {
221 221
 			echo $no_lessons;
222 222
 			return;
223 223
 		}
224 224
 
225 225
 		$html = '<ul>';
226 226
 
227
-		foreach( $lessons as $id => $lesson ) {
228
-			$html .= '<li><a href="' . esc_url( $lesson['link'] ) . '">' . esc_html( $lesson['title'] ) . '</a></li>';
227
+		foreach ($lessons as $id => $lesson) {
228
+			$html .= '<li><a href="'.esc_url($lesson['link']).'">'.esc_html($lesson['title']).'</a></li>';
229 229
 		}
230 230
 
231 231
 		$html .= '</ul>';
@@ -234,30 +234,30 @@  discard block
 block discarded – undo
234 234
 
235 235
 	}
236 236
 
237
-	public function save_question( $post_id = 0 ) {
237
+	public function save_question($post_id = 0) {
238 238
 
239
-		if( ! isset( $_POST['post_type']
240
-            ) || 'question' != $_POST['post_type'] ) {
239
+		if ( ! isset($_POST['post_type']
240
+            ) || 'question' != $_POST['post_type']) {
241 241
             return;
242 242
         }
243 243
 
244 244
 
245 245
 
246 246
         //setup the data for saving
247
-		$data = $_POST ;
247
+		$data = $_POST;
248 248
         $data['quiz_id'] = 0;
249 249
 		$data['question_id'] = $post_id;
250 250
 
251
-		if ( ! wp_is_post_revision( $post_id ) ){
251
+		if ( ! wp_is_post_revision($post_id)) {
252 252
 
253 253
 			// Unhook function to prevent infinite loops
254
-			remove_action( 'save_post', array( $this, 'save_question' ) );
254
+			remove_action('save_post', array($this, 'save_question'));
255 255
 
256 256
 			// Update question data
257
-			$question_id = Sensei()->lesson->lesson_save_question( $data, 'question' );
257
+			$question_id = Sensei()->lesson->lesson_save_question($data, 'question');
258 258
 
259 259
 			// Re-hook same function
260
-			add_action( 'save_post', array( $this, 'save_question' ) );
260
+			add_action('save_post', array($this, 'save_question'));
261 261
 		}
262 262
 
263 263
 		return;
@@ -270,15 +270,15 @@  discard block
 block discarded – undo
270 270
 	public function filter_options() {
271 271
 		global $typenow;
272 272
 
273
-		if( is_admin() && 'question' == $typenow ) {
273
+		if (is_admin() && 'question' == $typenow) {
274 274
 
275 275
 			$output = '';
276 276
 
277 277
 			// Question type
278
-			$selected = isset( $_GET['question_type'] ) ? $_GET['question_type'] : '';
279
-			$type_options = '<option value="">' . __( 'All types', 'woothemes-sensei' ) . '</option>';
280
-			foreach( $this->question_types as $label => $type ) {
281
-				$type_options .= '<option value="' . esc_attr( $label ) . '" ' . selected( $selected, $label, false ) . '>' . esc_html( $type ) . '</option>';
278
+			$selected = isset($_GET['question_type']) ? $_GET['question_type'] : '';
279
+			$type_options = '<option value="">'.__('All types', 'woothemes-sensei').'</option>';
280
+			foreach ($this->question_types as $label => $type) {
281
+				$type_options .= '<option value="'.esc_attr($label).'" '.selected($selected, $label, false).'>'.esc_html($type).'</option>';
282 282
 			}
283 283
 
284 284
 			$output .= '<select name="question_type" id="dropdown_question_type">';
@@ -286,12 +286,12 @@  discard block
 block discarded – undo
286 286
 			$output .= '</select>';
287 287
 
288 288
 			// Question category
289
-			$cats = get_terms( 'question-category', array( 'hide_empty' => false ) );
290
-			if ( ! empty( $cats ) && ! is_wp_error( $cats ) ) {
291
-				$selected = isset( $_GET['question_cat'] ) ? $_GET['question_cat'] : '';
292
-				$cat_options = '<option value="">' . __( 'All categories', 'woothemes-sensei' ) . '</option>';
293
-				foreach( $cats as $cat ) {
294
-					$cat_options .= '<option value="' . esc_attr( $cat->slug ) . '" ' . selected( $selected, $cat->slug, false ) . '>' . esc_html( $cat->name ) . '</option>';
289
+			$cats = get_terms('question-category', array('hide_empty' => false));
290
+			if ( ! empty($cats) && ! is_wp_error($cats)) {
291
+				$selected = isset($_GET['question_cat']) ? $_GET['question_cat'] : '';
292
+				$cat_options = '<option value="">'.__('All categories', 'woothemes-sensei').'</option>';
293
+				foreach ($cats as $cat) {
294
+					$cat_options .= '<option value="'.esc_attr($cat->slug).'" '.selected($selected, $cat->slug, false).'>'.esc_html($cat->name).'</option>';
295 295
 				}
296 296
 
297 297
 				$output .= '<select name="question_cat" id="dropdown_question_cat">';
@@ -308,14 +308,14 @@  discard block
 block discarded – undo
308 308
 	 * @param  array $request Current request
309 309
 	 * @return array          Modified request
310 310
 	 */
311
-	public function filter_actions( $request ) {
311
+	public function filter_actions($request) {
312 312
 		global $typenow;
313 313
 
314
-		if( is_admin() && 'question' == $typenow ) {
314
+		if (is_admin() && 'question' == $typenow) {
315 315
 
316 316
 			// Question type
317
-			$question_type = isset( $_GET['question_type'] ) ? $_GET['question_type'] : '';
318
-			if( $question_type ) {
317
+			$question_type = isset($_GET['question_type']) ? $_GET['question_type'] : '';
318
+			if ($question_type) {
319 319
 				$type_query = array(
320 320
 					'taxonomy' => 'question-type',
321 321
 					'terms' => $question_type,
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
 			}
326 326
 
327 327
 			// Question category
328
-			$question_cat = isset( $_GET['question_cat'] ) ? $_GET['question_cat'] : '';
329
-			if( $question_cat ) {
328
+			$question_cat = isset($_GET['question_cat']) ? $_GET['question_cat'] : '';
329
+			if ($question_cat) {
330 330
 				$cat_query = array(
331 331
 					'taxonomy' => 'question-category',
332 332
 					'terms' => $question_cat,
@@ -351,16 +351,16 @@  discard block
 block discarded – undo
351 351
      *
352 352
      * @return string $question_type | bool
353 353
      */
354
-    public function get_question_type( $question_id ){
354
+    public function get_question_type($question_id) {
355 355
 
356
-        if( empty( $question_id ) || ! intval( $question_id ) > 0
357
-            || 'question' != get_post_type( $question_id )   ){
356
+        if (empty($question_id) || ! intval($question_id) > 0
357
+            || 'question' != get_post_type($question_id)) {
358 358
             return false;
359 359
         }
360 360
 
361 361
         $question_type = 'multiple-choice';
362
-        $question_types = wp_get_post_terms( $question_id, 'question-type' );
363
-        foreach( $question_types as $type ) {
362
+        $question_types = wp_get_post_terms($question_id, 'question-type');
363
+        foreach ($question_types as $type) {
364 364
             $question_type = $type->slug;
365 365
         }
366 366
 
@@ -377,21 +377,21 @@  discard block
 block discarded – undo
377 377
 	 *
378 378
 	 * @return int $question_grade | bool
379 379
 	 */
380
-	public function get_question_grade( $question_id ) {
380
+	public function get_question_grade($question_id) {
381 381
 
382
-		if ( empty( $question_id ) || ! intval( $question_id ) > 0
383
-			|| 'question' != get_post_type( $question_id ) ) {
382
+		if (empty($question_id) || ! intval($question_id) > 0
383
+			|| 'question' != get_post_type($question_id)) {
384 384
 			return false;
385 385
 		}
386 386
 
387
-		$question_grade_raw = get_post_meta( $question_id, '_question_grade', true );
387
+		$question_grade_raw = get_post_meta($question_id, '_question_grade', true);
388 388
 		// If not set then default to 1...
389
-		if ( false === $question_grade_raw || $question_grade_raw == '' ) {
389
+		if (false === $question_grade_raw || $question_grade_raw == '') {
390 390
 			$question_grade = 1;
391 391
 		}
392 392
 		// ...but allow a grade of 0 for non-marked questions
393 393
 		else {
394
-			$question_grade = intval( $question_grade_raw );
394
+			$question_grade = intval($question_grade_raw);
395 395
 		}
396 396
 		return $question_grade;
397 397
 
@@ -404,9 +404,9 @@  discard block
 block discarded – undo
404 404
      * @since 1.9.0
405 405
      * @param $question_type
406 406
      */
407
-    public static function load_question_template( $question_type ){
407
+    public static function load_question_template($question_type) {
408 408
 
409
-        Sensei_Templates::get_template  ( 'single-quiz/question_type-' . $question_type . '.php' );
409
+        Sensei_Templates::get_template('single-quiz/question_type-'.$question_type.'.php');
410 410
     }
411 411
 
412 412
     /**
@@ -417,9 +417,9 @@  discard block
 block discarded – undo
417 417
      * @since 1.9.0
418 418
      * @param $question_id
419 419
      */
420
-    public static function the_question_title( $question_id ){
420
+    public static function the_question_title($question_id) {
421 421
 
422
-        echo self::get_the_question_title( $question_id );
422
+        echo self::get_the_question_title($question_id);
423 423
 
424 424
     }// end the_question_title
425 425
 
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
      * @param $question_id
432 432
      * @return string
433 433
      */
434
-    public static function get_the_question_title( $question_id ){
434
+    public static function get_the_question_title($question_id) {
435 435
 
436 436
         /**
437 437
          * Filter the sensei question title
@@ -439,17 +439,17 @@  discard block
 block discarded – undo
439 439
          * @since 1.3.0
440 440
          * @param $question_title
441 441
          */
442
-        $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) );
442
+        $title = apply_filters('sensei_question_title', get_the_title($question_id));
443 443
 
444 444
         /**
445 445
          * hook document in class-woothemes-sensei-message.php the_title()
446 446
          */
447
-        $title = apply_filters( 'sensei_single_title', $title, 'question');
447
+        $title = apply_filters('sensei_single_title', $title, 'question');
448 448
 
449 449
         $title_html  = '<span class="question question-title">';
450 450
         $title_html .= $title;
451 451
         $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>';
452
-        $title_html .='</span>';
452
+        $title_html .= '</span>';
453 453
 
454 454
         return $title_html;
455 455
     }
@@ -460,14 +460,14 @@  discard block
 block discarded – undo
460 460
      * @param $question_id
461 461
      * @return string
462 462
      */
463
-    public static function get_the_question_description( $question_id ){
463
+    public static function get_the_question_description($question_id) {
464 464
 
465
-        $question = get_post( $question_id );
465
+        $question = get_post($question_id);
466 466
 
467 467
         /**
468 468
          * Already documented within WordPress Core
469 469
          */
470
-        return apply_filters( 'the_content', $question->post_content );
470
+        return apply_filters('the_content', $question->post_content);
471 471
 
472 472
     }
473 473
 
@@ -477,9 +477,9 @@  discard block
 block discarded – undo
477 477
      * @since 1.9.0
478 478
      * @param $question_id
479 479
      */
480
-    public static function the_question_description( $question_id  ){
480
+    public static function the_question_description($question_id) {
481 481
 
482
-        echo self::get_the_question_description( $question_id );
482
+        echo self::get_the_question_description($question_id);
483 483
 
484 484
     }
485 485
 
@@ -490,38 +490,38 @@  discard block
 block discarded – undo
490 490
      * @param $question_id
491 491
      * @return string
492 492
      */
493
-    public static function get_the_question_media( $question_id ){
493
+    public static function get_the_question_media($question_id) {
494 494
 
495
-        $question_media = get_post_meta( $question_id, '_question_media', true );
495
+        $question_media = get_post_meta($question_id, '_question_media', true);
496 496
         $question_media_link = '';
497
-        if( 0 < intval( $question_media ) ) {
498
-            $mimetype = get_post_mime_type( $question_media );
499
-            if( $mimetype ) {
500
-                $mimetype_array = explode( '/', $mimetype);
501
-                if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) {
497
+        if (0 < intval($question_media)) {
498
+            $mimetype = get_post_mime_type($question_media);
499
+            if ($mimetype) {
500
+                $mimetype_array = explode('/', $mimetype);
501
+                if (isset($mimetype_array[0]) && $mimetype_array[0]) {
502 502
                     $question_media_type = $mimetype_array[0];
503
-                    $question_media_url = wp_get_attachment_url( $question_media );
504
-                    $attachment = get_post( $question_media );
503
+                    $question_media_url = wp_get_attachment_url($question_media);
504
+                    $attachment = get_post($question_media);
505 505
                     $question_media_title = $attachment->post_title;
506 506
                     $question_media_description = $attachment->post_content;
507
-                    switch( $question_media_type ) {
507
+                    switch ($question_media_type) {
508 508
                         case 'image':
509
-                            $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id );
510
-                            $attachment_src = wp_get_attachment_image_src( $question_media, $image_size );
511
-                            $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>';
509
+                            $image_size = apply_filters('sensei_question_image_size', 'medium', $question_id);
510
+                            $attachment_src = wp_get_attachment_image_src($question_media, $image_size);
511
+                            $question_media_link = '<a class="'.esc_attr($question_media_type).'" title="'.esc_attr($question_media_title).'" href="'.esc_url($question_media_url).'" target="_blank"><img src="'.$attachment_src[0].'" width="'.$attachment_src[1].'" height="'.$attachment_src[2].'" /></a>';
512 512
                             break;
513 513
 
514 514
                         case 'audio':
515
-                            $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) );
515
+                            $question_media_link = wp_audio_shortcode(array('src' => $question_media_url));
516 516
                             break;
517 517
 
518 518
                         case 'video':
519
-                            $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) );
519
+                            $question_media_link = wp_video_shortcode(array('src' => $question_media_url));
520 520
                             break;
521 521
 
522 522
                         default:
523
-                            $question_media_filename = basename( $question_media_url );
524
-                            $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>';
523
+                            $question_media_filename = basename($question_media_url);
524
+                            $question_media_link = '<a class="'.esc_attr($question_media_type).'" title="'.esc_attr($question_media_title).'" href="'.esc_url($question_media_url).'" target="_blank">'.$question_media_filename.'</a>';
525 525
                             break;
526 526
                     }
527 527
                 }
@@ -529,21 +529,21 @@  discard block
 block discarded – undo
529 529
         }
530 530
 
531 531
         $output = '';
532
-        if( $question_media_link ) {
532
+        if ($question_media_link) {
533 533
 
534 534
                 $output .= '<div class="question_media_display">';
535
-                $output .=      $question_media_link;
535
+                $output .= $question_media_link;
536 536
                 $output .= '<dl>';
537 537
 
538
-                if( $question_media_title ) {
538
+                if ($question_media_title) {
539 539
 
540
-                   $output .= '<dt>'. $question_media_title. '</dt>';
540
+                   $output .= '<dt>'.$question_media_title.'</dt>';
541 541
 
542 542
                  }
543 543
 
544
-                if( $question_media_description ) {
544
+                if ($question_media_description) {
545 545
 
546
-                    $output .= '<dd>' . $question_media_description . '</dd>';
546
+                    $output .= '<dd>'.$question_media_description.'</dd>';
547 547
 
548 548
                 }
549 549
 
@@ -564,9 +564,9 @@  discard block
 block discarded – undo
564 564
      * @since 1.9.0
565 565
      * @param string $question_id
566 566
      */
567
-    public static function the_question_media( $question_id ){
567
+    public static function the_question_media($question_id) {
568 568
 
569
-        echo self::get_the_question_media( $question_id );
569
+        echo self::get_the_question_media($question_id);
570 570
 
571 571
     }
572 572
 
@@ -577,11 +577,11 @@  discard block
 block discarded – undo
577 577
      *
578 578
      * @param $question_id
579 579
      */
580
-    public static function the_question_hidden_fields( $question_id ){
580
+    public static function the_question_hidden_fields($question_id) {
581 581
         ?>
582 582
 
583
-            <input type="hidden" name="question_id_<?php $question_id;?>" value="<?php $question_id;?>" />
584
-            <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e( $question_id ); ?>" />
583
+            <input type="hidden" name="question_id_<?php $question_id; ?>" value="<?php $question_id; ?>" />
584
+            <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e($question_id); ?>" />
585 585
 
586 586
         <?php
587 587
     }
@@ -592,27 +592,27 @@  discard block
 block discarded – undo
592 592
      * @since 1.9.0
593 593
      * @param $question_id
594 594
      */
595
-    public static function answer_feedback_notes( $question_id ){
595
+    public static function answer_feedback_notes($question_id) {
596 596
 
597 597
         //IDS
598 598
         $quiz_id = get_the_ID();
599
-        $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
599
+        $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id);
600 600
 
601 601
         // Data to check before showing feedback
602
-        $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() );
603
-        $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
604
-        $not_empty_user_quiz_grade = !empty( $user_quiz_grade );
605
-        $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id );
606
-        $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id );
607
-        $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true );
602
+        $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, get_current_user_id());
603
+        $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade($lesson_id, get_current_user_id());
604
+        $not_empty_user_quiz_grade = ! empty($user_quiz_grade);
605
+        $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed($lesson_id);
606
+        $lesson_completed = Sensei_Utils::user_completed_lesson($lesson_id);
607
+        $quiz_grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true);
608 608
 
609
-        if( ( $lesson_completed  && $not_empty_user_quiz_grade  )
610
-            ||  ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type )
611
-            || ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) {
609
+        if (($lesson_completed && $not_empty_user_quiz_grade)
610
+            ||  ($lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type)
611
+            || ('auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade)) {
612 612
 
613
-            $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() );
613
+            $answer_notes = Sensei()->quiz->get_user_question_feedback($lesson_id, $question_id, get_current_user_id());
614 614
 
615
-            if( $answer_notes ) { ?>
615
+            if ($answer_notes) { ?>
616 616
 
617 617
                 <div class="sensei-message info info-special answer-feedback">
618 618
 
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
                          * @param string $question_id
627 627
                          * @param string $lesson_id
628 628
                          */
629
-                        echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id );
629
+                        echo apply_filters('sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id);
630 630
 
631 631
                     ?>
632 632
 
@@ -645,72 +645,72 @@  discard block
 block discarded – undo
645 645
      * @since 1.9.0
646 646
      * @param string $question_id
647 647
      */
648
-    public static function the_answer_result_indication( $question_id ){
648
+    public static function the_answer_result_indication($question_id) {
649 649
 
650
-        global $post,  $current_user, $sensei_question_loop;
650
+        global $post, $current_user, $sensei_question_loop;
651 651
 
652 652
         // Post Data
653 653
         $quiz_id = $sensei_question_loop['quiz_id'];
654
-        $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
654
+        $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id);
655 655
         $question_item = $sensei_question_loop['current_question'];
656 656
 
657 657
         // Setup variable needed to determine if the message should show and what it should show
658
-        $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
659
-        $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() );
660
-        $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id );
661
-        $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true );
658
+        $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade($lesson_id, get_current_user_id());
659
+        $lesson_complete = Sensei_Utils::user_completed_lesson($lesson_id, get_current_user_id());
660
+        $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed($lesson_id);
661
+        $quiz_grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true);
662 662
 
663 663
         // retrieve the question total grade
664
-        $question_grade = Sensei()->question->get_question_grade( $question_id );
664
+        $question_grade = Sensei()->question->get_question_grade($question_id);
665 665
 
666 666
         // retrieve grade the user achieved
667
-        $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() );
667
+        $user_question_grade = Sensei()->quiz->get_user_question_grade($lesson_id, $question_id, get_current_user_id());
668 668
 
669 669
         // Question ID
670 670
         $question_id = $question_item->ID;
671 671
 
672 672
         // conditions to check
673
-        $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ;
674
-        $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete &&  $user_quiz_grade != '' && ! $reset_quiz_allowed ;
675
-        $grade_type_auto_a_valid_grade_and_reset_not_allowed =  'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ;
673
+        $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '';
674
+        $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed;
675
+        $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '';
676 676
 
677
-        if (  $completed_with_valid_grade
677
+        if ($completed_with_valid_grade
678 678
             || $completed_with_valid_grade_and_reset_not_allowed
679
-            || $grade_type_auto_a_valid_grade_and_reset_not_allowed  ) {
679
+            || $grade_type_auto_a_valid_grade_and_reset_not_allowed) {
680 680
 
681 681
             $user_correct = false;
682
-            $answer_message = __( 'Incorrect', 'woothemes-sensei' );
682
+            $answer_message = __('Incorrect', 'woothemes-sensei');
683 683
             $answer_message_class = 'user_wrong';
684 684
             // For zero grade mark as 'correct' but add no classes
685
-            if ( 0 == $question_grade ) {
685
+            if (0 == $question_grade) {
686 686
 
687 687
                 $user_correct = true;
688 688
                 $answer_message = '';
689 689
                 $answer_message_class = '';
690 690
 
691
-            } else if( $user_question_grade > 0 ) {
691
+            } else if ($user_question_grade > 0) {
692 692
 
693 693
                 $user_correct = true;
694
-                $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade );
694
+                $answer_message = sprintf(__('Grade: %d', 'woothemes-sensei'), $user_question_grade);
695 695
                 $answer_message_class = 'user_right';
696 696
 
697 697
             }
698 698
 
699 699
             // attach the correct answer if the question is auto gradable and user got it wrong
700
-            if( !$reset_quiz_allowed && !$user_correct ){
700
+            if ( ! $reset_quiz_allowed && ! $user_correct) {
701 701
 
702
-                $answer_message .=  ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID );
702
+                $answer_message .= ' - '.__('Right Answer:', 'woothemes-sensei').' '.self::get_correct_answer($question_item->ID);
703 703
 
704 704
             }
705 705
 
706 706
             // answer feedback
707
-            $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID );
708
-            if( $answer_notes ) {
707
+            $answer_notes = Sensei()->quiz->get_user_question_feedback($lesson_id, $question_id, $current_user->ID);
708
+            if ($answer_notes) {
709 709
                 $answer_message_class .= ' has_notes';
710 710
             }
711 711
             ?>
712 712
 
713
-            <div class="answer_message <?php esc_attr_e( $answer_message_class ); ?>">
713
+            <div class="answer_message <?php esc_attr_e($answer_message_class); ?>">
714 714
 
715 715
                 <span><?php echo $answer_message; ?></span>
716 716
 
@@ -731,39 +731,39 @@  discard block
 block discarded – undo
731 731
      * @param $quiz_id
732 732
      * @return array $question_data
733 733
      */
734
-    public static function get_template_data( $question_id, $quiz_id ){
734
+    public static function get_template_data($question_id, $quiz_id) {
735 735
 
736
-        $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id  );
736
+        $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id);
737 737
 
738
-        $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true );
738
+        $reset_allowed = get_post_meta($quiz_id, '_enable_quiz_reset', true);
739 739
         //backwards compatibility
740
-        if( 'on' == $reset_allowed ) {
740
+        if ('on' == $reset_allowed) {
741 741
             $reset_allowed = 1;
742 742
         }
743 743
 
744 744
         // Check again that the lesson is complete
745
-        $user_lesson_end = WooThemes_Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() );
745
+        $user_lesson_end = WooThemes_Sensei_Utils::user_completed_lesson(Sensei()->quiz->get_lesson_id($quiz_id), get_current_user_id());
746 746
         $user_lesson_complete = false;
747
-        if ( $user_lesson_end ) {
747
+        if ($user_lesson_end) {
748 748
             $user_lesson_complete = true;
749 749
         }
750 750
 
751 751
         //setup the question data
752
-        $data[ 'ID' ]                     = $question_id;
753
-        $data[ 'title' ]                  = get_the_title( $question_id );
754
-        $data[ 'content' ]                = get_post( $question_id )->post_content;
755
-        $data[ 'quiz_id' ]                = $quiz_id;
756
-        $data[ 'lesson_id' ]              = Sensei()->quiz->get_lesson_id( $quiz_id );
757
-        $data[ 'type' ]                   = Sensei()->question->get_question_type( $question_id );
758
-        $data[ 'question_grade' ]         = Sensei()->question->get_question_grade(  $question_id  );
759
-        $data[ 'user_question_grade' ]    = Sensei()->quiz->get_user_question_grade( $lesson_id,  $question_id , get_current_user_id());
760
-        $data[ 'question_right_answer' ]  = get_post_meta( $question_id , '_question_right_answer', true );
761
-        $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true );
762
-        $data[ 'user_answer_entry' ]      = Sensei()->quiz->get_user_question_answer( $lesson_id,  $question_id , get_current_user_id() );
763
-        $data[ 'lesson_completed' ]       = WooThemes_Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) );
764
-        $data[ 'quiz_grade_type' ]        = get_post_meta( $quiz_id , '_quiz_grade_type', true );
765
-        $data[ 'reset_quiz_allowed' ]     = $reset_allowed;
766
-        $data[ 'lesson_complete' ]        = $user_lesson_complete;
752
+        $data['ID']                     = $question_id;
753
+        $data['title']                  = get_the_title($question_id);
754
+        $data['content']                = get_post($question_id)->post_content;
755
+        $data['quiz_id']                = $quiz_id;
756
+        $data['lesson_id']              = Sensei()->quiz->get_lesson_id($quiz_id);
757
+        $data['type']                   = Sensei()->question->get_question_type($question_id);
758
+        $data['question_grade']         = Sensei()->question->get_question_grade($question_id);
759
+        $data['user_question_grade']    = Sensei()->quiz->get_user_question_grade($lesson_id, $question_id, get_current_user_id());
760
+        $data['question_right_answer']  = get_post_meta($question_id, '_question_right_answer', true);
761
+        $data['question_wrong_answers'] = get_post_meta($question_id, '_question_wrong_answers', true);
762
+        $data['user_answer_entry']      = Sensei()->quiz->get_user_question_answer($lesson_id, $question_id, get_current_user_id());
763
+        $data['lesson_completed']       = WooThemes_Sensei_Utils::user_completed_course($lesson_id, get_current_user_id( ));
764
+        $data['quiz_grade_type']        = get_post_meta($quiz_id, '_quiz_grade_type', true);
765
+        $data['reset_quiz_allowed']     = $reset_allowed;
766
+        $data['lesson_complete']        = $user_lesson_complete;
767 767
 
768 768
         /**
769 769
          * Filter the question template data. This filter fires  in
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
          * @param string $question_id
778 778
          * @param string $quiz_id
779 779
          */
780
-        return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id );
780
+        return apply_filters('sensei_get_question_template_data', $data, $question_id, $quiz_id);
781 781
 
782 782
     }
783 783
 
@@ -793,28 +793,28 @@  discard block
 block discarded – undo
793 793
      *
794 794
      * @return array()
795 795
      */
796
-    public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){
796
+    public static function file_upload_load_question_data($question_data, $question_id, $quiz_id) {
797 797
 
798 798
 
799
-        if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) {
799
+        if ('file-upload' == Sensei()->question->get_question_type($question_id)) {
800 800
 
801 801
             // Get uploaded file
802
-            $attachment_id = $question_data[ 'user_answer_entry' ];
802
+            $attachment_id = $question_data['user_answer_entry'];
803 803
             $answer_media_url = $answer_media_filename = '';
804 804
 
805 805
 
806 806
             $question_helptext = '';
807
-            if( isset( $question_data['question_wrong_answers'][0] ) ) {
807
+            if (isset($question_data['question_wrong_answers'][0])) {
808 808
 
809
-                $question_helptext =  $question_data['question_wrong_answers'][0];
809
+                $question_helptext = $question_data['question_wrong_answers'][0];
810 810
 
811 811
             }
812 812
 
813 813
 
814
-            if( 0 < intval( $attachment_id ) ) {
814
+            if (0 < intval($attachment_id)) {
815 815
 
816
-                $answer_media_url = wp_get_attachment_url( $attachment_id );
817
-                $answer_media_filename = basename( $answer_media_url );
816
+                $answer_media_url = wp_get_attachment_url($attachment_id);
817
+                $answer_media_filename = basename($answer_media_url);
818 818
 
819 819
             }
820 820
 
@@ -822,11 +822,11 @@  discard block
 block discarded – undo
822 822
             // Get max upload file size, formatted for display
823 823
             // Code copied from wp-admin/includes/media.php:1515
824 824
             $upload_size_unit = $max_upload_size = wp_max_upload_size();
825
-            $sizes = array( 'KB', 'MB', 'GB' );
826
-            for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) {
825
+            $sizes = array('KB', 'MB', 'GB');
826
+            for ($u = -1; $upload_size_unit > 1024 && $u < count($sizes) - 1; $u++) {
827 827
                 $upload_size_unit /= 1024;
828 828
             }
829
-            if ( $u < 0 ) {
829
+            if ($u < 0) {
830 830
 
831 831
                 $upload_size_unit = 0;
832 832
                 $u = 0;
@@ -836,14 +836,14 @@  discard block
 block discarded – undo
836 836
                 $upload_size_unit = (int) $upload_size_unit;
837 837
 
838 838
             }
839
-            $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) );
839
+            $max_upload_size = sprintf(__('Maximum upload file size: %d%s'), esc_html($upload_size_unit), esc_html($sizes[$u]));
840 840
 
841 841
             // Assemble all the data needed by the file upload template
842
-            $question_data[ 'answer_media_url' ]      = $answer_media_url;
843
-            $question_data[ 'answer_media_filename' ] = $answer_media_filename;
844
-            $question_data[ 'max_upload_size' ]       = $max_upload_size;
842
+            $question_data['answer_media_url']      = $answer_media_url;
843
+            $question_data['answer_media_filename'] = $answer_media_filename;
844
+            $question_data['max_upload_size']       = $max_upload_size;
845 845
 
846
-            $question_data[ 'question_helptext' ]     = $question_helptext;
846
+            $question_data['question_helptext']     = $question_helptext;
847 847
 
848 848
         }// end if is file upload type
849 849
 
@@ -863,27 +863,27 @@  discard block
 block discarded – undo
863 863
      *
864 864
      * @return array()
865 865
      */
866
-    public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){
866
+    public static function multiple_choice_load_question_data($question_data, $question_id, $quiz_id) {
867 867
 
868
-        if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) {
868
+        if ('multiple-choice' == Sensei()->question->get_question_type($question_id)) {
869 869
 
870 870
 
871 871
             $answer_type = 'radio';
872
-            if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) {
872
+            if (is_array($question_data['question_right_answer']) && (1 < count($question_data['question_right_answer']))) {
873 873
 
874 874
                 $answer_type = 'checkbox';
875 875
 
876 876
             }
877 877
 
878 878
             // Merge right and wrong answers
879
-            if ( is_array( $question_data[ 'question_right_answer' ] ) ) {
879
+            if (is_array($question_data['question_right_answer'])) {
880 880
 
881
-                $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] );
881
+                $merged_options = array_merge($question_data['question_wrong_answers'], $question_data['question_right_answer']);
882 882
 
883
-            }  else {
883
+            } else {
884 884
 
885
-                array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] );
886
-                $merged_options = $question_data[ 'question_wrong_answers' ];
885
+                array_push($question_data['question_wrong_answers'], $question_data['question_right_answer']);
886
+                $merged_options = $question_data['question_wrong_answers'];
887 887
 
888 888
             }
889 889
 
@@ -891,24 +891,24 @@  discard block
 block discarded – undo
891 891
             $question_answers_options = array();
892 892
             $count = 0;
893 893
 
894
-            foreach( $merged_options as $answer ) {
894
+            foreach ($merged_options as $answer) {
895 895
 
896 896
                 $count++;
897 897
                 $question_option = array();
898 898
 
899
-                if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' )
900
-                    || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' )
901
-                    || ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ]  && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) {
899
+                if (($question_data['lesson_completed'] && $question_data['user_quiz_grade'] != '')
900
+                    || ($question_data['lesson_completed'] && ! $question_data['reset_quiz_allowed'] && $question_data['user_quiz_grade'] != '')
901
+                    || ('auto' == $question_data['quiz_grade_type'] && ! $question_data['reset_quiz_allowed'] && ! empty($question_data['user_quiz_grade']))) {
902 902
 
903 903
                     $user_correct = false;
904 904
 
905 905
 
906 906
                     // For zero grade mark as 'correct' but add no classes
907
-                    if ( 0 == $question_data[ 'question_grade' ] ) {
907
+                    if (0 == $question_data['question_grade']) {
908 908
 
909 909
                         $user_correct = true;
910 910
 
911
-                    }  else if( $question_data[ 'user_question_grade' ] > 0 ) {
911
+                    } else if ($question_data['user_question_grade'] > 0) {
912 912
 
913 913
                         $user_correct = true;
914 914
 
@@ -918,20 +918,20 @@  discard block
 block discarded – undo
918 918
 
919 919
                 // setup the option specific classes
920 920
                 $answer_class = '';
921
-                if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) {
922
-                    if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) {
921
+                if (isset($user_correct) && 0 < $question_data['question_grade']) {
922
+                    if (is_array($question_data['question_right_answer']) && in_array($answer, $question_data['question_right_answer'])) {
923 923
 
924 924
                         $answer_class .= ' right_answer';
925 925
 
926
-                    }  elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) {
926
+                    }  elseif ( ! is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer) {
927 927
 
928 928
                         $answer_class .= ' right_answer';
929 929
 
930
-                    } elseif( ( is_array( $question_data['user_answer_entry']  ) && in_array($answer, $question_data['user_answer_entry'] ) )
931
-                        ||  ( !  $question_data['user_answer_entry'] &&  $question_data['user_answer_entry'] == $answer ) ) {
930
+                    } elseif ((is_array($question_data['user_answer_entry']) && in_array($answer, $question_data['user_answer_entry']))
931
+                        ||  ( ! $question_data['user_answer_entry'] && $question_data['user_answer_entry'] == $answer)) {
932 932
 
933 933
                         $answer_class = 'user_wrong';
934
-                        if( $user_correct ) {
934
+                        if ($user_correct) {
935 935
 
936 936
                             $answer_class = 'user_right';
937 937
 
@@ -943,26 +943,26 @@  discard block
 block discarded – undo
943 943
 
944 944
                 // determine if the current option must be checked
945 945
                 $checked = '';
946
-                if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) {
947
-                    if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) {
946
+                if (isset($question_data['user_answer_entry']) && 0 < count($question_data['user_answer_entry'])) {
947
+                    if (is_array($question_data['user_answer_entry']) && in_array($answer, $question_data['user_answer_entry'])) {
948 948
 
949 949
                         $checked = 'checked="checked"';
950 950
 
951
-                    } elseif ( !is_array( $question_data['user_answer_entry'] ) ) {
951
+                    } elseif ( ! is_array($question_data['user_answer_entry'])) {
952 952
 
953
-                        $checked = checked( $answer, $question_data['user_answer_entry'] , false );
953
+                        $checked = checked($answer, $question_data['user_answer_entry'], false);
954 954
 
955 955
                     }
956 956
 
957 957
                 } // End If Statement
958 958
 
959 959
                 //Load the answer option data
960
-                $question_option[ 'ID' ]          = Sensei()->lesson->get_answer_id( $answer );
961
-                $question_option[ 'answer' ]      = $answer;
962
-                $question_option[ 'option_class'] = $answer_class;
963
-                $question_option[ 'checked']      = $checked;
964
-                $question_option[ 'count' ]       = $count;
965
-                $question_option[ 'type' ] = $answer_type;
960
+                $question_option['ID']          = Sensei()->lesson->get_answer_id($answer);
961
+                $question_option['answer']      = $answer;
962
+                $question_option['option_class'] = $answer_class;
963
+                $question_option['checked']      = $checked;
964
+                $question_option['count']       = $count;
965
+                $question_option['type'] = $answer_type;
966 966
 
967 967
                 // add the speci  fic option to the list of options for this question
968 968
                 $question_answers_options[] = $question_option;
@@ -972,47 +972,47 @@  discard block
 block discarded – undo
972 972
 
973 973
             // Shuffle the array depending on the settings
974 974
             $answer_options_sorted = array();
975
-            $random_order = get_post_meta( $question_data['ID'], '_random_order', true );
976
-            if(  $random_order && $random_order == 'yes' ) {
975
+            $random_order = get_post_meta($question_data['ID'], '_random_order', true);
976
+            if ($random_order && $random_order == 'yes') {
977 977
 
978 978
                 $answer_options_sorted = $question_answers_options;
979
-                shuffle( $answer_options_sorted );
979
+                shuffle($answer_options_sorted);
980 980
 
981 981
             } else {
982 982
 
983 983
                 $answer_order = array();
984
-                $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true );
985
-                if( $answer_order_string ) {
984
+                $answer_order_string = get_post_meta($question_data['ID'], '_answer_order', true);
985
+                if ($answer_order_string) {
986 986
 
987
-                    $answer_order = array_filter( explode( ',', $answer_order_string ) );
988
-                    if( count( $answer_order ) > 0 ) {
987
+                    $answer_order = array_filter(explode(',', $answer_order_string));
988
+                    if (count($answer_order) > 0) {
989 989
 
990
-                        foreach( $answer_order as $answer_id ) {
990
+                        foreach ($answer_order as $answer_id) {
991 991
 
992
-                            if( isset( $question_answers_options[ $answer_id ] ) ) {
992
+                            if (isset($question_answers_options[$answer_id])) {
993 993
 
994
-                                $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ];
995
-                                unset( $question_answers_options[ $answer_id ] );
994
+                                $answer_options_sorted[$answer_id] = $question_answers_options[$answer_id];
995
+                                unset($question_answers_options[$answer_id]);
996 996
 
997 997
                             }
998 998
 
999 999
                         }
1000 1000
 
1001
-                        if( count( $question_answers_options ) > 0 ) {
1002
-                            foreach( $question_answers_options as $id => $answer ) {
1001
+                        if (count($question_answers_options) > 0) {
1002
+                            foreach ($question_answers_options as $id => $answer) {
1003 1003
 
1004
-                                $answer_options_sorted[ $id ] = $answer;
1004
+                                $answer_options_sorted[$id] = $answer;
1005 1005
 
1006 1006
                             }
1007 1007
                         }
1008 1008
 
1009
-                    }else{
1009
+                    } else {
1010 1010
 
1011 1011
                         $answer_options_sorted = $question_answers_options;
1012 1012
 
1013 1013
                     }
1014 1014
 
1015
-                }else{
1015
+                } else {
1016 1016
 
1017 1017
                     $answer_options_sorted = $question_answers_options;
1018 1018
 
@@ -1022,7 +1022,7 @@  discard block
 block discarded – undo
1022 1022
 
1023 1023
 
1024 1024
             // assemble and setup the data for the templates data array
1025
-            $question_data[ 'answer_options' ]    =  $answer_options_sorted;
1025
+            $question_data['answer_options'] = $answer_options_sorted;
1026 1026
 
1027 1027
         }
1028 1028
 
@@ -1042,14 +1042,14 @@  discard block
 block discarded – undo
1042 1042
      *
1043 1043
      * @return array()
1044 1044
      */
1045
-    public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){
1045
+    public static function gap_fill_load_question_data($question_data, $question_id, $quiz_id) {
1046 1046
 
1047
-        if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) {
1047
+        if ('gap-fill' == Sensei()->question->get_question_type($question_id)) {
1048 1048
 
1049
-            $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] );
1050
-            $question_data[ 'gapfill_pre' ]  = isset( $gapfill_array[0] ) ? $gapfill_array[0] : '';
1051
-            $question_data[ 'gapfill_gap' ]  = isset( $gapfill_array[1] ) ? $gapfill_array[1] : '';
1052
-            $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : '';
1049
+            $gapfill_array = explode('||', $question_data['question_right_answer']);
1050
+            $question_data['gapfill_pre']  = isset($gapfill_array[0]) ? $gapfill_array[0] : '';
1051
+            $question_data['gapfill_gap']  = isset($gapfill_array[1]) ? $gapfill_array[1] : '';
1052
+            $question_data['gapfill_post'] = isset($gapfill_array[2]) ? $gapfill_array[2] : '';
1053 1053
 
1054 1054
         }
1055 1055
 
@@ -1064,32 +1064,32 @@  discard block
 block discarded – undo
1064 1064
      * @param $question_id
1065 1065
      * @return string $correct_answer or empty
1066 1066
      */
1067
-    public static function get_correct_answer( $question_id ){
1067
+    public static function get_correct_answer($question_id) {
1068 1068
 
1069
-        $right_answer = get_post_meta( $question_id, '_question_right_answer', true );
1070
-        $type = Sensei()->question->get_question_type( $question_id );
1071
-        $type_name = __( 'Multiple Choice', 'woothemes-sensei' );
1069
+        $right_answer = get_post_meta($question_id, '_question_right_answer', true);
1070
+        $type = Sensei()->question->get_question_type($question_id);
1071
+        $type_name = __('Multiple Choice', 'woothemes-sensei');
1072 1072
         $grade_type = 'manual-grade';
1073 1073
 
1074
-        if ('boolean'== $type ) {
1074
+        if ('boolean' == $type) {
1075 1075
 
1076 1076
             $right_answer = ucfirst($right_answer);
1077 1077
 
1078
-        }elseif( 'multiple-choice' == $type ) {
1078
+        }elseif ('multiple-choice' == $type) {
1079 1079
 
1080 1080
             $right_answer = (array) $right_answer;
1081
-            $right_answer = implode( ', ', $right_answer );
1081
+            $right_answer = implode(', ', $right_answer);
1082 1082
 
1083
-        }elseif( 'gap-fill' == $type ) {
1083
+        }elseif ('gap-fill' == $type) {
1084 1084
 
1085
-            $right_answer_array = explode( '||', $right_answer );
1086
-            if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; }
1087
-            if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; }
1088
-            if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; }
1085
+            $right_answer_array = explode('||', $right_answer);
1086
+            if (isset($right_answer_array[0])) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; }
1087
+            if (isset($right_answer_array[1])) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; }
1088
+            if (isset($right_answer_array[2])) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; }
1089 1089
 
1090
-            $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post;
1090
+            $right_answer = $gapfill_pre.' <span class="highlight">'.$gapfill_gap.'</span> '.$gapfill_post;
1091 1091
 
1092
-        }else{
1092
+        } else {
1093 1093
 
1094 1094
             // for non auto gradable question types no answer should be returned.
1095 1095
             $right_answer = '';
@@ -1107,4 +1107,4 @@  discard block
 block discarded – undo
1107 1107
  * for backward compatibility
1108 1108
  * @since 1.9.0
1109 1109
  */
1110
-class WooThemes_Sensei_Question extends Sensei_Question{}
1110
+class WooThemes_Sensei_Question extends Sensei_Question {}
Please login to merge, or discard this patch.
Braces   +15 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Question Class
@@ -211,7 +214,9 @@  discard block
 block discarded – undo
211 214
 
212 215
 			$lesson_id = get_post_meta( $quiz, '_quiz_lesson', true );
213 216
 
214
-			if( ! $lesson_id ) continue;
217
+			if( ! $lesson_id ) {
218
+				continue;
219
+			}
215 220
 
216 221
 			$lessons[ $lesson_id ]['title'] = get_the_title( $lesson_id );
217 222
 			$lessons[ $lesson_id ]['link'] = admin_url( 'post.php?post=' . $lesson_id . '&action=edit' );
@@ -880,7 +885,7 @@  discard block
 block discarded – undo
880 885
 
881 886
                 $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] );
882 887
 
883
-            }  else {
888
+            } else {
884 889
 
885 890
                 array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] );
886 891
                 $merged_options = $question_data[ 'question_wrong_answers' ];
@@ -908,7 +913,7 @@  discard block
 block discarded – undo
908 913
 
909 914
                         $user_correct = true;
910 915
 
911
-                    }  else if( $question_data[ 'user_question_grade' ] > 0 ) {
916
+                    } else if( $question_data[ 'user_question_grade' ] > 0 ) {
912 917
 
913 918
                         $user_correct = true;
914 919
 
@@ -923,7 +928,7 @@  discard block
 block discarded – undo
923 928
 
924 929
                         $answer_class .= ' right_answer';
925 930
 
926
-                    }  elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) {
931
+                    } elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) {
927 932
 
928 933
                         $answer_class .= ' right_answer';
929 934
 
@@ -1006,13 +1011,13 @@  discard block
 block discarded – undo
1006 1011
                             }
1007 1012
                         }
1008 1013
 
1009
-                    }else{
1014
+                    } else{
1010 1015
 
1011 1016
                         $answer_options_sorted = $question_answers_options;
1012 1017
 
1013 1018
                     }
1014 1019
 
1015
-                }else{
1020
+                } else{
1016 1021
 
1017 1022
                     $answer_options_sorted = $question_answers_options;
1018 1023
 
@@ -1075,12 +1080,12 @@  discard block
 block discarded – undo
1075 1080
 
1076 1081
             $right_answer = ucfirst($right_answer);
1077 1082
 
1078
-        }elseif( 'multiple-choice' == $type ) {
1083
+        } elseif( 'multiple-choice' == $type ) {
1079 1084
 
1080 1085
             $right_answer = (array) $right_answer;
1081 1086
             $right_answer = implode( ', ', $right_answer );
1082 1087
 
1083
-        }elseif( 'gap-fill' == $type ) {
1088
+        } elseif( 'gap-fill' == $type ) {
1084 1089
 
1085 1090
             $right_answer_array = explode( '||', $right_answer );
1086 1091
             if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; }
@@ -1089,7 +1094,7 @@  discard block
 block discarded – undo
1089 1094
 
1090 1095
             $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post;
1091 1096
 
1092
-        }else{
1097
+        } else{
1093 1098
 
1094 1099
             // for non auto gradable question types no answer should be returned.
1095 1100
             $right_answer = '';
Please login to merge, or discard this patch.
includes/class-sensei-quiz.php 4 patches
Doc Comments   +4 added lines, -5 removed lines patch added patch discarded remove patch
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
      *
124 124
      * This function hooks into the quiz page and accepts the answer form save post.
125 125
      * @since 1.7.3
126
-     * @return bool $saved;
126
+     * @return boolean|null $saved;
127 127
      */
128 128
     public function user_save_quiz_answers_listener(){
129 129
 
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 	 * @param int $lesson_id
215 215
 	 * @param int $user_id
216 216
 	 *
217
-	 * @return array $answers or false
217
+	 * @return boolean $answers or false
218 218
 	 */
219 219
 	public function get_user_answers( $lesson_id, $user_id ){
220 220
 
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
       *      @type int $question_id
708 708
       *      @type int $question_grade
709 709
       * }
710
-      * @param $lesson_id
710
+      * @param integer $lesson_id
711 711
       * @param $user_id (Optional) will use the current user if not supplied
712 712
       *
713 713
       * @return bool
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
       *
755 755
       * @since 1.7.4
756 756
       *
757
-      * @param $lesson_id
757
+      * @param integer $lesson_id
758 758
       * @param $user_id (Optional) will use the current user if not supplied
759 759
       *
760 760
       * @return array $user_quiz_grades or false if none exists for this users
@@ -1090,7 +1090,6 @@  discard block
 block discarded – undo
1090 1090
       * Filter the single title and add the Quiz to it.
1091 1091
       *
1092 1092
       * @param string $title
1093
-      * @param int $id title post id
1094 1093
       * @return string $quiz_title
1095 1094
       */
1096 1095
      public static function single_quiz_title( $title, $post_id ){
Please login to merge, or discard this patch.
Indentation   +882 added lines, -882 removed lines patch added patch discarded remove patch
@@ -31,63 +31,63 @@  discard block
 block discarded – undo
31 31
 		// listen to the reset button click
32 32
 		add_action( 'template_redirect', array( $this, 'reset_button_click_listener'  ) );
33 33
 
34
-        // fire the complete quiz button submit for grading action
35
-        add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) );
34
+		// fire the complete quiz button submit for grading action
35
+		add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) );
36 36
 
37 37
 		// fire the save user answers quiz button click responder
38 38
 		add_action( 'sensei_complete_quiz', array( $this, 'user_save_quiz_answers_listener' ) );
39 39
 
40
-        // fire the load global data function
41
-        add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 );
40
+		// fire the load global data function
41
+		add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 );
42 42
 
43
-        add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') );
43
+		add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') );
44 44
 
45 45
 
46
-    } // End __construct()
46
+	} // End __construct()
47 47
 
48 48
 	/**
49
-	* Update the quiz author when the lesson post type is save
50
-	*
51
-	* @param int $post_id
52
-	* @return void
53
-	*/
49
+	 * Update the quiz author when the lesson post type is save
50
+	 *
51
+	 * @param int $post_id
52
+	 * @return void
53
+	 */
54 54
 	public function update_author( $post_id ){
55 55
 
56 56
 
57 57
 		// If this isn't a 'lesson' post, don't update it.
58
-        // if this is a revision don't save it
59
-	    if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type']
60
-            || wp_is_post_revision( $post_id ) ) {
58
+		// if this is a revision don't save it
59
+		if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type']
60
+			|| wp_is_post_revision( $post_id ) ) {
61 61
 
62
-                return;
62
+				return;
63 63
 
64
-        }
65
-	    // get the lesson author id to be use late
66
-	    $saved_post = get_post( $post_id );
67
-	    $new_lesson_author_id =  $saved_post->post_author;
64
+		}
65
+		// get the lesson author id to be use late
66
+		$saved_post = get_post( $post_id );
67
+		$new_lesson_author_id =  $saved_post->post_author;
68 68
 
69
-	    //get the lessons quiz
69
+		//get the lessons quiz
70 70
 		$lesson_quizzes = Sensei()->lesson->lesson_quizzes( $post_id );
71
-	    foreach ( (array) $lesson_quizzes as $quiz_item ) {
71
+		foreach ( (array) $lesson_quizzes as $quiz_item ) {
72 72
 
73
-	    	if( ! $quiz_item ) {
74
-	    		continue;
75
-	    	}
73
+			if( ! $quiz_item ) {
74
+				continue;
75
+			}
76 76
 
77
-		    // setup the quiz items new author value
77
+			// setup the quiz items new author value
78 78
 			$my_post = array(
79
-			      'ID'           => $quiz_item,
80
-			      'post_author' =>  $new_lesson_author_id
79
+				  'ID'           => $quiz_item,
80
+				  'post_author' =>  $new_lesson_author_id
81 81
 			);
82 82
 
83
-            // remove the action so that it doesn't fire again
84
-            remove_action( 'save_post', array( $this, 'update_author' ));
83
+			// remove the action so that it doesn't fire again
84
+			remove_action( 'save_post', array( $this, 'update_author' ));
85 85
 
86 86
 			// Update the post into the database
87 87
 		  	wp_update_post( $my_post );
88
-	    }
88
+		}
89 89
 
90
-	    return;
90
+		return;
91 91
 	}// end update_author
92 92
 
93 93
 
@@ -118,32 +118,32 @@  discard block
 block discarded – undo
118 118
 	} // end lesson
119 119
 
120 120
 
121
-    /**
122
-     * user_save_quiz_answers_listener
123
-     *
124
-     * This function hooks into the quiz page and accepts the answer form save post.
125
-     * @since 1.7.3
126
-     * @return bool $saved;
127
-     */
128
-    public function user_save_quiz_answers_listener(){
121
+	/**
122
+	 * user_save_quiz_answers_listener
123
+	 *
124
+	 * This function hooks into the quiz page and accepts the answer form save post.
125
+	 * @since 1.7.3
126
+	 * @return bool $saved;
127
+	 */
128
+	public function user_save_quiz_answers_listener(){
129 129
 
130
-        if( ! isset( $_POST[ 'quiz_save' ])
131
-            || !isset( $_POST[ 'sensei_question' ] )
132
-            || empty( $_POST[ 'sensei_question' ] )
133
-            ||  ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce'  ) > 1 ) {
134
-            return;
135
-        }
130
+		if( ! isset( $_POST[ 'quiz_save' ])
131
+			|| !isset( $_POST[ 'sensei_question' ] )
132
+			|| empty( $_POST[ 'sensei_question' ] )
133
+			||  ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce'  ) > 1 ) {
134
+			return;
135
+		}
136 136
 
137
-        global $post;
138
-        $lesson_id = $this->get_lesson_id( $post->ID );
139
-        $quiz_answers = $_POST[ 'sensei_question' ];
140
-        // call the save function
141
-        self::save_user_answers( $quiz_answers, $_FILES , $lesson_id  , get_current_user_id() );
137
+		global $post;
138
+		$lesson_id = $this->get_lesson_id( $post->ID );
139
+		$quiz_answers = $_POST[ 'sensei_question' ];
140
+		// call the save function
141
+		self::save_user_answers( $quiz_answers, $_FILES , $lesson_id  , get_current_user_id() );
142 142
 
143
-        // remove the hook as it should only fire once per click
144
-        remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' );
143
+		// remove the hook as it should only fire once per click
144
+		remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' );
145 145
 
146
-    } // end user_save_quiz_answers_listener
146
+	} // end user_save_quiz_answers_listener
147 147
 
148 148
 	/**
149 149
 	 * Save the user answers for the given lesson's quiz
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 * @access public
155 155
 	 *
156 156
 	 * @param array $quiz_answers
157
-     * @param array $files from global $_FILES
157
+	 * @param array $files from global $_FILES
158 158
 	 * @param int $lesson_id
159 159
 	 * @param int $user_id
160 160
 	 *
@@ -162,11 +162,11 @@  discard block
 block discarded – undo
162 162
 	 */
163 163
 	public static function save_user_answers( $quiz_answers, $files = array(), $lesson_id , $user_id = 0 ){
164 164
 
165
-        if( ! ( $user_id > 0 ) ){
166
-            $user_id = get_current_user_id();
167
-        }
165
+		if( ! ( $user_id > 0 ) ){
166
+			$user_id = get_current_user_id();
167
+		}
168 168
 
169
-        // make sure the parameters are valid before continuing
169
+		// make sure the parameters are valid before continuing
170 170
 		if( empty( $lesson_id ) || empty( $user_id )
171 171
 			|| 'lesson' != get_post_type( $lesson_id )
172 172
 			||!get_userdata( $user_id )
@@ -177,25 +177,25 @@  discard block
 block discarded – undo
177 177
 		}
178 178
 
179 179
 
180
-        // start the lesson before saving the data in case the user has not started the lesson
181
-        $activity_logged = WooThemes_Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
180
+		// start the lesson before saving the data in case the user has not started the lesson
181
+		$activity_logged = WooThemes_Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
182 182
 
183 183
 		//prepare the answers
184 184
 		$prepared_answers = self::prepare_form_submitted_answers( $quiz_answers , $files );
185 185
 
186 186
 		// save the user data
187
-        $answers_saved = WooThemes_Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ;
187
+		$answers_saved = WooThemes_Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ;
188 188
 
189 189
 		// were the answers saved correctly?
190 190
 		if( intval( $answers_saved ) > 0){
191 191
 
192
-            // save transient to make retrieval faster
193
-            $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
194
-            set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS );
192
+			// save transient to make retrieval faster
193
+			$transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
194
+			set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS );
195 195
 
196
-            // update the message showed to user
197
-            Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' )  . '</div>';
198
-        }
196
+			// update the message showed to user
197
+			Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' )  . '</div>';
198
+		}
199 199
 
200 200
 		return $answers_saved;
201 201
 
@@ -203,9 +203,9 @@  discard block
 block discarded – undo
203 203
 
204 204
 	/**
205 205
 	 * Get the user answers for the given lesson's quiz.
206
-     *
207
-     * This function returns the data that is stored on the lesson as meta and is not compatible with
208
-     * retrieving data for quiz answer before sensei 1.7.4
206
+	 *
207
+	 * This function returns the data that is stored on the lesson as meta and is not compatible with
208
+	 * retrieving data for quiz answer before sensei 1.7.4
209 209
 	 *
210 210
 	 *
211 211
 	 * @since 1.7.4
@@ -225,27 +225,27 @@  discard block
 block discarded – undo
225 225
 			return false;
226 226
 		}
227 227
 
228
-        // save some time and get the transient cached data
229
-        $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
230
-        $transient_cached_answers = get_transient( $transient_key );
228
+		// save some time and get the transient cached data
229
+		$transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
230
+		$transient_cached_answers = get_transient( $transient_key );
231 231
 
232
-        // return the transient or get the values get the values from the comment meta
233
-        if( !empty( $transient_cached_answers  ) && false != $transient_cached_answers ){
232
+		// return the transient or get the values get the values from the comment meta
233
+		if( !empty( $transient_cached_answers  ) && false != $transient_cached_answers ){
234 234
 
235
-            $encoded_user_answers = $transient_cached_answers;
235
+			$encoded_user_answers = $transient_cached_answers;
236 236
 
237
-        }else{
237
+		}else{
238 238
 
239
-            $encoded_user_answers = WooThemes_Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id  , $user_id );
239
+			$encoded_user_answers = WooThemes_Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id  , $user_id );
240 240
 
241
-        } // end if transient check
241
+		} // end if transient check
242 242
 
243 243
 		if( ! is_array( $encoded_user_answers ) ){
244 244
 			return false;
245 245
 		}
246 246
 
247
-        //set the transient with the new valid data for faster retrieval in future
248
-        set_transient( $transient_key,  $encoded_user_answers, 10 * DAY_IN_SECONDS);
247
+		//set the transient with the new valid data for faster retrieval in future
248
+		set_transient( $transient_key,  $encoded_user_answers, 10 * DAY_IN_SECONDS);
249 249
 
250 250
 		// decode an unserialize all answers
251 251
 		foreach( $encoded_user_answers as $question_id => $encoded_answer ) {
@@ -279,8 +279,8 @@  discard block
 block discarded – undo
279 279
 		$current_quiz_id = $post->ID;
280 280
 		$lesson_id = $this->get_lesson_id( $current_quiz_id );
281 281
 
282
-        // reset all user data
283
-        $this->reset_user_lesson_data( $lesson_id, get_current_user_id() );
282
+		// reset all user data
283
+		$this->reset_user_lesson_data( $lesson_id, get_current_user_id() );
284 284
 
285 285
 		//this function should only run once
286 286
 		remove_action( 'template_redirect', array( $this, 'reset_button_click_listener'  ) );
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 	 * Complete/ submit  quiz hooked function
292 292
 	 *
293 293
 	 * This function listens to the complete button submit action and processes the users submitted answers
294
-     * not that this function submits the given users quiz answers for grading.
294
+	 * not that this function submits the given users quiz answers for grading.
295 295
 	 *
296 296
 	 * @since  1.7.4
297 297
 	 * @access public
@@ -301,90 +301,90 @@  discard block
 block discarded – undo
301 301
 	 */
302 302
 	public function user_quiz_submit_listener() {
303 303
 
304
-        // only respond to valid quiz completion submissions
305
-        if( ! isset( $_POST[ 'quiz_complete' ])
306
-            || !isset( $_POST[ 'sensei_question' ] )
307
-            || empty( $_POST[ 'sensei_question' ] )
308
-            ||  ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce'  ) > 1 ) {
309
-            return;
310
-        }
304
+		// only respond to valid quiz completion submissions
305
+		if( ! isset( $_POST[ 'quiz_complete' ])
306
+			|| !isset( $_POST[ 'sensei_question' ] )
307
+			|| empty( $_POST[ 'sensei_question' ] )
308
+			||  ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce'  ) > 1 ) {
309
+			return;
310
+		}
311 311
 
312
-        global $post, $current_user;
313
-        $lesson_id = $this->get_lesson_id( $post->ID );
314
-        $quiz_answers = $_POST[ 'sensei_question' ];
312
+		global $post, $current_user;
313
+		$lesson_id = $this->get_lesson_id( $post->ID );
314
+		$quiz_answers = $_POST[ 'sensei_question' ];
315 315
 
316
-        self::submit_answers_for_grading( $quiz_answers, $_FILES ,  $lesson_id  , $current_user->ID );
316
+		self::submit_answers_for_grading( $quiz_answers, $_FILES ,  $lesson_id  , $current_user->ID );
317 317
 
318 318
 	} // End sensei_complete_quiz()
319 319
 
320
-    /**
321
-     * This function set's up the data need for the quiz page
322
-     *
323
-     * This function hooks into sensei_complete_quiz and load the global data for the
324
-     * current quiz.
325
-     *
326
-     * @since 1.7.4
327
-     * @access public
328
-     *
329
-     */
330
-    public function load_global_quiz_data(){
320
+	/**
321
+	 * This function set's up the data need for the quiz page
322
+	 *
323
+	 * This function hooks into sensei_complete_quiz and load the global data for the
324
+	 * current quiz.
325
+	 *
326
+	 * @since 1.7.4
327
+	 * @access public
328
+	 *
329
+	 */
330
+	public function load_global_quiz_data(){
331 331
 
332
-        global  $post, $current_user;
333
-        $this->data = new stdClass();
332
+		global  $post, $current_user;
333
+		$this->data = new stdClass();
334 334
 
335
-        // Default grade
336
-        $grade = 0;
335
+		// Default grade
336
+		$grade = 0;
337 337
 
338
-        // Get Quiz Questions
339
-        $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID );
338
+		// Get Quiz Questions
339
+		$lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID );
340 340
 
341
-        $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) );
341
+		$quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) );
342 342
 
343
-        // Get quiz grade type
344
-        $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true );
343
+		// Get quiz grade type
344
+		$quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true );
345 345
 
346
-        // Get quiz pass setting
347
-        $pass_required = get_post_meta( $post->ID, '_pass_required', true );
346
+		// Get quiz pass setting
347
+		$pass_required = get_post_meta( $post->ID, '_pass_required', true );
348 348
 
349
-        // Get quiz pass mark
350
-        $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) );
349
+		// Get quiz pass mark
350
+		$quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) );
351 351
 
352
-        // Get latest quiz answers and grades
353
-        $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID );
354
-        $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() );
355
-        $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID );
356
-        $user_quiz_grade = 0;
357
-        if( isset( $user_lesson_status->comment_ID ) ) {
358
-            $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
359
-        }
352
+		// Get latest quiz answers and grades
353
+		$lesson_id = Sensei()->quiz->get_lesson_id( $post->ID );
354
+		$user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() );
355
+		$user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID );
356
+		$user_quiz_grade = 0;
357
+		if( isset( $user_lesson_status->comment_ID ) ) {
358
+			$user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
359
+		}
360 360
 
361
-        if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); }
361
+		if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); }
362 362
 
363
-        // Check again that the lesson is complete
364
-        $user_lesson_end = WooThemes_Sensei_Utils::user_completed_lesson( $user_lesson_status );
365
-        $user_lesson_complete = false;
366
-        if ( $user_lesson_end ) {
367
-            $user_lesson_complete = true;
368
-        } // End If Statement
363
+		// Check again that the lesson is complete
364
+		$user_lesson_end = WooThemes_Sensei_Utils::user_completed_lesson( $user_lesson_status );
365
+		$user_lesson_complete = false;
366
+		if ( $user_lesson_end ) {
367
+			$user_lesson_complete = true;
368
+		} // End If Statement
369 369
 
370
-        $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true );
371
-        //backwards compatibility
372
-        if( 'on' == $reset_allowed ) {
373
-            $reset_allowed = 1;
374
-        }
370
+		$reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true );
371
+		//backwards compatibility
372
+		if( 'on' == $reset_allowed ) {
373
+			$reset_allowed = 1;
374
+		}
375 375
 
376
-        // Build frontend data object for backwards compatibility
377
-        // using this is no longer recommended
378
-        $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
379
-        $this->data->quiz_passmark = $quiz_passmark;
380
-        $this->data->quiz_lesson = $quiz_lesson_id;
381
-        $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true );
382
-        $this->data->user_lesson_end = $user_lesson_end;
383
-        $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() );
384
-        $this->data->lesson_quiz_questions = $lesson_quiz_questions;
385
-        $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id );
376
+		// Build frontend data object for backwards compatibility
377
+		// using this is no longer recommended
378
+		$this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
379
+		$this->data->quiz_passmark = $quiz_passmark;
380
+		$this->data->quiz_lesson = $quiz_lesson_id;
381
+		$this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true );
382
+		$this->data->user_lesson_end = $user_lesson_end;
383
+		$this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() );
384
+		$this->data->lesson_quiz_questions = $lesson_quiz_questions;
385
+		$this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id );
386 386
 
387
-    } // end load_global_quiz_data
387
+	} // end load_global_quiz_data
388 388
 
389 389
 
390 390
 	/**
@@ -414,25 +414,25 @@  discard block
 block discarded – undo
414 414
 		foreach( $unprepared_answers as $question_id => $answer ) {
415 415
 
416 416
 			//get the current questions question type
417
-            $question_type = Sensei()->question->get_question_type( $question_id );
417
+			$question_type = Sensei()->question->get_question_type( $question_id );
418 418
 
419 419
 			// Sanitise answer
420 420
 			if( 0 == get_magic_quotes_gpc() ) {
421 421
 				$answer = wp_unslash( $answer );
422 422
 			}
423 423
 
424
-            // compress the answer for saving
424
+			// compress the answer for saving
425 425
 			if( 'multi-line' == $question_type ) {
426
-                $answer = esc_html( $answer );
427
-            }elseif( 'file-upload' == $question_type  ){
428
-                $file_key = 'file_upload_' . $question_id;
429
-                if( isset( $files[ $file_key ] ) ) {
430
-                        $attachment_id = WooThemes_Sensei_Utils::upload_file(  $files[ $file_key ] );
431
-                        if( $attachment_id ) {
432
-                            $answer = $attachment_id;
433
-                        }
434
-                    }
435
-            } // end if
426
+				$answer = esc_html( $answer );
427
+			}elseif( 'file-upload' == $question_type  ){
428
+				$file_key = 'file_upload_' . $question_id;
429
+				if( isset( $files[ $file_key ] ) ) {
430
+						$attachment_id = WooThemes_Sensei_Utils::upload_file(  $files[ $file_key ] );
431
+						if( $attachment_id ) {
432
+							$answer = $attachment_id;
433
+						}
434
+					}
435
+			} // end if
436 436
 
437 437
 			$prepared_answers[ $question_id ] =  base64_encode( maybe_serialize( $answer ) );
438 438
 
@@ -441,814 +441,814 @@  discard block
 block discarded – undo
441 441
 		return $prepared_answers;
442 442
 	} // prepare_form_submitted_answers
443 443
 
444
-    /**
445
-     * Reset user submitted questions
446
-     *
447
-     * This function resets the quiz data for a user that has been submitted fro grading already. It is different to
448
-     * the save_user_answers as currently the saved and submitted answers are stored differently.
449
-     *
450
-     * @since 1.7.4
451
-     * @access public
452
-     *
453
-     * @return bool $reset_success
454
-     * @param int $user_id
455
-     * @param int $lesson_id
456
-     */
457
-    public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){
444
+	/**
445
+	 * Reset user submitted questions
446
+	 *
447
+	 * This function resets the quiz data for a user that has been submitted fro grading already. It is different to
448
+	 * the save_user_answers as currently the saved and submitted answers are stored differently.
449
+	 *
450
+	 * @since 1.7.4
451
+	 * @access public
452
+	 *
453
+	 * @return bool $reset_success
454
+	 * @param int $user_id
455
+	 * @param int $lesson_id
456
+	 */
457
+	public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){
458
+
459
+		//make sure the parameters are valid
460
+		if( empty( $lesson_id ) || empty( $user_id )
461
+			|| 'lesson' != get_post_type( $lesson_id )
462
+			|| ! get_userdata( $user_id ) ){
463
+			return false;
464
+		}
465
+
466
+
467
+
468
+		//get the users lesson status to make
469
+		$user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
470
+		if( ! isset( $user_lesson_status->comment_ID ) ) {
471
+			// this user is not taking this lesson so this process is not needed
472
+			return false;
473
+		}
474
+
475
+		//get the lesson quiz and course
476
+		$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
477
+		$course_id = Sensei()->lesson->get_course_id( $lesson_id );
478
+
479
+		// reset the transients
480
+		$answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
481
+		$grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id;
482
+		$answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
483
+		delete_transient( $answers_transient_key );
484
+		delete_transient( $grades_transient_key );
485
+		delete_transient( $answers_feedback_transient_key );
486
+
487
+		// reset the quiz answers and feedback notes
488
+		$deleted_answers = WooThemes_Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id );
489
+		$deleted_grades = WooThemes_Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id );
490
+		$deleted_user_feedback = WooThemes_Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id );
491
+
492
+		// Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade
493
+		WooThemes_Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id );
494
+
495
+		WooThemes_Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) );
496
+
497
+		// Update course completion
498
+		WooThemes_Sensei_Utils::update_course_status( $user_id, $course_id );
458 499
 
459
-        //make sure the parameters are valid
460
-        if( empty( $lesson_id ) || empty( $user_id )
461
-            || 'lesson' != get_post_type( $lesson_id )
462
-            || ! get_userdata( $user_id ) ){
463
-            return false;
464
-        }
465
-
466
-
467
-
468
-        //get the users lesson status to make
469
-        $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
470
-        if( ! isset( $user_lesson_status->comment_ID ) ) {
471
-            // this user is not taking this lesson so this process is not needed
472
-            return false;
473
-        }
500
+		// Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson()
501
+		do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id );
502
+		Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>';
474 503
 
475
-        //get the lesson quiz and course
476
-        $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
477
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
504
+		return ( $deleted_answers && $deleted_grades ) ;
478 505
 
479
-        // reset the transients
480
-        $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
481
-        $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id;
482
-        $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
483
-        delete_transient( $answers_transient_key );
484
-        delete_transient( $grades_transient_key );
485
-        delete_transient( $answers_feedback_transient_key );
506
+	} // end reset_user_lesson_data
486 507
 
487
-        // reset the quiz answers and feedback notes
488
-        $deleted_answers = WooThemes_Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id );
489
-        $deleted_grades = WooThemes_Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id );
490
-        $deleted_user_feedback = WooThemes_Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id );
508
+	 /**
509
+	  * Submit the users quiz answers for grading
510
+	  *
511
+	  * This function accepts users answers and stores it but also initiates the grading
512
+	  * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher.
513
+	  *
514
+	  * @since 1.7.4
515
+	  * @access public
516
+	  *
517
+	  * @param array $quiz_answers
518
+	  * @param array $files from $_FILES
519
+	  * @param int $user_id
520
+	  * @param int $lesson_id
521
+	  *
522
+	  * @return bool $answers_submitted
523
+	  */
524
+	 public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){
491 525
 
492
-        // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade
493
-        WooThemes_Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id );
526
+		 $answers_submitted = false;
494 527
 
495
-        WooThemes_Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) );
528
+		 // get the user_id if none was passed in use the current logged in user
529
+		 if( ! intval( $user_id ) > 0 ) {
530
+			 $user_id = get_current_user_id();
531
+		 }
496 532
 
497
-        // Update course completion
498
-        WooThemes_Sensei_Utils::update_course_status( $user_id, $course_id );
533
+		 // make sure the parameters are valid before continuing
534
+		 if( empty( $lesson_id ) || empty( $user_id )
535
+			 || 'lesson' != get_post_type( $lesson_id )
536
+			 ||!get_userdata( $user_id )
537
+			 || !is_array( $quiz_answers ) ){
499 538
 
500
-        // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson()
501
-        do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id );
502
-        Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>';
539
+			 return false;
503 540
 
504
-        return ( $deleted_answers && $deleted_grades ) ;
541
+		 }
505 542
 
506
-    } // end reset_user_lesson_data
543
+		 // Default grade
544
+		 $grade = 0;
507 545
 
508
-     /**
509
-      * Submit the users quiz answers for grading
510
-      *
511
-      * This function accepts users answers and stores it but also initiates the grading
512
-      * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher.
513
-      *
514
-      * @since 1.7.4
515
-      * @access public
516
-      *
517
-      * @param array $quiz_answers
518
-      * @param array $files from $_FILES
519
-      * @param int $user_id
520
-      * @param int $lesson_id
521
-      *
522
-      * @return bool $answers_submitted
523
-      */
524
-     public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){
546
+		 // Get Quiz ID
547
+		 $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
525 548
 
526
-         $answers_submitted = false;
549
+		 // Get quiz grade type
550
+		 $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true );
527 551
 
528
-         // get the user_id if none was passed in use the current logged in user
529
-         if( ! intval( $user_id ) > 0 ) {
530
-             $user_id = get_current_user_id();
531
-         }
552
+		 // Get quiz pass setting
553
+		 $pass_required = get_post_meta( $quiz_id, '_pass_required', true );
532 554
 
533
-         // make sure the parameters are valid before continuing
534
-         if( empty( $lesson_id ) || empty( $user_id )
535
-             || 'lesson' != get_post_type( $lesson_id )
536
-             ||!get_userdata( $user_id )
537
-             || !is_array( $quiz_answers ) ){
555
+		 // Get the minimum percentage need to pass this quiz
556
+		 $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
538 557
 
539
-             return false;
558
+		 // Handle Quiz Questions asked
559
+		 // This is to ensure we save the questions that we've asked this user and that this can't be change unless
560
+		 // the quiz is reset by admin or user( user: only if the setting is enabled ).
561
+		 // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions
562
+		 $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
563
+		 $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true );
564
+		 if( empty( $questions_asked ) ){
540 565
 
541
-         }
566
+			 $questions_asked = array_keys( $quiz_answers );
567
+			 $questions_asked_string = implode( ',', $questions_asked );
542 568
 
543
-         // Default grade
544
-         $grade = 0;
569
+			 // Save questions that were asked in this quiz
570
+			 update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string );
545 571
 
546
-         // Get Quiz ID
547
-         $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
572
+		 }
548 573
 
549
-         // Get quiz grade type
550
-         $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true );
574
+		 // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson
575
+		 self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id );
551 576
 
552
-         // Get quiz pass setting
553
-         $pass_required = get_post_meta( $quiz_id, '_pass_required', true );
577
+		 // Grade quiz
578
+		 $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type );
554 579
 
555
-         // Get the minimum percentage need to pass this quiz
556
-         $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
580
+		 // Get Lesson Grading Setting
581
+		 $lesson_metadata = array();
582
+		 $lesson_status = 'ungraded'; // Default when completing a quiz
557 583
 
558
-         // Handle Quiz Questions asked
559
-         // This is to ensure we save the questions that we've asked this user and that this can't be change unless
560
-         // the quiz is reset by admin or user( user: only if the setting is enabled ).
561
-         // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions
562
-         $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
563
-         $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true );
564
-         if( empty( $questions_asked ) ){
584
+		 // At this point the answers have been submitted
585
+		 $answers_submitted = true;
565 586
 
566
-             $questions_asked = array_keys( $quiz_answers );
567
-             $questions_asked_string = implode( ',', $questions_asked );
568
-
569
-             // Save questions that were asked in this quiz
570
-             update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string );
587
+		 // if this condition is false the quiz should manually be graded by admin
588
+		 if ('auto' == $quiz_grade_type && ! is_wp_error( $grade )  ) {
571 589
 
572
-         }
590
+			 // Quiz has been automatically Graded
591
+			 if ( 'on' == $pass_required ) {
573 592
 
574
-         // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson
575
-         self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id );
593
+				 // Student has reached the pass mark and lesson is complete
594
+				 if ( $quiz_pass_percentage <= $grade ) {
576 595
 
577
-         // Grade quiz
578
-         $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type );
596
+					 $lesson_status = 'passed';
579 597
 
580
-         // Get Lesson Grading Setting
581
-         $lesson_metadata = array();
582
-         $lesson_status = 'ungraded'; // Default when completing a quiz
598
+				 } else {
583 599
 
584
-         // At this point the answers have been submitted
585
-         $answers_submitted = true;
600
+					 $lesson_status = 'failed';
586 601
 
587
-         // if this condition is false the quiz should manually be graded by admin
588
-         if ('auto' == $quiz_grade_type && ! is_wp_error( $grade )  ) {
602
+				 } // End If Statement
589 603
 
590
-             // Quiz has been automatically Graded
591
-             if ( 'on' == $pass_required ) {
604
+			 } else {
592 605
 
593
-                 // Student has reached the pass mark and lesson is complete
594
-                 if ( $quiz_pass_percentage <= $grade ) {
606
+				 // Student only has to partake the quiz
607
+				 $lesson_status = 'graded';
608
+
609
+			 }
610
+
611
+			 $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above
612
+
613
+		 } // end if ! is_wp_error( $grade ...
614
+
615
+		 WooThemes_Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata );
595 616
 
596
-                     $lesson_status = 'passed';
617
+		 if( 'passed' == $lesson_status || 'graded' == $lesson_status ){
597 618
 
598
-                 } else {
619
+			 /**
620
+			  * Lesson end action hook
621
+			  *
622
+			  * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded'
623
+			  *
624
+			  * @param int $user_id
625
+			  * @param int $lesson_id
626
+			  */
627
+			 do_action( 'sensei_user_lesson_end', $user_id, $lesson_id );
599 628
 
600
-                     $lesson_status = 'failed';
629
+		 }
601 630
 
602
-                 } // End If Statement
631
+		 /**
632
+		  * User quiz has been submitted
633
+		  *
634
+		  * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission
635
+		  * results.
636
+		  *
637
+		  * @param int $user_id
638
+		  * @param int $quiz_id
639
+		  * @param string $grade
640
+		  * @param string $quiz_pass_percentage
641
+		  * @param string $quiz_grade_type
642
+		  */
643
+		 do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type );
603 644
 
604
-             } else {
645
+		 return $answers_submitted;
605 646
 
606
-                 // Student only has to partake the quiz
607
-                 $lesson_status = 'graded';
608
-
609
-             }
610
-
611
-             $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above
612
-
613
-         } // end if ! is_wp_error( $grade ...
614
-
615
-         WooThemes_Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata );
647
+	 }// end submit_answers_for_grading
616 648
 
617
-         if( 'passed' == $lesson_status || 'graded' == $lesson_status ){
649
+	 /**
650
+	  * Get the user question answer
651
+	  *
652
+	  * This function gets the the users saved answer on given quiz for the given question parameter
653
+	  * this function allows for a fallback to users still using the question saved data from before 1.7.4
654
+	  *
655
+	  * @since 1.7.4
656
+	  *
657
+	  * @param int  $lesson_id
658
+	  * @param int $question_id
659
+	  * @param int  $user_id ( optional )
660
+	  *
661
+	  * @return bool $answers_submitted
662
+	  */
663
+	 public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){
618 664
 
619
-             /**
620
-              * Lesson end action hook
621
-              *
622
-              * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded'
623
-              *
624
-              * @param int $user_id
625
-              * @param int $lesson_id
626
-              */
627
-             do_action( 'sensei_user_lesson_end', $user_id, $lesson_id );
665
+		 // parameter validation
666
+		 if( empty( $lesson_id ) || empty( $question_id )
667
+			 || ! ( intval( $lesson_id  ) > 0 )
668
+			 || ! ( intval( $question_id  ) > 0 )
669
+			 || 'lesson' != get_post_type( $lesson_id )
670
+			 || 'question' != get_post_type( $question_id )) {
628 671
 
629
-         }
672
+			 return false;
673
+		 }
674
+
675
+		 if( ! ( intval( $user_id ) > 0 )   ){
676
+			 $user_id = get_current_user_id();
677
+		 }
678
+
679
+		 $users_answers = $this->get_user_answers( $lesson_id, $user_id );
680
+
681
+		 if( !$users_answers || empty( $users_answers )
682
+		 ||  ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){
683
+
684
+			 //Fallback for pre 1.7.4 data
685
+			 $comment =  WooThemes_Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true );
686
+
687
+			 if( ! isset( $comment->comment_content ) ){
688
+				 return false;
689
+			 }
690
+
691
+			 return maybe_unserialize( base64_decode( $comment->comment_content ) );
692
+		 }
693
+
694
+		 return $users_answers[ $question_id ];
695
+
696
+	 }// end get_user_question_answer
697
+
698
+	 /**
699
+	  * Saving the users quiz question grades
700
+	  *
701
+	  * This function save all the grades for all the question in a given quiz on the lesson
702
+	  * comment meta. It makes use of transients to save the grades for easier access at a later stage
703
+	  *
704
+	  * @since 1.7.4
705
+	  *
706
+	  * @param array $quiz_grades{
707
+	  *      @type int $question_id
708
+	  *      @type int $question_grade
709
+	  * }
710
+	  * @param $lesson_id
711
+	  * @param $user_id (Optional) will use the current user if not supplied
712
+	  *
713
+	  * @return bool
714
+	  */
715
+	 public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){
716
+
717
+		 // get the user_id if none was passed in use the current logged in user
718
+		 if( ! intval( $user_id ) > 0 ) {
719
+			 $user_id = get_current_user_id();
720
+		 }
721
+
722
+		 // make sure the parameters are valid before continuing
723
+		 if( empty( $lesson_id ) || empty( $user_id )
724
+			 || 'lesson' != get_post_type( $lesson_id )
725
+			 ||!get_userdata( $user_id )
726
+			 || !is_array( $quiz_grades ) ){
727
+
728
+			 return false;
729
+
730
+		 }
731
+
732
+		 $success = false;
733
+
734
+		 // save that data for the user on the lesson comment meta
735
+		 $comment_meta_id = WooThemes_Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id   );
736
+
737
+		 // were the grades save successfully ?
738
+		 if( intval( $comment_meta_id ) > 0 ) {
739
+
740
+			 $success = true;
741
+			 // save transient
742
+			 $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id;
743
+			 set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS );
744
+		 }
745
+
746
+		 return $success;
747
+
748
+	 }// end set_user_grades
749
+
750
+	 /**
751
+	  * Retrieve the users quiz question grades
752
+	  *
753
+	  * This function gets all the grades for all the questions in the given lesson quiz for a specific user.
754
+	  *
755
+	  * @since 1.7.4
756
+	  *
757
+	  * @param $lesson_id
758
+	  * @param $user_id (Optional) will use the current user if not supplied
759
+	  *
760
+	  * @return array $user_quiz_grades or false if none exists for this users
761
+	  */
762
+	 public function get_user_grades( $lesson_id, $user_id = 0 ){
763
+
764
+		 $user_grades = array();
765
+
766
+		 // get the user_id if none was passed in use the current logged in user
767
+		 if( ! intval( $user_id ) > 0 ) {
768
+			 $user_id = get_current_user_id();
769
+		 }
770
+
771
+		 if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
772
+			 || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
773
+			 return false;
774
+		 }
775
+
776
+		 // save some time and get the transient cached data
777
+		 $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id;
778
+		 $user_grades = get_transient( $transient_key );
779
+
780
+		 // get the data if nothing was stored in the transient
781
+		 if( empty( $user_grades  ) || false != $user_grades ){
782
+
783
+			 $user_grades = WooThemes_Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id );
784
+
785
+			 //set the transient with the new valid data for faster retrieval in future
786
+			 set_transient( $transient_key,  $user_grades, 10 * DAY_IN_SECONDS );
787
+
788
+		 } // end if transient check
789
+
790
+		 // if there is no data for this user
791
+		 if( ! is_array( $user_grades ) ){
792
+			 return false;
793
+		 }
794
+
795
+		 return $user_grades;
796
+
797
+	 }// end  get_user_grades
798
+
799
+	 /**
800
+	  * Get the user question grade
801
+	  *
802
+	  * This function gets the grade on a quiz for the given question parameter
803
+	  * It does NOT do any grading. It simply retrieves the data that was stored during grading.
804
+	  * this function allows for a fallback to users still using the question saved data from before 1.7.4
805
+	  *
806
+	  * @since 1.7.4
807
+	  *
808
+	  * @param int  $lesson_id
809
+	  * @param int $question_id
810
+	  * @param int  $user_id ( optional )
811
+	  *
812
+	  * @return bool $question_grade
813
+	  */
814
+	 public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){
815
+
816
+		 // parameter validation
817
+		 if( empty( $lesson_id ) || empty( $question_id )
818
+			 || ! ( intval( $lesson_id  ) > 0 )
819
+			 || ! ( intval( $question_id  ) > 0 )
820
+			 || 'lesson' != get_post_type( $lesson_id )
821
+			 || 'question' != get_post_type( $question_id )) {
822
+
823
+			 return false;
824
+		 }
825
+
826
+		 $all_user_grades = self::get_user_grades( $lesson_id,$user_id );
827
+
828
+		 if( ! $all_user_grades || ! isset(  $all_user_grades[ $question_id ] ) ){
829
+
830
+			 //fallback to data pre 1.7.4
831
+			 $args = array(
832
+				 'post_id' => $question_id,
833
+				 'user_id' => $user_id,
834
+				 'type'    => 'sensei_user_answer'
835
+			 );
836
+
837
+			 $question_activity = WooThemes_Sensei_Utils::sensei_check_for_activity( $args , true );
838
+			 $fall_back_grade = false;
839
+			 if( isset( $question_activity->comment_ID ) ){
840
+				 $fall_back_grade = get_comment_meta(  $question_activity->comment_ID , 'user_grade', true );
841
+			 }
842
+
843
+			 return $fall_back_grade;
844
+
845
+		 } // end if $all_user_grades...
846
+
847
+		 return $all_user_grades[ $question_id ];
848
+
849
+	 }// end get_user_question_grade
850
+
851
+	 /**
852
+	  * Save the user's answers feedback
853
+	  *
854
+	  * For this function you must supply all three parameters. If will return false one is left out.
855
+	  * The data will be saved on the lesson ID supplied.
856
+	  *
857
+	  * @since 1.7.5
858
+	  * @access public
859
+	  *
860
+	  * @param array $answers_feedback{
861
+	  *  $type int $question_id
862
+	  *  $type string $question_feedback
863
+	  * }
864
+	  * @param int $lesson_id
865
+	  * @param int $user_id
866
+	  *
867
+	  * @return false or int $feedback_saved
868
+	  */
869
+	public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){
870
+
871
+		// make sure the parameters are valid before continuing
872
+		if( empty( $lesson_id ) || empty( $user_id )
873
+			|| 'lesson' != get_post_type( $lesson_id )
874
+			||!get_userdata( $user_id )
875
+			|| !is_array( $answers_feedback ) ){
876
+
877
+			return false;
878
+
879
+		}
880
+
881
+
882
+		// check if the lesson is started before saving, if not start the lesson for the user
883
+		if ( !( 0 < intval( WooThemes_Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) {
884
+			WooThemes_Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
885
+		}
630 886
 
631
-         /**
632
-          * User quiz has been submitted
633
-          *
634
-          * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission
635
-          * results.
636
-          *
637
-          * @param int $user_id
638
-          * @param int $quiz_id
639
-          * @param string $grade
640
-          * @param string $quiz_pass_percentage
641
-          * @param string $quiz_grade_type
642
-          */
643
-         do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type );
887
+		// encode the feedback
888
+		$encoded_answers_feedback =  array();
889
+		foreach( $answers_feedback as $question_id => $feedback ){
890
+			$encoded_answers_feedback[ $question_id ] = base64_encode( $feedback );
891
+		}
892
+
893
+		// save the user data
894
+		$feedback_saved = WooThemes_Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ;
895
+
896
+		//Were the the question feedback save correctly?
897
+		if( intval( $feedback_saved ) > 0){
898
+
899
+			// save transient to make retrieval faster in future
900
+			 $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
901
+			 set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS );
644 902
 
645
-         return $answers_submitted;
903
+		}
904
+
905
+		return $feedback_saved;
906
+
907
+	} // end save_user_answers_feedback
908
+
909
+	 /**
910
+	  * Get the user's answers feedback.
911
+	  *
912
+	  * This function returns the feedback submitted by the teacher/admin
913
+	  * during grading. Grading occurs manually or automatically.
914
+	  *
915
+	  * @since 1.7.5
916
+	  * @access public
917
+	  *
918
+	  * @param int $lesson_id
919
+	  * @param int $user_id
920
+	  *
921
+	  * @return false | array $answers_feedback{
922
+	  *  $type int $question_id
923
+	  *  $type string $question_feedback
924
+	  * }
925
+	  */
926
+	 public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){
927
+
928
+		 $answers_feedback = array();
646 929
 
647
-     }// end submit_answers_for_grading
930
+		 // get the user_id if none was passed in use the current logged in user
931
+		 if( ! intval( $user_id ) > 0 ) {
932
+			 $user_id = get_current_user_id();
933
+		 }
648 934
 
649
-     /**
650
-      * Get the user question answer
651
-      *
652
-      * This function gets the the users saved answer on given quiz for the given question parameter
653
-      * this function allows for a fallback to users still using the question saved data from before 1.7.4
654
-      *
655
-      * @since 1.7.4
656
-      *
657
-      * @param int  $lesson_id
658
-      * @param int $question_id
659
-      * @param int  $user_id ( optional )
660
-      *
661
-      * @return bool $answers_submitted
662
-      */
663
-     public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){
935
+		 if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
936
+			 || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
937
+			 return false;
938
+		 }
939
+
940
+		 // first check the transient to save a few split seconds
941
+		 $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
942
+		 $encoded_feedback = get_transient( $transient_key );
943
+
944
+		 // get the data if nothing was stored in the transient
945
+		 if( empty( $encoded_feedback  ) || !$encoded_feedback ){
664 946
 
665
-         // parameter validation
666
-         if( empty( $lesson_id ) || empty( $question_id )
667
-             || ! ( intval( $lesson_id  ) > 0 )
668
-             || ! ( intval( $question_id  ) > 0 )
669
-             || 'lesson' != get_post_type( $lesson_id )
670
-             || 'question' != get_post_type( $question_id )) {
947
+			 $encoded_feedback = WooThemes_Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id );
948
+
949
+			 //set the transient with the new valid data for faster retrieval in future
950
+			 set_transient( $transient_key,  $encoded_feedback, 10 * DAY_IN_SECONDS);
951
+
952
+		 } // end if transient check
671 953
 
672
-             return false;
673
-         }
674
-
675
-         if( ! ( intval( $user_id ) > 0 )   ){
676
-             $user_id = get_current_user_id();
677
-         }
678
-
679
-         $users_answers = $this->get_user_answers( $lesson_id, $user_id );
680
-
681
-         if( !$users_answers || empty( $users_answers )
682
-         ||  ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){
683
-
684
-             //Fallback for pre 1.7.4 data
685
-             $comment =  WooThemes_Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true );
686
-
687
-             if( ! isset( $comment->comment_content ) ){
688
-                 return false;
689
-             }
690
-
691
-             return maybe_unserialize( base64_decode( $comment->comment_content ) );
692
-         }
693
-
694
-         return $users_answers[ $question_id ];
695
-
696
-     }// end get_user_question_answer
697
-
698
-     /**
699
-      * Saving the users quiz question grades
700
-      *
701
-      * This function save all the grades for all the question in a given quiz on the lesson
702
-      * comment meta. It makes use of transients to save the grades for easier access at a later stage
703
-      *
704
-      * @since 1.7.4
705
-      *
706
-      * @param array $quiz_grades{
707
-      *      @type int $question_id
708
-      *      @type int $question_grade
709
-      * }
710
-      * @param $lesson_id
711
-      * @param $user_id (Optional) will use the current user if not supplied
712
-      *
713
-      * @return bool
714
-      */
715
-     public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){
716
-
717
-         // get the user_id if none was passed in use the current logged in user
718
-         if( ! intval( $user_id ) > 0 ) {
719
-             $user_id = get_current_user_id();
720
-         }
721
-
722
-         // make sure the parameters are valid before continuing
723
-         if( empty( $lesson_id ) || empty( $user_id )
724
-             || 'lesson' != get_post_type( $lesson_id )
725
-             ||!get_userdata( $user_id )
726
-             || !is_array( $quiz_grades ) ){
727
-
728
-             return false;
729
-
730
-         }
731
-
732
-         $success = false;
733
-
734
-         // save that data for the user on the lesson comment meta
735
-         $comment_meta_id = WooThemes_Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id   );
736
-
737
-         // were the grades save successfully ?
738
-         if( intval( $comment_meta_id ) > 0 ) {
739
-
740
-             $success = true;
741
-             // save transient
742
-             $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id;
743
-             set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS );
744
-         }
745
-
746
-         return $success;
747
-
748
-     }// end set_user_grades
749
-
750
-     /**
751
-      * Retrieve the users quiz question grades
752
-      *
753
-      * This function gets all the grades for all the questions in the given lesson quiz for a specific user.
754
-      *
755
-      * @since 1.7.4
756
-      *
757
-      * @param $lesson_id
758
-      * @param $user_id (Optional) will use the current user if not supplied
759
-      *
760
-      * @return array $user_quiz_grades or false if none exists for this users
761
-      */
762
-     public function get_user_grades( $lesson_id, $user_id = 0 ){
763
-
764
-         $user_grades = array();
765
-
766
-         // get the user_id if none was passed in use the current logged in user
767
-         if( ! intval( $user_id ) > 0 ) {
768
-             $user_id = get_current_user_id();
769
-         }
770
-
771
-         if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
772
-             || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
773
-             return false;
774
-         }
775
-
776
-         // save some time and get the transient cached data
777
-         $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id;
778
-         $user_grades = get_transient( $transient_key );
779
-
780
-         // get the data if nothing was stored in the transient
781
-         if( empty( $user_grades  ) || false != $user_grades ){
782
-
783
-             $user_grades = WooThemes_Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id );
784
-
785
-             //set the transient with the new valid data for faster retrieval in future
786
-             set_transient( $transient_key,  $user_grades, 10 * DAY_IN_SECONDS );
787
-
788
-         } // end if transient check
789
-
790
-         // if there is no data for this user
791
-         if( ! is_array( $user_grades ) ){
792
-             return false;
793
-         }
794
-
795
-         return $user_grades;
796
-
797
-     }// end  get_user_grades
798
-
799
-     /**
800
-      * Get the user question grade
801
-      *
802
-      * This function gets the grade on a quiz for the given question parameter
803
-      * It does NOT do any grading. It simply retrieves the data that was stored during grading.
804
-      * this function allows for a fallback to users still using the question saved data from before 1.7.4
805
-      *
806
-      * @since 1.7.4
807
-      *
808
-      * @param int  $lesson_id
809
-      * @param int $question_id
810
-      * @param int  $user_id ( optional )
811
-      *
812
-      * @return bool $question_grade
813
-      */
814
-     public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){
815
-
816
-         // parameter validation
817
-         if( empty( $lesson_id ) || empty( $question_id )
818
-             || ! ( intval( $lesson_id  ) > 0 )
819
-             || ! ( intval( $question_id  ) > 0 )
820
-             || 'lesson' != get_post_type( $lesson_id )
821
-             || 'question' != get_post_type( $question_id )) {
822
-
823
-             return false;
824
-         }
825
-
826
-         $all_user_grades = self::get_user_grades( $lesson_id,$user_id );
827
-
828
-         if( ! $all_user_grades || ! isset(  $all_user_grades[ $question_id ] ) ){
829
-
830
-             //fallback to data pre 1.7.4
831
-             $args = array(
832
-                 'post_id' => $question_id,
833
-                 'user_id' => $user_id,
834
-                 'type'    => 'sensei_user_answer'
835
-             );
836
-
837
-             $question_activity = WooThemes_Sensei_Utils::sensei_check_for_activity( $args , true );
838
-             $fall_back_grade = false;
839
-             if( isset( $question_activity->comment_ID ) ){
840
-                 $fall_back_grade = get_comment_meta(  $question_activity->comment_ID , 'user_grade', true );
841
-             }
842
-
843
-             return $fall_back_grade;
844
-
845
-         } // end if $all_user_grades...
846
-
847
-         return $all_user_grades[ $question_id ];
848
-
849
-     }// end get_user_question_grade
850
-
851
-     /**
852
-      * Save the user's answers feedback
853
-      *
854
-      * For this function you must supply all three parameters. If will return false one is left out.
855
-      * The data will be saved on the lesson ID supplied.
856
-      *
857
-      * @since 1.7.5
858
-      * @access public
859
-      *
860
-      * @param array $answers_feedback{
861
-      *  $type int $question_id
862
-      *  $type string $question_feedback
863
-      * }
864
-      * @param int $lesson_id
865
-      * @param int $user_id
866
-      *
867
-      * @return false or int $feedback_saved
868
-      */
869
-    public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){
870
-
871
-        // make sure the parameters are valid before continuing
872
-        if( empty( $lesson_id ) || empty( $user_id )
873
-            || 'lesson' != get_post_type( $lesson_id )
874
-            ||!get_userdata( $user_id )
875
-            || !is_array( $answers_feedback ) ){
876
-
877
-            return false;
878
-
879
-        }
880
-
881
-
882
-        // check if the lesson is started before saving, if not start the lesson for the user
883
-        if ( !( 0 < intval( WooThemes_Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) {
884
-            WooThemes_Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
885
-        }
886
-
887
-        // encode the feedback
888
-        $encoded_answers_feedback =  array();
889
-        foreach( $answers_feedback as $question_id => $feedback ){
890
-            $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback );
891
-        }
892
-
893
-        // save the user data
894
-        $feedback_saved = WooThemes_Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ;
895
-
896
-        //Were the the question feedback save correctly?
897
-        if( intval( $feedback_saved ) > 0){
898
-
899
-            // save transient to make retrieval faster in future
900
-             $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
901
-             set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS );
902
-
903
-        }
904
-
905
-        return $feedback_saved;
906
-
907
-    } // end save_user_answers_feedback
908
-
909
-     /**
910
-      * Get the user's answers feedback.
911
-      *
912
-      * This function returns the feedback submitted by the teacher/admin
913
-      * during grading. Grading occurs manually or automatically.
914
-      *
915
-      * @since 1.7.5
916
-      * @access public
917
-      *
918
-      * @param int $lesson_id
919
-      * @param int $user_id
920
-      *
921
-      * @return false | array $answers_feedback{
922
-      *  $type int $question_id
923
-      *  $type string $question_feedback
924
-      * }
925
-      */
926
-     public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){
927
-
928
-         $answers_feedback = array();
929
-
930
-         // get the user_id if none was passed in use the current logged in user
931
-         if( ! intval( $user_id ) > 0 ) {
932
-             $user_id = get_current_user_id();
933
-         }
934
-
935
-         if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
936
-             || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
937
-             return false;
938
-         }
939
-
940
-         // first check the transient to save a few split seconds
941
-         $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
942
-         $encoded_feedback = get_transient( $transient_key );
943
-
944
-         // get the data if nothing was stored in the transient
945
-         if( empty( $encoded_feedback  ) || !$encoded_feedback ){
946
-
947
-             $encoded_feedback = WooThemes_Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id );
948
-
949
-             //set the transient with the new valid data for faster retrieval in future
950
-             set_transient( $transient_key,  $encoded_feedback, 10 * DAY_IN_SECONDS);
951
-
952
-         } // end if transient check
953
-
954
-         // if there is no data for this user
955
-         if( ! is_array( $encoded_feedback ) ){
956
-             return false;
957
-         }
954
+		 // if there is no data for this user
955
+		 if( ! is_array( $encoded_feedback ) ){
956
+			 return false;
957
+		 }
958 958
 
959
-         foreach( $encoded_feedback as $question_id => $feedback ){
959
+		 foreach( $encoded_feedback as $question_id => $feedback ){
960 960
 
961
-             $answers_feedback[ $question_id ] = base64_decode( $feedback );
961
+			 $answers_feedback[ $question_id ] = base64_decode( $feedback );
962 962
 
963
-         }
963
+		 }
964 964
 
965
-         return $answers_feedback;
965
+		 return $answers_feedback;
966 966
 
967
-     } // end get_user_answers_feedback
967
+	 } // end get_user_answers_feedback
968 968
 
969
-     /**
970
-      * Get the user's answer feedback for a specific question.
971
-      *
972
-      * This function gives you a single answer note/feedback string
973
-      * for the user on the given question.
974
-      *
975
-      * @since 1.7.5
976
-      * @access public
977
-      *
978
-      * @param int $lesson_id
979
-      * @param int $question_id
980
-      * @param int $user_id
981
-      *
982
-      * @return string $feedback or bool if false
983
-      */
984
-     public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){
969
+	 /**
970
+	  * Get the user's answer feedback for a specific question.
971
+	  *
972
+	  * This function gives you a single answer note/feedback string
973
+	  * for the user on the given question.
974
+	  *
975
+	  * @since 1.7.5
976
+	  * @access public
977
+	  *
978
+	  * @param int $lesson_id
979
+	  * @param int $question_id
980
+	  * @param int $user_id
981
+	  *
982
+	  * @return string $feedback or bool if false
983
+	  */
984
+	 public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){
985 985
 
986
-         $feedback = false;
986
+		 $feedback = false;
987 987
 
988
-         // parameter validation
989
-         if( empty( $lesson_id ) || empty( $question_id )
990
-             || ! ( intval( $lesson_id  ) > 0 )
991
-             || ! ( intval( $question_id  ) > 0 )
992
-             || 'lesson' != get_post_type( $lesson_id )
993
-             || 'question' != get_post_type( $question_id )) {
988
+		 // parameter validation
989
+		 if( empty( $lesson_id ) || empty( $question_id )
990
+			 || ! ( intval( $lesson_id  ) > 0 )
991
+			 || ! ( intval( $question_id  ) > 0 )
992
+			 || 'lesson' != get_post_type( $lesson_id )
993
+			 || 'question' != get_post_type( $question_id )) {
994 994
 
995
-             return false;
996
-         }
995
+			 return false;
996
+		 }
997 997
 
998
-         // get all the feedback for the user on the given lesson
999
-         $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id );
998
+		 // get all the feedback for the user on the given lesson
999
+		 $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id );
1000 1000
 
1001
-         if( !$all_feedback || empty( $all_feedback )
1002
-             || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){
1001
+		 if( !$all_feedback || empty( $all_feedback )
1002
+			 || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){
1003 1003
 
1004
-             //fallback to data pre 1.7.4
1004
+			 //fallback to data pre 1.7.4
1005 1005
 
1006
-             // setup the sensei data query
1007
-             $args = array(
1008
-                 'post_id' => $question_id,
1009
-                 'user_id' => $user_id,
1010
-                 'type'    => 'sensei_user_answer'
1011
-             );
1012
-             $question_activity = WooThemes_Sensei_Utils::sensei_check_for_activity( $args , true );
1006
+			 // setup the sensei data query
1007
+			 $args = array(
1008
+				 'post_id' => $question_id,
1009
+				 'user_id' => $user_id,
1010
+				 'type'    => 'sensei_user_answer'
1011
+			 );
1012
+			 $question_activity = WooThemes_Sensei_Utils::sensei_check_for_activity( $args , true );
1013 1013
 
1014
-             // set the default to false and return that if no old data is available.
1015
-             if( isset( $question_activity->comment_ID ) ){
1016
-                 $feedback = base64_decode( get_comment_meta(  $question_activity->comment_ID , 'answer_note', true ) );
1017
-             }
1014
+			 // set the default to false and return that if no old data is available.
1015
+			 if( isset( $question_activity->comment_ID ) ){
1016
+				 $feedback = base64_decode( get_comment_meta(  $question_activity->comment_ID , 'answer_note', true ) );
1017
+			 }
1018 1018
 
1019
-             // finally use the default question feedback
1020
-             if( empty( $feedback ) ){
1021
-                 $feedback = get_post_meta( $question_id, '_answer_feedback', true );
1022
-             }
1019
+			 // finally use the default question feedback
1020
+			 if( empty( $feedback ) ){
1021
+				 $feedback = get_post_meta( $question_id, '_answer_feedback', true );
1022
+			 }
1023 1023
 
1024
-             return $feedback;
1024
+			 return $feedback;
1025 1025
 
1026
-         }
1026
+		 }
1027 1027
 
1028
-         return $all_feedback[ $question_id ];
1028
+		 return $all_feedback[ $question_id ];
1029 1029
 
1030
-     } // end get_user_question_feedback
1030
+	 } // end get_user_question_feedback
1031 1031
 
1032
-     /**
1033
-      * Check if a quiz has no questions, and redirect back to lesson.
1034
-      *
1035
-      * Though a quiz is created for each lesson, it should not be visible
1036
-      * unless it has questions.
1037
-      *
1038
-      * @since 1.9.0
1039
-      * @access public
1040
-      * @param none
1041
-      * @return void
1042
-      */
1032
+	 /**
1033
+	  * Check if a quiz has no questions, and redirect back to lesson.
1034
+	  *
1035
+	  * Though a quiz is created for each lesson, it should not be visible
1036
+	  * unless it has questions.
1037
+	  *
1038
+	  * @since 1.9.0
1039
+	  * @access public
1040
+	  * @param none
1041
+	  * @return void
1042
+	  */
1043 1043
 
1044
-     public function quiz_has_no_questions() {
1044
+	 public function quiz_has_no_questions() {
1045 1045
 
1046 1046
 
1047
-         if( ! is_singular( 'quiz' ) )  {
1048
-             return;
1049
-         }
1047
+		 if( ! is_singular( 'quiz' ) )  {
1048
+			 return;
1049
+		 }
1050 1050
 
1051
-         global $post;
1051
+		 global $post;
1052 1052
 
1053
-         $lesson_id = $this->get_lesson_id($post->ID);
1053
+		 $lesson_id = $this->get_lesson_id($post->ID);
1054 1054
 
1055
-         $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
1055
+		 $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
1056 1056
 
1057
-         $lesson = get_post($lesson_id);
1057
+		 $lesson = get_post($lesson_id);
1058 1058
 
1059
-         if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) {
1059
+		 if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) {
1060 1060
 
1061
-             wp_redirect(get_permalink($lesson->ID), 301);
1062
-             exit;
1061
+			 wp_redirect(get_permalink($lesson->ID), 301);
1062
+			 exit;
1063 1063
 
1064
-         }
1064
+		 }
1065 1065
 
1066
-     } // end quiz_has_no_questions
1066
+	 } // end quiz_has_no_questions
1067 1067
 
1068 1068
 /**
1069
-  * Deprecate the sensei_single_main_content on the single-quiz template.
1070
-  *
1071
-  * @deprecated since 1.9.0
1072
-  */
1069
+ * Deprecate the sensei_single_main_content on the single-quiz template.
1070
+ *
1071
+ * @deprecated since 1.9.0
1072
+ */
1073 1073
  public static function deprecate_quiz_sensei_single_main_content_hook(){
1074 1074
 
1075
-     sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after');
1075
+	 sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after');
1076 1076
 
1077 1077
  }
1078
-    /*
1078
+	/*
1079 1079
      * Deprecate the sensei_quiz_single_title on the single-quiz template.
1080 1080
      *
1081 1081
      * @deprecated since 1.9.0
1082 1082
      */
1083
-     public static function deprecate_quiz_sensei_quiz_single_title_hook(){
1083
+	 public static function deprecate_quiz_sensei_quiz_single_title_hook(){
1084 1084
 
1085
-         sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before ');
1085
+		 sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before ');
1086 1086
 
1087
-     }
1087
+	 }
1088 1088
 
1089
-     /**
1090
-      * Filter the single title and add the Quiz to it.
1091
-      *
1092
-      * @param string $title
1093
-      * @param int $id title post id
1094
-      * @return string $quiz_title
1095
-      */
1096
-     public static function single_quiz_title( $title, $post_id ){
1089
+	 /**
1090
+	  * Filter the single title and add the Quiz to it.
1091
+	  *
1092
+	  * @param string $title
1093
+	  * @param int $id title post id
1094
+	  * @return string $quiz_title
1095
+	  */
1096
+	 public static function single_quiz_title( $title, $post_id ){
1097 1097
 
1098
-         if( 'quiz' == get_post_type( $post_id ) ){
1098
+		 if( 'quiz' == get_post_type( $post_id ) ){
1099 1099
 
1100
-             $title_with_no_quizzes = $title;
1100
+			 $title_with_no_quizzes = $title;
1101 1101
 
1102
-             // if the title has quiz, remove it: legacy titles have the word quiz stored.
1103
-             if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){
1102
+			 // if the title has quiz, remove it: legacy titles have the word quiz stored.
1103
+			 if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){
1104 1104
 
1105
-                 // remove all possible appearances of quiz
1106
-                 $title_with_no_quizzes = str_replace( 'quiz', '', $title  );
1107
-                 $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes  );
1108
-                 $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes  );
1105
+				 // remove all possible appearances of quiz
1106
+				 $title_with_no_quizzes = str_replace( 'quiz', '', $title  );
1107
+				 $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes  );
1108
+				 $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes  );
1109 1109
 
1110
-             }
1110
+			 }
1111 1111
 
1112
-             $title = $title_with_no_quizzes .  ' ' . __( 'Quiz', 'woothemes-sensei' );
1113
-         }
1112
+			 $title = $title_with_no_quizzes .  ' ' . __( 'Quiz', 'woothemes-sensei' );
1113
+		 }
1114 1114
 
1115
-         /**
1116
-          * hook document in class-woothemes-sensei-message.php
1117
-          */
1118
-         return apply_filters( 'sensei_single_title', $title, get_post_type( ) );
1115
+		 /**
1116
+		  * hook document in class-woothemes-sensei-message.php
1117
+		  */
1118
+		 return apply_filters( 'sensei_single_title', $title, get_post_type( ) );
1119 1119
 
1120
-     }
1120
+	 }
1121 1121
 
1122
-     /**
1123
-      * Initialize the quiz question loop on the single quiz template
1124
-      *
1125
-      * The function will create a global quiz loop varialbe.
1126
-      *
1127
-      * @since 1.9.0
1128
-      *
1129
-      */
1130
-     public static function start_quiz_questions_loop(){
1122
+	 /**
1123
+	  * Initialize the quiz question loop on the single quiz template
1124
+	  *
1125
+	  * The function will create a global quiz loop varialbe.
1126
+	  *
1127
+	  * @since 1.9.0
1128
+	  *
1129
+	  */
1130
+	 public static function start_quiz_questions_loop(){
1131 1131
 
1132
-         global $sensei_question_loop;
1132
+		 global $sensei_question_loop;
1133 1133
 
1134
-         //intialize the questions loop object
1135
-         $sensei_question_loop['current'] = -1;
1136
-         $sensei_question_loop['total']   =  0;
1137
-         $sensei_question_loop['questions'] = array();
1134
+		 //intialize the questions loop object
1135
+		 $sensei_question_loop['current'] = -1;
1136
+		 $sensei_question_loop['total']   =  0;
1137
+		 $sensei_question_loop['questions'] = array();
1138 1138
 
1139 1139
 
1140
-         $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() );
1140
+		 $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() );
1141 1141
 
1142
-         if( count( $questions  ) > 0  ){
1142
+		 if( count( $questions  ) > 0  ){
1143 1143
 
1144
-             $sensei_question_loop['total']   =  count( $questions );
1145
-             $sensei_question_loop['questions'] = $questions;
1146
-             $sensei_question_loop['quiz_id'] = get_the_ID();
1144
+			 $sensei_question_loop['total']   =  count( $questions );
1145
+			 $sensei_question_loop['questions'] = $questions;
1146
+			 $sensei_question_loop['quiz_id'] = get_the_ID();
1147 1147
 
1148
-         }
1148
+		 }
1149 1149
 
1150
-     }// static function
1150
+	 }// static function
1151 1151
 
1152
-     /**
1153
-      * Initialize the quiz question loop on the single quiz template
1154
-      *
1155
-      * The function will create a global quiz loop varialbe.
1156
-      *
1157
-      * @since 1.9.0
1158
-      *
1159
-      */
1160
-     public static function stop_quiz_questions_loop(){
1152
+	 /**
1153
+	  * Initialize the quiz question loop on the single quiz template
1154
+	  *
1155
+	  * The function will create a global quiz loop varialbe.
1156
+	  *
1157
+	  * @since 1.9.0
1158
+	  *
1159
+	  */
1160
+	 public static function stop_quiz_questions_loop(){
1161 1161
 
1162
-         $sensei_question_loop['total']   =  0;
1163
-         $sensei_question_loop['questions'] = array();
1164
-         $sensei_question_loop['quiz_id'] = '';
1162
+		 $sensei_question_loop['total']   =  0;
1163
+		 $sensei_question_loop['questions'] = array();
1164
+		 $sensei_question_loop['quiz_id'] = '';
1165 1165
 
1166
-     }
1166
+	 }
1167 1167
 
1168
-     /**
1169
-      * Output the title for the single quiz page
1170
-      *
1171
-      * @since 1.9.0
1172
-      */
1173
-     public static function the_title(){
1174
-         ?>
1168
+	 /**
1169
+	  * Output the title for the single quiz page
1170
+	  *
1171
+	  * @since 1.9.0
1172
+	  */
1173
+	 public static function the_title(){
1174
+		 ?>
1175 1175
          <header>
1176 1176
 
1177 1177
              <h1>
1178 1178
 
1179 1179
                  <?php
1180
-                 /**
1181
-                  * Filter documented in class-sensei-messages.php the_title
1182
-                  */
1183
-                 echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) );
1184
-                 ?>
1180
+				 /**
1181
+				  * Filter documented in class-sensei-messages.php the_title
1182
+				  */
1183
+				 echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) );
1184
+				 ?>
1185 1185
 
1186 1186
              </h1>
1187 1187
 
1188 1188
          </header>
1189 1189
 
1190 1190
          <?php
1191
-     }//the_title
1191
+	 }//the_title
1192 1192
 
1193
-     /**
1194
-      * Output the sensei quiz status message.
1195
-      *
1196
-      * @param $quiz_id
1197
-      */
1198
-    public static function  the_user_status_message( $quiz_id ){
1193
+	 /**
1194
+	  * Output the sensei quiz status message.
1195
+	  *
1196
+	  * @param $quiz_id
1197
+	  */
1198
+	public static function  the_user_status_message( $quiz_id ){
1199 1199
 
1200
-        $lesson_id =  Sensei()->quiz->get_lesson_id( $quiz_id );
1201
-        $status = WooThemes_Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() );
1202
-        echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
1200
+		$lesson_id =  Sensei()->quiz->get_lesson_id( $quiz_id );
1201
+		$status = WooThemes_Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() );
1202
+		echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
1203 1203
 
1204
-    }
1204
+	}
1205 1205
 
1206
-     /**
1207
-      * This functions runs the old sensei_quiz_action_buttons action
1208
-      * for backwards compatiblity sake.
1209
-      *
1210
-      * @since 1.9.0
1211
-      * @deprecated
1212
-      */
1213
-     public static function deprecate_sensei_quiz_action_buttons_hook(){
1206
+	 /**
1207
+	  * This functions runs the old sensei_quiz_action_buttons action
1208
+	  * for backwards compatiblity sake.
1209
+	  *
1210
+	  * @since 1.9.0
1211
+	  * @deprecated
1212
+	  */
1213
+	 public static function deprecate_sensei_quiz_action_buttons_hook(){
1214 1214
 
1215
-         sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after');
1215
+		 sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after');
1216 1216
 
1217
-     }
1217
+	 }
1218 1218
 
1219
-     /**
1220
-      * The quiz action buttons needed to ouput quiz
1221
-      * action such as reset complete and save.
1222
-      *
1223
-      * @since 1.3.0
1224
-      */
1225
-     public static function action_buttons() {
1219
+	 /**
1220
+	  * The quiz action buttons needed to ouput quiz
1221
+	  * action such as reset complete and save.
1222
+	  *
1223
+	  * @since 1.3.0
1224
+	  */
1225
+	 public static function action_buttons() {
1226 1226
 
1227
-         global $post, $current_user;
1227
+		 global $post, $current_user;
1228 1228
 
1229
-         $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true );
1230
-         $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true );
1231
-         $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
1232
-         $show_actions = true;
1233
-         $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID );
1229
+		 $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true );
1230
+		 $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true );
1231
+		 $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
1232
+		 $show_actions = true;
1233
+		 $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID );
1234 1234
 
1235
-         //setup quiz grade
1236
-         $user_quiz_grade = '';
1237
-         if( ! empty( $user_lesson_status  ) ){
1238
-             $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1239
-         }
1235
+		 //setup quiz grade
1236
+		 $user_quiz_grade = '';
1237
+		 if( ! empty( $user_lesson_status  ) ){
1238
+			 $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1239
+		 }
1240 1240
 
1241 1241
 
1242
-         if( intval( $lesson_prerequisite ) > 0 ) {
1242
+		 if( intval( $lesson_prerequisite ) > 0 ) {
1243 1243
 
1244
-             // If the user hasn't completed the prereq then hide the current actions
1245
-             $show_actions = WooThemes_Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID );
1244
+			 // If the user hasn't completed the prereq then hide the current actions
1245
+			 $show_actions = WooThemes_Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID );
1246 1246
 
1247
-         }
1248
-         if ( $show_actions && is_user_logged_in() && WooThemes_Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) {
1247
+		 }
1248
+		 if ( $show_actions && is_user_logged_in() && WooThemes_Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) {
1249 1249
 
1250
-             // Get Reset Settings
1251
-             $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?>
1250
+			 // Get Reset Settings
1251
+			 $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?>
1252 1252
 
1253 1253
              <!-- Action Nonce's -->
1254 1254
              <input type="hidden" name="woothemes_sensei_complete_quiz_nonce" id="woothemes_sensei_complete_quiz_nonce"
@@ -1275,55 +1275,55 @@  discard block
 block discarded – undo
1275 1275
 
1276 1276
          <?php }
1277 1277
 
1278
-     } // End sensei_quiz_action_buttons()
1279
-
1280
-     /**
1281
-      * Fetch the quiz grade
1282
-      *
1283
-      * @since 1.9.0
1284
-      *
1285
-      * @param int $lesson_id
1286
-      * @param int $user_id
1287
-      *
1288
-      * @return double $user_quiz_grade
1289
-      */
1290
-     public static function get_user_quiz_grade( $lesson_id, $user_id ){
1291
-
1292
-         // get the quiz grade
1293
-         $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
1294
-         $user_quiz_grade = 0;
1295
-         if( isset( $user_lesson_status->comment_ID ) ) {
1296
-             $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1297
-         }
1298
-
1299
-         return (double) $user_quiz_grade;
1300
-
1301
-     }
1302
-
1303
-     /**
1304
-      * Check the quiz reset property for a given lesson's quiz.
1305
-      *
1306
-      * The data is stored on the quiz but going forward the quiz post
1307
-      * type will be retired, hence the lesson_id is a require parameter.
1308
-      *
1309
-      * @since 1.9.0
1310
-      *
1311
-      * @param int $lesson_id
1312
-      * @return bool
1313
-      */
1314
-     public static function is_reset_allowed( $lesson_id ){
1315
-
1316
-         $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1317
-
1318
-         $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true );
1319
-         //backwards compatibility
1320
-         if( 'on' == $reset_allowed ) {
1321
-             $reset_allowed = 1;
1322
-         }
1323
-
1324
-         return (bool) $reset_allowed;
1325
-
1326
-     }
1278
+	 } // End sensei_quiz_action_buttons()
1279
+
1280
+	 /**
1281
+	  * Fetch the quiz grade
1282
+	  *
1283
+	  * @since 1.9.0
1284
+	  *
1285
+	  * @param int $lesson_id
1286
+	  * @param int $user_id
1287
+	  *
1288
+	  * @return double $user_quiz_grade
1289
+	  */
1290
+	 public static function get_user_quiz_grade( $lesson_id, $user_id ){
1291
+
1292
+		 // get the quiz grade
1293
+		 $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
1294
+		 $user_quiz_grade = 0;
1295
+		 if( isset( $user_lesson_status->comment_ID ) ) {
1296
+			 $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1297
+		 }
1298
+
1299
+		 return (double) $user_quiz_grade;
1300
+
1301
+	 }
1302
+
1303
+	 /**
1304
+	  * Check the quiz reset property for a given lesson's quiz.
1305
+	  *
1306
+	  * The data is stored on the quiz but going forward the quiz post
1307
+	  * type will be retired, hence the lesson_id is a require parameter.
1308
+	  *
1309
+	  * @since 1.9.0
1310
+	  *
1311
+	  * @param int $lesson_id
1312
+	  * @return bool
1313
+	  */
1314
+	 public static function is_reset_allowed( $lesson_id ){
1315
+
1316
+		 $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1317
+
1318
+		 $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true );
1319
+		 //backwards compatibility
1320
+		 if( 'on' == $reset_allowed ) {
1321
+			 $reset_allowed = 1;
1322
+		 }
1323
+
1324
+		 return (bool) $reset_allowed;
1325
+
1326
+	 }
1327 1327
 
1328 1328
  } // End Class WooThemes_Sensei_Quiz
1329 1329
 
Please login to merge, or discard this patch.
Spacing   +286 added lines, -286 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Quiz Class
@@ -23,24 +23,24 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param $file
25 25
 	 */
26
-	public function __construct ( $file = __FILE__ ) {
26
+	public function __construct($file = __FILE__) {
27 27
 		$this->file = $file;
28
-		$this->meta_fields = array( 'quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required','enable_quiz_reset' );
29
-		add_action( 'save_post', array( $this, 'update_author' ));
28
+		$this->meta_fields = array('quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required', 'enable_quiz_reset');
29
+		add_action('save_post', array($this, 'update_author'));
30 30
 
31 31
 		// listen to the reset button click
32
-		add_action( 'template_redirect', array( $this, 'reset_button_click_listener'  ) );
32
+		add_action('template_redirect', array($this, 'reset_button_click_listener'));
33 33
 
34 34
         // fire the complete quiz button submit for grading action
35
-        add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) );
35
+        add_action('sensei_complete_quiz', array($this, 'user_quiz_submit_listener'));
36 36
 
37 37
 		// fire the save user answers quiz button click responder
38
-		add_action( 'sensei_complete_quiz', array( $this, 'user_save_quiz_answers_listener' ) );
38
+		add_action('sensei_complete_quiz', array($this, 'user_save_quiz_answers_listener'));
39 39
 
40 40
         // fire the load global data function
41
-        add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 );
41
+        add_action('sensei_complete_quiz', array($this, 'load_global_quiz_data'), 80);
42 42
 
43
-        add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') );
43
+        add_action('template_redirect', array($this, 'quiz_has_no_questions'));
44 44
 
45 45
 
46 46
     } // End __construct()
@@ -51,26 +51,26 @@  discard block
 block discarded – undo
51 51
 	* @param int $post_id
52 52
 	* @return void
53 53
 	*/
54
-	public function update_author( $post_id ){
54
+	public function update_author($post_id) {
55 55
 
56 56
 
57 57
 		// If this isn't a 'lesson' post, don't update it.
58 58
         // if this is a revision don't save it
59
-	    if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type']
60
-            || wp_is_post_revision( $post_id ) ) {
59
+	    if (isset($_POST['post_type']) && 'lesson' != $_POST['post_type']
60
+            || wp_is_post_revision($post_id)) {
61 61
 
62 62
                 return;
63 63
 
64 64
         }
65 65
 	    // get the lesson author id to be use late
66
-	    $saved_post = get_post( $post_id );
67
-	    $new_lesson_author_id =  $saved_post->post_author;
66
+	    $saved_post = get_post($post_id);
67
+	    $new_lesson_author_id = $saved_post->post_author;
68 68
 
69 69
 	    //get the lessons quiz
70
-		$lesson_quizzes = Sensei()->lesson->lesson_quizzes( $post_id );
71
-	    foreach ( (array) $lesson_quizzes as $quiz_item ) {
70
+		$lesson_quizzes = Sensei()->lesson->lesson_quizzes($post_id);
71
+	    foreach ((array) $lesson_quizzes as $quiz_item) {
72 72
 
73
-	    	if( ! $quiz_item ) {
73
+	    	if ( ! $quiz_item) {
74 74
 	    		continue;
75 75
 	    	}
76 76
 
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
 			);
82 82
 
83 83
             // remove the action so that it doesn't fire again
84
-            remove_action( 'save_post', array( $this, 'update_author' ));
84
+            remove_action('save_post', array($this, 'update_author'));
85 85
 
86 86
 			// Update the post into the database
87
-		  	wp_update_post( $my_post );
87
+		  	wp_update_post($my_post);
88 88
 	    }
89 89
 
90 90
 	    return;
@@ -98,19 +98,19 @@  discard block
 block discarded – undo
98 98
 	 * @param int $quiz_id
99 99
 	 * @return int @lesson_id
100 100
 	 */
101
-	public function get_lesson_id( $quiz_id ){
101
+	public function get_lesson_id($quiz_id) {
102 102
 
103
-		if( empty( $quiz_id ) || ! intval( $quiz_id ) > 0 ){
103
+		if (empty($quiz_id) || ! intval($quiz_id) > 0) {
104 104
 			global $post;
105
-			if( 'quiz' == get_post_type( $post ) ){
105
+			if ('quiz' == get_post_type($post)) {
106 106
 				$quiz_id = $post->ID;
107
-			}else{
107
+			} else {
108 108
 				return false;
109 109
 			}
110 110
 
111 111
 		}
112 112
 
113
-		$quiz = get_post( $quiz_id );
113
+		$quiz = get_post($quiz_id);
114 114
 		$lesson_id = $quiz->post_parent;
115 115
 
116 116
 		return $lesson_id;
@@ -125,23 +125,23 @@  discard block
 block discarded – undo
125 125
      * @since 1.7.3
126 126
      * @return bool $saved;
127 127
      */
128
-    public function user_save_quiz_answers_listener(){
128
+    public function user_save_quiz_answers_listener() {
129 129
 
130
-        if( ! isset( $_POST[ 'quiz_save' ])
131
-            || !isset( $_POST[ 'sensei_question' ] )
132
-            || empty( $_POST[ 'sensei_question' ] )
133
-            ||  ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce'  ) > 1 ) {
130
+        if ( ! isset($_POST['quiz_save'])
131
+            || ! isset($_POST['sensei_question'])
132
+            || empty($_POST['sensei_question'])
133
+            ||  ! wp_verify_nonce($_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce') > 1) {
134 134
             return;
135 135
         }
136 136
 
137 137
         global $post;
138
-        $lesson_id = $this->get_lesson_id( $post->ID );
139
-        $quiz_answers = $_POST[ 'sensei_question' ];
138
+        $lesson_id = $this->get_lesson_id($post->ID);
139
+        $quiz_answers = $_POST['sensei_question'];
140 140
         // call the save function
141
-        self::save_user_answers( $quiz_answers, $_FILES , $lesson_id  , get_current_user_id() );
141
+        self::save_user_answers($quiz_answers, $_FILES, $lesson_id, get_current_user_id());
142 142
 
143 143
         // remove the hook as it should only fire once per click
144
-        remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' );
144
+        remove_action('sensei_complete_quiz', 'user_save_quiz_answers_listener');
145 145
 
146 146
     } // end user_save_quiz_answers_listener
147 147
 
@@ -160,17 +160,17 @@  discard block
 block discarded – undo
160 160
 	 *
161 161
 	 * @return false or int $answers_saved
162 162
 	 */
163
-	public static function save_user_answers( $quiz_answers, $files = array(), $lesson_id , $user_id = 0 ){
163
+	public static function save_user_answers($quiz_answers, $files = array(), $lesson_id, $user_id = 0) {
164 164
 
165
-        if( ! ( $user_id > 0 ) ){
165
+        if ( ! ($user_id > 0)) {
166 166
             $user_id = get_current_user_id();
167 167
         }
168 168
 
169 169
         // make sure the parameters are valid before continuing
170
-		if( empty( $lesson_id ) || empty( $user_id )
171
-			|| 'lesson' != get_post_type( $lesson_id )
172
-			||!get_userdata( $user_id )
173
-			|| !is_array( $quiz_answers ) ){
170
+		if (empty($lesson_id) || empty($user_id)
171
+			|| 'lesson' != get_post_type($lesson_id)
172
+			||! get_userdata($user_id)
173
+			|| ! is_array($quiz_answers)) {
174 174
 
175 175
 			return false;
176 176
 
@@ -178,23 +178,23 @@  discard block
 block discarded – undo
178 178
 
179 179
 
180 180
         // start the lesson before saving the data in case the user has not started the lesson
181
-        $activity_logged = WooThemes_Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
181
+        $activity_logged = WooThemes_Sensei_Utils::sensei_start_lesson($lesson_id, $user_id);
182 182
 
183 183
 		//prepare the answers
184
-		$prepared_answers = self::prepare_form_submitted_answers( $quiz_answers , $files );
184
+		$prepared_answers = self::prepare_form_submitted_answers($quiz_answers, $files);
185 185
 
186 186
 		// save the user data
187
-        $answers_saved = WooThemes_Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ;
187
+        $answers_saved = WooThemes_Sensei_Utils::add_user_data('quiz_answers', $lesson_id, $prepared_answers, $user_id);
188 188
 
189 189
 		// were the answers saved correctly?
190
-		if( intval( $answers_saved ) > 0){
190
+		if (intval($answers_saved) > 0) {
191 191
 
192 192
             // save transient to make retrieval faster
193 193
             $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
194
-            set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS );
194
+            set_transient($transient_key, $prepared_answers, 10 * DAY_IN_SECONDS);
195 195
 
196 196
             // update the message showed to user
197
-            Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' )  . '</div>';
197
+            Sensei()->frontend->messages = '<div class="sensei-message note">'.__('Quiz Saved Successfully.', 'woothemes-sensei').'</div>';
198 198
         }
199 199
 
200 200
 		return $answers_saved;
@@ -216,41 +216,41 @@  discard block
 block discarded – undo
216 216
 	 *
217 217
 	 * @return array $answers or false
218 218
 	 */
219
-	public function get_user_answers( $lesson_id, $user_id ){
219
+	public function get_user_answers($lesson_id, $user_id) {
220 220
 
221 221
 		$answers = false;
222 222
 
223
-		if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
224
-		|| ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
223
+		if ( ! intval($lesson_id) > 0 || 'lesson' != get_post_type($lesson_id)
224
+		|| ! intval($user_id) > 0 || ! get_userdata($user_id)) {
225 225
 			return false;
226 226
 		}
227 227
 
228 228
         // save some time and get the transient cached data
229 229
         $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
230
-        $transient_cached_answers = get_transient( $transient_key );
230
+        $transient_cached_answers = get_transient($transient_key);
231 231
 
232 232
         // return the transient or get the values get the values from the comment meta
233
-        if( !empty( $transient_cached_answers  ) && false != $transient_cached_answers ){
233
+        if ( ! empty($transient_cached_answers) && false != $transient_cached_answers) {
234 234
 
235 235
             $encoded_user_answers = $transient_cached_answers;
236 236
 
237
-        }else{
237
+        } else {
238 238
 
239
-            $encoded_user_answers = WooThemes_Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id  , $user_id );
239
+            $encoded_user_answers = WooThemes_Sensei_Utils::get_user_data('quiz_answers', $lesson_id, $user_id);
240 240
 
241 241
         } // end if transient check
242 242
 
243
-		if( ! is_array( $encoded_user_answers ) ){
243
+		if ( ! is_array($encoded_user_answers)) {
244 244
 			return false;
245 245
 		}
246 246
 
247 247
         //set the transient with the new valid data for faster retrieval in future
248
-        set_transient( $transient_key,  $encoded_user_answers, 10 * DAY_IN_SECONDS);
248
+        set_transient($transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS);
249 249
 
250 250
 		// decode an unserialize all answers
251
-		foreach( $encoded_user_answers as $question_id => $encoded_answer ) {
252
-			$decoded_answer = base64_decode( $encoded_answer );
253
-			$answers[$question_id] = maybe_unserialize( $decoded_answer );
251
+		foreach ($encoded_user_answers as $question_id => $encoded_answer) {
252
+			$decoded_answer = base64_decode($encoded_answer);
253
+			$answers[$question_id] = maybe_unserialize($decoded_answer);
254 254
 		}
255 255
 
256 256
 		return $answers;
@@ -267,23 +267,23 @@  discard block
 block discarded – undo
267 267
 	 *
268 268
 	 * @return void;
269 269
 	 */
270
-	public function reset_button_click_listener( ){
270
+	public function reset_button_click_listener( ) {
271 271
 
272
-		if( ! isset( $_POST[ 'quiz_reset' ])
273
-			||  ! wp_verify_nonce( $_POST['woothemes_sensei_reset_quiz_nonce'], 'woothemes_sensei_reset_quiz_nonce'  ) > 1 ) {
272
+		if ( ! isset($_POST['quiz_reset'])
273
+			||  ! wp_verify_nonce($_POST['woothemes_sensei_reset_quiz_nonce'], 'woothemes_sensei_reset_quiz_nonce') > 1) {
274 274
 
275 275
 			return; // exit
276 276
 		}
277 277
 
278 278
 		global $post;
279 279
 		$current_quiz_id = $post->ID;
280
-		$lesson_id = $this->get_lesson_id( $current_quiz_id );
280
+		$lesson_id = $this->get_lesson_id($current_quiz_id);
281 281
 
282 282
         // reset all user data
283
-        $this->reset_user_lesson_data( $lesson_id, get_current_user_id() );
283
+        $this->reset_user_lesson_data($lesson_id, get_current_user_id());
284 284
 
285 285
 		//this function should only run once
286
-		remove_action( 'template_redirect', array( $this, 'reset_button_click_listener'  ) );
286
+		remove_action('template_redirect', array($this, 'reset_button_click_listener'));
287 287
 
288 288
 	} // end reset_button_click_listener
289 289
 
@@ -302,18 +302,18 @@  discard block
 block discarded – undo
302 302
 	public function user_quiz_submit_listener() {
303 303
 
304 304
         // only respond to valid quiz completion submissions
305
-        if( ! isset( $_POST[ 'quiz_complete' ])
306
-            || !isset( $_POST[ 'sensei_question' ] )
307
-            || empty( $_POST[ 'sensei_question' ] )
308
-            ||  ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce'  ) > 1 ) {
305
+        if ( ! isset($_POST['quiz_complete'])
306
+            || ! isset($_POST['sensei_question'])
307
+            || empty($_POST['sensei_question'])
308
+            ||  ! wp_verify_nonce($_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce') > 1) {
309 309
             return;
310 310
         }
311 311
 
312 312
         global $post, $current_user;
313
-        $lesson_id = $this->get_lesson_id( $post->ID );
314
-        $quiz_answers = $_POST[ 'sensei_question' ];
313
+        $lesson_id = $this->get_lesson_id($post->ID);
314
+        $quiz_answers = $_POST['sensei_question'];
315 315
 
316
-        self::submit_answers_for_grading( $quiz_answers, $_FILES ,  $lesson_id  , $current_user->ID );
316
+        self::submit_answers_for_grading($quiz_answers, $_FILES, $lesson_id, $current_user->ID);
317 317
 
318 318
 	} // End sensei_complete_quiz()
319 319
 
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
      * @access public
328 328
      *
329 329
      */
330
-    public function load_global_quiz_data(){
330
+    public function load_global_quiz_data() {
331 331
 
332 332
         global  $post, $current_user;
333 333
         $this->data = new stdClass();
@@ -336,46 +336,46 @@  discard block
 block discarded – undo
336 336
         $grade = 0;
337 337
 
338 338
         // Get Quiz Questions
339
-        $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID );
339
+        $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions($post->ID);
340 340
 
341
-        $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) );
341
+        $quiz_lesson_id = absint(get_post_meta($post->ID, '_quiz_lesson', true));
342 342
 
343 343
         // Get quiz grade type
344
-        $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true );
344
+        $quiz_grade_type = get_post_meta($post->ID, '_quiz_grade_type', true);
345 345
 
346 346
         // Get quiz pass setting
347
-        $pass_required = get_post_meta( $post->ID, '_pass_required', true );
347
+        $pass_required = get_post_meta($post->ID, '_pass_required', true);
348 348
 
349 349
         // Get quiz pass mark
350
-        $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) );
350
+        $quiz_passmark = abs(round(doubleval(get_post_meta($post->ID, '_quiz_passmark', true)), 2));
351 351
 
352 352
         // Get latest quiz answers and grades
353
-        $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID );
354
-        $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() );
355
-        $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID );
353
+        $lesson_id = Sensei()->quiz->get_lesson_id($post->ID);
354
+        $user_quizzes = Sensei()->quiz->get_user_answers($lesson_id, get_current_user_id());
355
+        $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status($quiz_lesson_id, $current_user->ID);
356 356
         $user_quiz_grade = 0;
357
-        if( isset( $user_lesson_status->comment_ID ) ) {
358
-            $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
357
+        if (isset($user_lesson_status->comment_ID)) {
358
+            $user_quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true);
359 359
         }
360 360
 
361
-        if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); }
361
+        if ( ! is_array($user_quizzes)) { $user_quizzes = array(); }
362 362
 
363 363
         // Check again that the lesson is complete
364
-        $user_lesson_end = WooThemes_Sensei_Utils::user_completed_lesson( $user_lesson_status );
364
+        $user_lesson_end = WooThemes_Sensei_Utils::user_completed_lesson($user_lesson_status);
365 365
         $user_lesson_complete = false;
366
-        if ( $user_lesson_end ) {
366
+        if ($user_lesson_end) {
367 367
             $user_lesson_complete = true;
368 368
         } // End If Statement
369 369
 
370
-        $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true );
370
+        $reset_allowed = get_post_meta($post->ID, '_enable_quiz_reset', true);
371 371
         //backwards compatibility
372
-        if( 'on' == $reset_allowed ) {
372
+        if ('on' == $reset_allowed) {
373 373
             $reset_allowed = 1;
374 374
         }
375 375
 
376 376
         // Build frontend data object for backwards compatibility
377 377
         // using this is no longer recommended
378
-        $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
378
+        $this->data->user_quiz_grade = $user_quiz_grade; // Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
379 379
         $this->data->quiz_passmark = $quiz_passmark;
380 380
         $this->data->quiz_lesson = $quiz_lesson_id;
381 381
         $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true );
@@ -400,41 +400,41 @@  discard block
 block discarded – undo
400 400
 	 * @param $files
401 401
 	 * @return array
402 402
 	 */
403
-	public static function prepare_form_submitted_answers( $unprepared_answers,  $files ){
403
+	public static function prepare_form_submitted_answers($unprepared_answers, $files) {
404 404
 
405 405
 
406 406
 		$prepared_answers = array();
407 407
 
408 408
 		// validate incoming answers
409
-		if( empty( $unprepared_answers  ) || ! is_array( $unprepared_answers ) ){
409
+		if (empty($unprepared_answers) || ! is_array($unprepared_answers)) {
410 410
 			return false;
411 411
 		}
412 412
 
413 413
 		// Loop through submitted quiz answers and save them appropriately
414
-		foreach( $unprepared_answers as $question_id => $answer ) {
414
+		foreach ($unprepared_answers as $question_id => $answer) {
415 415
 
416 416
 			//get the current questions question type
417
-            $question_type = Sensei()->question->get_question_type( $question_id );
417
+            $question_type = Sensei()->question->get_question_type($question_id);
418 418
 
419 419
 			// Sanitise answer
420
-			if( 0 == get_magic_quotes_gpc() ) {
421
-				$answer = wp_unslash( $answer );
420
+			if (0 == get_magic_quotes_gpc()) {
421
+				$answer = wp_unslash($answer);
422 422
 			}
423 423
 
424 424
             // compress the answer for saving
425
-			if( 'multi-line' == $question_type ) {
426
-                $answer = esc_html( $answer );
427
-            }elseif( 'file-upload' == $question_type  ){
428
-                $file_key = 'file_upload_' . $question_id;
429
-                if( isset( $files[ $file_key ] ) ) {
430
-                        $attachment_id = WooThemes_Sensei_Utils::upload_file(  $files[ $file_key ] );
431
-                        if( $attachment_id ) {
425
+			if ('multi-line' == $question_type) {
426
+                $answer = esc_html($answer);
427
+            }elseif ('file-upload' == $question_type) {
428
+                $file_key = 'file_upload_'.$question_id;
429
+                if (isset($files[$file_key])) {
430
+                        $attachment_id = WooThemes_Sensei_Utils::upload_file($files[$file_key]);
431
+                        if ($attachment_id) {
432 432
                             $answer = $attachment_id;
433 433
                         }
434 434
                     }
435 435
             } // end if
436 436
 
437
-			$prepared_answers[ $question_id ] =  base64_encode( maybe_serialize( $answer ) );
437
+			$prepared_answers[$question_id] = base64_encode(maybe_serialize($answer));
438 438
 
439 439
 		}// end for each $quiz_answers
440 440
 
@@ -454,54 +454,54 @@  discard block
 block discarded – undo
454 454
      * @param int $user_id
455 455
      * @param int $lesson_id
456 456
      */
457
-    public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){
457
+    public function reset_user_lesson_data($lesson_id, $user_id = 0) {
458 458
 
459 459
         //make sure the parameters are valid
460
-        if( empty( $lesson_id ) || empty( $user_id )
461
-            || 'lesson' != get_post_type( $lesson_id )
462
-            || ! get_userdata( $user_id ) ){
460
+        if (empty($lesson_id) || empty($user_id)
461
+            || 'lesson' != get_post_type($lesson_id)
462
+            || ! get_userdata($user_id)) {
463 463
             return false;
464 464
         }
465 465
 
466 466
 
467 467
 
468 468
         //get the users lesson status to make
469
-        $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
470
-        if( ! isset( $user_lesson_status->comment_ID ) ) {
469
+        $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_id, $user_id);
470
+        if ( ! isset($user_lesson_status->comment_ID)) {
471 471
             // this user is not taking this lesson so this process is not needed
472 472
             return false;
473 473
         }
474 474
 
475 475
         //get the lesson quiz and course
476
-        $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
477
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
476
+        $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
477
+        $course_id = Sensei()->lesson->get_course_id($lesson_id);
478 478
 
479 479
         // reset the transients
480 480
         $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
481 481
         $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id;
482 482
         $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
483
-        delete_transient( $answers_transient_key );
484
-        delete_transient( $grades_transient_key );
485
-        delete_transient( $answers_feedback_transient_key );
483
+        delete_transient($answers_transient_key);
484
+        delete_transient($grades_transient_key);
485
+        delete_transient($answers_feedback_transient_key);
486 486
 
487 487
         // reset the quiz answers and feedback notes
488
-        $deleted_answers = WooThemes_Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id );
489
-        $deleted_grades = WooThemes_Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id );
490
-        $deleted_user_feedback = WooThemes_Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id );
488
+        $deleted_answers = WooThemes_Sensei_Utils::delete_user_data('quiz_answers', $lesson_id, $user_id);
489
+        $deleted_grades = WooThemes_Sensei_Utils::delete_user_data('quiz_grades', $lesson_id, $user_id);
490
+        $deleted_user_feedback = WooThemes_Sensei_Utils::delete_user_data('quiz_answers_feedback', $lesson_id, $user_id);
491 491
 
492 492
         // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade
493
-        WooThemes_Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id );
493
+        WooThemes_Sensei_Utils::sensei_delete_quiz_answers($quiz_id, $user_id);
494 494
 
495
-        WooThemes_Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) );
495
+        WooThemes_Sensei_Utils::update_lesson_status($user_id, $lesson_id, 'in-progress', array('questions_asked' => '', 'grade' => ''));
496 496
 
497 497
         // Update course completion
498
-        WooThemes_Sensei_Utils::update_course_status( $user_id, $course_id );
498
+        WooThemes_Sensei_Utils::update_course_status($user_id, $course_id);
499 499
 
500 500
         // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson()
501
-        do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id );
502
-        Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>';
501
+        do_action('sensei_user_lesson_reset', $user_id, $lesson_id);
502
+        Sensei()->frontend->messages = '<div class="sensei-message note">'.__('Quiz Reset Successfully.', 'woothemes-sensei').'</div>';
503 503
 
504
-        return ( $deleted_answers && $deleted_grades ) ;
504
+        return ($deleted_answers && $deleted_grades);
505 505
 
506 506
     } // end reset_user_lesson_data
507 507
 
@@ -521,20 +521,20 @@  discard block
 block discarded – undo
521 521
       *
522 522
       * @return bool $answers_submitted
523 523
       */
524
-     public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){
524
+     public static function submit_answers_for_grading($quiz_answers, $files = array(), $lesson_id, $user_id = 0) {
525 525
 
526 526
          $answers_submitted = false;
527 527
 
528 528
          // get the user_id if none was passed in use the current logged in user
529
-         if( ! intval( $user_id ) > 0 ) {
529
+         if ( ! intval($user_id) > 0) {
530 530
              $user_id = get_current_user_id();
531 531
          }
532 532
 
533 533
          // make sure the parameters are valid before continuing
534
-         if( empty( $lesson_id ) || empty( $user_id )
535
-             || 'lesson' != get_post_type( $lesson_id )
536
-             ||!get_userdata( $user_id )
537
-             || !is_array( $quiz_answers ) ){
534
+         if (empty($lesson_id) || empty($user_id)
535
+             || 'lesson' != get_post_type($lesson_id)
536
+             ||! get_userdata($user_id)
537
+             || ! is_array($quiz_answers)) {
538 538
 
539 539
              return false;
540 540
 
@@ -544,38 +544,38 @@  discard block
 block discarded – undo
544 544
          $grade = 0;
545 545
 
546 546
          // Get Quiz ID
547
-         $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
547
+         $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
548 548
 
549 549
          // Get quiz grade type
550
-         $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true );
550
+         $quiz_grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true);
551 551
 
552 552
          // Get quiz pass setting
553
-         $pass_required = get_post_meta( $quiz_id, '_pass_required', true );
553
+         $pass_required = get_post_meta($quiz_id, '_pass_required', true);
554 554
 
555 555
          // Get the minimum percentage need to pass this quiz
556
-         $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
556
+         $quiz_pass_percentage = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2));
557 557
 
558 558
          // Handle Quiz Questions asked
559 559
          // This is to ensure we save the questions that we've asked this user and that this can't be change unless
560 560
          // the quiz is reset by admin or user( user: only if the setting is enabled ).
561 561
          // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions
562
-         $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
563
-         $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true );
564
-         if( empty( $questions_asked ) ){
562
+         $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_id, $user_id);
563
+         $questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true);
564
+         if (empty($questions_asked)) {
565 565
 
566
-             $questions_asked = array_keys( $quiz_answers );
567
-             $questions_asked_string = implode( ',', $questions_asked );
566
+             $questions_asked = array_keys($quiz_answers);
567
+             $questions_asked_string = implode(',', $questions_asked);
568 568
 
569 569
              // Save questions that were asked in this quiz
570
-             update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string );
570
+             update_comment_meta($user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string);
571 571
 
572 572
          }
573 573
 
574 574
          // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson
575
-         self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id );
575
+         self::save_user_answers($quiz_answers, $files, $lesson_id, $user_id);
576 576
 
577 577
          // Grade quiz
578
-         $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type );
578
+         $grade = Sensei_Grading::grade_quiz_auto($quiz_id, $quiz_answers, 0, $quiz_grade_type);
579 579
 
580 580
          // Get Lesson Grading Setting
581 581
          $lesson_metadata = array();
@@ -585,13 +585,13 @@  discard block
 block discarded – undo
585 585
          $answers_submitted = true;
586 586
 
587 587
          // if this condition is false the quiz should manually be graded by admin
588
-         if ('auto' == $quiz_grade_type && ! is_wp_error( $grade )  ) {
588
+         if ('auto' == $quiz_grade_type && ! is_wp_error($grade)) {
589 589
 
590 590
              // Quiz has been automatically Graded
591
-             if ( 'on' == $pass_required ) {
591
+             if ('on' == $pass_required) {
592 592
 
593 593
                  // Student has reached the pass mark and lesson is complete
594
-                 if ( $quiz_pass_percentage <= $grade ) {
594
+                 if ($quiz_pass_percentage <= $grade) {
595 595
 
596 596
                      $lesson_status = 'passed';
597 597
 
@@ -612,9 +612,9 @@  discard block
 block discarded – undo
612 612
 
613 613
          } // end if ! is_wp_error( $grade ...
614 614
 
615
-         WooThemes_Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata );
615
+         WooThemes_Sensei_Utils::update_lesson_status($user_id, $lesson_id, $lesson_status, $lesson_metadata);
616 616
 
617
-         if( 'passed' == $lesson_status || 'graded' == $lesson_status ){
617
+         if ('passed' == $lesson_status || 'graded' == $lesson_status) {
618 618
 
619 619
              /**
620 620
               * Lesson end action hook
@@ -624,7 +624,7 @@  discard block
 block discarded – undo
624 624
               * @param int $user_id
625 625
               * @param int $lesson_id
626 626
               */
627
-             do_action( 'sensei_user_lesson_end', $user_id, $lesson_id );
627
+             do_action('sensei_user_lesson_end', $user_id, $lesson_id);
628 628
 
629 629
          }
630 630
 
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
           * @param string $quiz_pass_percentage
641 641
           * @param string $quiz_grade_type
642 642
           */
643
-         do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type );
643
+         do_action('sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type);
644 644
 
645 645
          return $answers_submitted;
646 646
 
@@ -660,38 +660,38 @@  discard block
 block discarded – undo
660 660
       *
661 661
       * @return bool $answers_submitted
662 662
       */
663
-     public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){
663
+     public function get_user_question_answer($lesson_id, $question_id, $user_id = 0) {
664 664
 
665 665
          // parameter validation
666
-         if( empty( $lesson_id ) || empty( $question_id )
667
-             || ! ( intval( $lesson_id  ) > 0 )
668
-             || ! ( intval( $question_id  ) > 0 )
669
-             || 'lesson' != get_post_type( $lesson_id )
670
-             || 'question' != get_post_type( $question_id )) {
666
+         if (empty($lesson_id) || empty($question_id)
667
+             || ! (intval($lesson_id) > 0)
668
+             || ! (intval($question_id) > 0)
669
+             || 'lesson' != get_post_type($lesson_id)
670
+             || 'question' != get_post_type($question_id)) {
671 671
 
672 672
              return false;
673 673
          }
674 674
 
675
-         if( ! ( intval( $user_id ) > 0 )   ){
675
+         if ( ! (intval($user_id) > 0)) {
676 676
              $user_id = get_current_user_id();
677 677
          }
678 678
 
679
-         $users_answers = $this->get_user_answers( $lesson_id, $user_id );
679
+         $users_answers = $this->get_user_answers($lesson_id, $user_id);
680 680
 
681
-         if( !$users_answers || empty( $users_answers )
682
-         ||  ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){
681
+         if ( ! $users_answers || empty($users_answers)
682
+         ||  ! is_array($users_answers) || ! isset($users_answers[$question_id])) {
683 683
 
684 684
              //Fallback for pre 1.7.4 data
685
-             $comment =  WooThemes_Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true );
685
+             $comment = WooThemes_Sensei_Utils::sensei_check_for_activity(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer'), true);
686 686
 
687
-             if( ! isset( $comment->comment_content ) ){
687
+             if ( ! isset($comment->comment_content)) {
688 688
                  return false;
689 689
              }
690 690
 
691
-             return maybe_unserialize( base64_decode( $comment->comment_content ) );
691
+             return maybe_unserialize(base64_decode($comment->comment_content));
692 692
          }
693 693
 
694
-         return $users_answers[ $question_id ];
694
+         return $users_answers[$question_id];
695 695
 
696 696
      }// end get_user_question_answer
697 697
 
@@ -712,18 +712,18 @@  discard block
 block discarded – undo
712 712
       *
713 713
       * @return bool
714 714
       */
715
-     public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){
715
+     public function set_user_grades($quiz_grades, $lesson_id, $user_id = 0) {
716 716
 
717 717
          // get the user_id if none was passed in use the current logged in user
718
-         if( ! intval( $user_id ) > 0 ) {
718
+         if ( ! intval($user_id) > 0) {
719 719
              $user_id = get_current_user_id();
720 720
          }
721 721
 
722 722
          // make sure the parameters are valid before continuing
723
-         if( empty( $lesson_id ) || empty( $user_id )
724
-             || 'lesson' != get_post_type( $lesson_id )
725
-             ||!get_userdata( $user_id )
726
-             || !is_array( $quiz_grades ) ){
723
+         if (empty($lesson_id) || empty($user_id)
724
+             || 'lesson' != get_post_type($lesson_id)
725
+             ||! get_userdata($user_id)
726
+             || ! is_array($quiz_grades)) {
727 727
 
728 728
              return false;
729 729
 
@@ -732,15 +732,15 @@  discard block
 block discarded – undo
732 732
          $success = false;
733 733
 
734 734
          // save that data for the user on the lesson comment meta
735
-         $comment_meta_id = WooThemes_Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id   );
735
+         $comment_meta_id = WooThemes_Sensei_Utils::add_user_data('quiz_grades', $lesson_id, $quiz_grades, $user_id);
736 736
 
737 737
          // were the grades save successfully ?
738
-         if( intval( $comment_meta_id ) > 0 ) {
738
+         if (intval($comment_meta_id) > 0) {
739 739
 
740 740
              $success = true;
741 741
              // save transient
742
-             $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id;
743
-             set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS );
742
+             $transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id;
743
+             set_transient($transient_key, $quiz_grades, 10 * DAY_IN_SECONDS);
744 744
          }
745 745
 
746 746
          return $success;
@@ -759,36 +759,36 @@  discard block
 block discarded – undo
759 759
       *
760 760
       * @return array $user_quiz_grades or false if none exists for this users
761 761
       */
762
-     public function get_user_grades( $lesson_id, $user_id = 0 ){
762
+     public function get_user_grades($lesson_id, $user_id = 0) {
763 763
 
764 764
          $user_grades = array();
765 765
 
766 766
          // get the user_id if none was passed in use the current logged in user
767
-         if( ! intval( $user_id ) > 0 ) {
767
+         if ( ! intval($user_id) > 0) {
768 768
              $user_id = get_current_user_id();
769 769
          }
770 770
 
771
-         if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
772
-             || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
771
+         if ( ! intval($lesson_id) > 0 || 'lesson' != get_post_type($lesson_id)
772
+             || ! intval($user_id) > 0 || ! get_userdata($user_id)) {
773 773
              return false;
774 774
          }
775 775
 
776 776
          // save some time and get the transient cached data
777
-         $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id;
778
-         $user_grades = get_transient( $transient_key );
777
+         $transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id;
778
+         $user_grades = get_transient($transient_key);
779 779
 
780 780
          // get the data if nothing was stored in the transient
781
-         if( empty( $user_grades  ) || false != $user_grades ){
781
+         if (empty($user_grades) || false != $user_grades) {
782 782
 
783
-             $user_grades = WooThemes_Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id );
783
+             $user_grades = WooThemes_Sensei_Utils::get_user_data('quiz_grades', $lesson_id, $user_id);
784 784
 
785 785
              //set the transient with the new valid data for faster retrieval in future
786
-             set_transient( $transient_key,  $user_grades, 10 * DAY_IN_SECONDS );
786
+             set_transient($transient_key, $user_grades, 10 * DAY_IN_SECONDS);
787 787
 
788 788
          } // end if transient check
789 789
 
790 790
          // if there is no data for this user
791
-         if( ! is_array( $user_grades ) ){
791
+         if ( ! is_array($user_grades)) {
792 792
              return false;
793 793
          }
794 794
 
@@ -811,21 +811,21 @@  discard block
 block discarded – undo
811 811
       *
812 812
       * @return bool $question_grade
813 813
       */
814
-     public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){
814
+     public function get_user_question_grade($lesson_id, $question_id, $user_id = 0) {
815 815
 
816 816
          // parameter validation
817
-         if( empty( $lesson_id ) || empty( $question_id )
818
-             || ! ( intval( $lesson_id  ) > 0 )
819
-             || ! ( intval( $question_id  ) > 0 )
820
-             || 'lesson' != get_post_type( $lesson_id )
821
-             || 'question' != get_post_type( $question_id )) {
817
+         if (empty($lesson_id) || empty($question_id)
818
+             || ! (intval($lesson_id) > 0)
819
+             || ! (intval($question_id) > 0)
820
+             || 'lesson' != get_post_type($lesson_id)
821
+             || 'question' != get_post_type($question_id)) {
822 822
 
823 823
              return false;
824 824
          }
825 825
 
826
-         $all_user_grades = self::get_user_grades( $lesson_id,$user_id );
826
+         $all_user_grades = self::get_user_grades($lesson_id, $user_id);
827 827
 
828
-         if( ! $all_user_grades || ! isset(  $all_user_grades[ $question_id ] ) ){
828
+         if ( ! $all_user_grades || ! isset($all_user_grades[$question_id])) {
829 829
 
830 830
              //fallback to data pre 1.7.4
831 831
              $args = array(
@@ -834,17 +834,17 @@  discard block
 block discarded – undo
834 834
                  'type'    => 'sensei_user_answer'
835 835
              );
836 836
 
837
-             $question_activity = WooThemes_Sensei_Utils::sensei_check_for_activity( $args , true );
837
+             $question_activity = WooThemes_Sensei_Utils::sensei_check_for_activity($args, true);
838 838
              $fall_back_grade = false;
839
-             if( isset( $question_activity->comment_ID ) ){
840
-                 $fall_back_grade = get_comment_meta(  $question_activity->comment_ID , 'user_grade', true );
839
+             if (isset($question_activity->comment_ID)) {
840
+                 $fall_back_grade = get_comment_meta($question_activity->comment_ID, 'user_grade', true);
841 841
              }
842 842
 
843 843
              return $fall_back_grade;
844 844
 
845 845
          } // end if $all_user_grades...
846 846
 
847
-         return $all_user_grades[ $question_id ];
847
+         return $all_user_grades[$question_id];
848 848
 
849 849
      }// end get_user_question_grade
850 850
 
@@ -866,13 +866,13 @@  discard block
 block discarded – undo
866 866
       *
867 867
       * @return false or int $feedback_saved
868 868
       */
869
-    public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){
869
+    public function save_user_answers_feedback($answers_feedback, $lesson_id, $user_id = 0) {
870 870
 
871 871
         // make sure the parameters are valid before continuing
872
-        if( empty( $lesson_id ) || empty( $user_id )
873
-            || 'lesson' != get_post_type( $lesson_id )
874
-            ||!get_userdata( $user_id )
875
-            || !is_array( $answers_feedback ) ){
872
+        if (empty($lesson_id) || empty($user_id)
873
+            || 'lesson' != get_post_type($lesson_id)
874
+            ||! get_userdata($user_id)
875
+            || ! is_array($answers_feedback)) {
876 876
 
877 877
             return false;
878 878
 
@@ -880,25 +880,25 @@  discard block
 block discarded – undo
880 880
 
881 881
 
882 882
         // check if the lesson is started before saving, if not start the lesson for the user
883
-        if ( !( 0 < intval( WooThemes_Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) {
884
-            WooThemes_Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
883
+        if ( ! (0 < intval(WooThemes_Sensei_Utils::user_started_lesson($lesson_id, $user_id)))) {
884
+            WooThemes_Sensei_Utils::sensei_start_lesson($lesson_id, $user_id);
885 885
         }
886 886
 
887 887
         // encode the feedback
888
-        $encoded_answers_feedback =  array();
889
-        foreach( $answers_feedback as $question_id => $feedback ){
890
-            $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback );
888
+        $encoded_answers_feedback = array();
889
+        foreach ($answers_feedback as $question_id => $feedback) {
890
+            $encoded_answers_feedback[$question_id] = base64_encode($feedback);
891 891
         }
892 892
 
893 893
         // save the user data
894
-        $feedback_saved = WooThemes_Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ;
894
+        $feedback_saved = WooThemes_Sensei_Utils::add_user_data('quiz_answers_feedback', $lesson_id, $encoded_answers_feedback, $user_id);
895 895
 
896 896
         //Were the the question feedback save correctly?
897
-        if( intval( $feedback_saved ) > 0){
897
+        if (intval($feedback_saved) > 0) {
898 898
 
899 899
             // save transient to make retrieval faster in future
900 900
              $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
901
-             set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS );
901
+             set_transient($transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS);
902 902
 
903 903
         }
904 904
 
@@ -923,42 +923,42 @@  discard block
 block discarded – undo
923 923
       *  $type string $question_feedback
924 924
       * }
925 925
       */
926
-     public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){
926
+     public function get_user_answers_feedback($lesson_id, $user_id = 0) {
927 927
 
928 928
          $answers_feedback = array();
929 929
 
930 930
          // get the user_id if none was passed in use the current logged in user
931
-         if( ! intval( $user_id ) > 0 ) {
931
+         if ( ! intval($user_id) > 0) {
932 932
              $user_id = get_current_user_id();
933 933
          }
934 934
 
935
-         if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
936
-             || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
935
+         if ( ! intval($lesson_id) > 0 || 'lesson' != get_post_type($lesson_id)
936
+             || ! intval($user_id) > 0 || ! get_userdata($user_id)) {
937 937
              return false;
938 938
          }
939 939
 
940 940
          // first check the transient to save a few split seconds
941 941
          $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
942
-         $encoded_feedback = get_transient( $transient_key );
942
+         $encoded_feedback = get_transient($transient_key);
943 943
 
944 944
          // get the data if nothing was stored in the transient
945
-         if( empty( $encoded_feedback  ) || !$encoded_feedback ){
945
+         if (empty($encoded_feedback) || ! $encoded_feedback) {
946 946
 
947
-             $encoded_feedback = WooThemes_Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id );
947
+             $encoded_feedback = WooThemes_Sensei_Utils::get_user_data('quiz_answers_feedback', $lesson_id, $user_id);
948 948
 
949 949
              //set the transient with the new valid data for faster retrieval in future
950
-             set_transient( $transient_key,  $encoded_feedback, 10 * DAY_IN_SECONDS);
950
+             set_transient($transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS);
951 951
 
952 952
          } // end if transient check
953 953
 
954 954
          // if there is no data for this user
955
-         if( ! is_array( $encoded_feedback ) ){
955
+         if ( ! is_array($encoded_feedback)) {
956 956
              return false;
957 957
          }
958 958
 
959
-         foreach( $encoded_feedback as $question_id => $feedback ){
959
+         foreach ($encoded_feedback as $question_id => $feedback) {
960 960
 
961
-             $answers_feedback[ $question_id ] = base64_decode( $feedback );
961
+             $answers_feedback[$question_id] = base64_decode($feedback);
962 962
 
963 963
          }
964 964
 
@@ -981,25 +981,25 @@  discard block
 block discarded – undo
981 981
       *
982 982
       * @return string $feedback or bool if false
983 983
       */
984
-     public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){
984
+     public function get_user_question_feedback($lesson_id, $question_id, $user_id = 0) {
985 985
 
986 986
          $feedback = false;
987 987
 
988 988
          // parameter validation
989
-         if( empty( $lesson_id ) || empty( $question_id )
990
-             || ! ( intval( $lesson_id  ) > 0 )
991
-             || ! ( intval( $question_id  ) > 0 )
992
-             || 'lesson' != get_post_type( $lesson_id )
993
-             || 'question' != get_post_type( $question_id )) {
989
+         if (empty($lesson_id) || empty($question_id)
990
+             || ! (intval($lesson_id) > 0)
991
+             || ! (intval($question_id) > 0)
992
+             || 'lesson' != get_post_type($lesson_id)
993
+             || 'question' != get_post_type($question_id)) {
994 994
 
995 995
              return false;
996 996
          }
997 997
 
998 998
          // get all the feedback for the user on the given lesson
999
-         $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id );
999
+         $all_feedback = $this->get_user_answers_feedback($lesson_id, $user_id);
1000 1000
 
1001
-         if( !$all_feedback || empty( $all_feedback )
1002
-             || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){
1001
+         if ( ! $all_feedback || empty($all_feedback)
1002
+             || ! is_array($all_feedback) || ! isset($all_feedback[$question_id])) {
1003 1003
 
1004 1004
              //fallback to data pre 1.7.4
1005 1005
 
@@ -1009,23 +1009,23 @@  discard block
 block discarded – undo
1009 1009
                  'user_id' => $user_id,
1010 1010
                  'type'    => 'sensei_user_answer'
1011 1011
              );
1012
-             $question_activity = WooThemes_Sensei_Utils::sensei_check_for_activity( $args , true );
1012
+             $question_activity = WooThemes_Sensei_Utils::sensei_check_for_activity($args, true);
1013 1013
 
1014 1014
              // set the default to false and return that if no old data is available.
1015
-             if( isset( $question_activity->comment_ID ) ){
1016
-                 $feedback = base64_decode( get_comment_meta(  $question_activity->comment_ID , 'answer_note', true ) );
1015
+             if (isset($question_activity->comment_ID)) {
1016
+                 $feedback = base64_decode(get_comment_meta($question_activity->comment_ID, 'answer_note', true));
1017 1017
              }
1018 1018
 
1019 1019
              // finally use the default question feedback
1020
-             if( empty( $feedback ) ){
1021
-                 $feedback = get_post_meta( $question_id, '_answer_feedback', true );
1020
+             if (empty($feedback)) {
1021
+                 $feedback = get_post_meta($question_id, '_answer_feedback', true);
1022 1022
              }
1023 1023
 
1024 1024
              return $feedback;
1025 1025
 
1026 1026
          }
1027 1027
 
1028
-         return $all_feedback[ $question_id ];
1028
+         return $all_feedback[$question_id];
1029 1029
 
1030 1030
      } // end get_user_question_feedback
1031 1031
 
@@ -1044,7 +1044,7 @@  discard block
 block discarded – undo
1044 1044
      public function quiz_has_no_questions() {
1045 1045
 
1046 1046
 
1047
-         if( ! is_singular( 'quiz' ) )  {
1047
+         if ( ! is_singular('quiz')) {
1048 1048
              return;
1049 1049
          }
1050 1050
 
@@ -1052,11 +1052,11 @@  discard block
 block discarded – undo
1052 1052
 
1053 1053
          $lesson_id = $this->get_lesson_id($post->ID);
1054 1054
 
1055
-         $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
1055
+         $has_questions = get_post_meta($lesson_id, '_quiz_has_questions', true);
1056 1056
 
1057 1057
          $lesson = get_post($lesson_id);
1058 1058
 
1059
-         if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) {
1059
+         if (is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name") {
1060 1060
 
1061 1061
              wp_redirect(get_permalink($lesson->ID), 301);
1062 1062
              exit;
@@ -1070,7 +1070,7 @@  discard block
 block discarded – undo
1070 1070
   *
1071 1071
   * @deprecated since 1.9.0
1072 1072
   */
1073
- public static function deprecate_quiz_sensei_single_main_content_hook(){
1073
+ public static function deprecate_quiz_sensei_single_main_content_hook() {
1074 1074
 
1075 1075
      sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after');
1076 1076
 
@@ -1080,7 +1080,7 @@  discard block
 block discarded – undo
1080 1080
      *
1081 1081
      * @deprecated since 1.9.0
1082 1082
      */
1083
-     public static function deprecate_quiz_sensei_quiz_single_title_hook(){
1083
+     public static function deprecate_quiz_sensei_quiz_single_title_hook() {
1084 1084
 
1085 1085
          sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before ');
1086 1086
 
@@ -1093,29 +1093,29 @@  discard block
 block discarded – undo
1093 1093
       * @param int $id title post id
1094 1094
       * @return string $quiz_title
1095 1095
       */
1096
-     public static function single_quiz_title( $title, $post_id ){
1096
+     public static function single_quiz_title($title, $post_id) {
1097 1097
 
1098
-         if( 'quiz' == get_post_type( $post_id ) ){
1098
+         if ('quiz' == get_post_type($post_id)) {
1099 1099
 
1100 1100
              $title_with_no_quizzes = $title;
1101 1101
 
1102 1102
              // if the title has quiz, remove it: legacy titles have the word quiz stored.
1103
-             if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){
1103
+             if (1 < substr_count(strtoupper($title_with_no_quizzes), 'QUIZ')) {
1104 1104
 
1105 1105
                  // remove all possible appearances of quiz
1106
-                 $title_with_no_quizzes = str_replace( 'quiz', '', $title  );
1107
-                 $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes  );
1108
-                 $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes  );
1106
+                 $title_with_no_quizzes = str_replace('quiz', '', $title);
1107
+                 $title_with_no_quizzes = str_replace('Quiz', '', $title_with_no_quizzes);
1108
+                 $title_with_no_quizzes = str_replace('QUIZ', '', $title_with_no_quizzes);
1109 1109
 
1110 1110
              }
1111 1111
 
1112
-             $title = $title_with_no_quizzes .  ' ' . __( 'Quiz', 'woothemes-sensei' );
1112
+             $title = $title_with_no_quizzes.' '.__('Quiz', 'woothemes-sensei');
1113 1113
          }
1114 1114
 
1115 1115
          /**
1116 1116
           * hook document in class-woothemes-sensei-message.php
1117 1117
           */
1118
-         return apply_filters( 'sensei_single_title', $title, get_post_type( ) );
1118
+         return apply_filters('sensei_single_title', $title, get_post_type( ));
1119 1119
 
1120 1120
      }
1121 1121
 
@@ -1127,21 +1127,21 @@  discard block
 block discarded – undo
1127 1127
       * @since 1.9.0
1128 1128
       *
1129 1129
       */
1130
-     public static function start_quiz_questions_loop(){
1130
+     public static function start_quiz_questions_loop() {
1131 1131
 
1132 1132
          global $sensei_question_loop;
1133 1133
 
1134 1134
          //intialize the questions loop object
1135 1135
          $sensei_question_loop['current'] = -1;
1136
-         $sensei_question_loop['total']   =  0;
1136
+         $sensei_question_loop['total']   = 0;
1137 1137
          $sensei_question_loop['questions'] = array();
1138 1138
 
1139 1139
 
1140
-         $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() );
1140
+         $questions = Sensei()->lesson->lesson_quiz_questions(get_the_ID());
1141 1141
 
1142
-         if( count( $questions  ) > 0  ){
1142
+         if (count($questions) > 0) {
1143 1143
 
1144
-             $sensei_question_loop['total']   =  count( $questions );
1144
+             $sensei_question_loop['total']   = count($questions);
1145 1145
              $sensei_question_loop['questions'] = $questions;
1146 1146
              $sensei_question_loop['quiz_id'] = get_the_ID();
1147 1147
 
@@ -1157,9 +1157,9 @@  discard block
 block discarded – undo
1157 1157
       * @since 1.9.0
1158 1158
       *
1159 1159
       */
1160
-     public static function stop_quiz_questions_loop(){
1160
+     public static function stop_quiz_questions_loop() {
1161 1161
 
1162
-         $sensei_question_loop['total']   =  0;
1162
+         $sensei_question_loop['total']   = 0;
1163 1163
          $sensei_question_loop['questions'] = array();
1164 1164
          $sensei_question_loop['quiz_id'] = '';
1165 1165
 
@@ -1170,7 +1170,7 @@  discard block
 block discarded – undo
1170 1170
       *
1171 1171
       * @since 1.9.0
1172 1172
       */
1173
-     public static function the_title(){
1173
+     public static function the_title() {
1174 1174
          ?>
1175 1175
          <header>
1176 1176
 
@@ -1180,7 +1180,7 @@  discard block
 block discarded – undo
1180 1180
                  /**
1181 1181
                   * Filter documented in class-sensei-messages.php the_title
1182 1182
                   */
1183
-                 echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) );
1183
+                 echo apply_filters('sensei_single_title', get_the_title(get_post()), get_post_type(get_the_ID()));
1184 1184
                  ?>
1185 1185
 
1186 1186
              </h1>
@@ -1195,11 +1195,11 @@  discard block
 block discarded – undo
1195 1195
       *
1196 1196
       * @param $quiz_id
1197 1197
       */
1198
-    public static function  the_user_status_message( $quiz_id ){
1198
+    public static function  the_user_status_message($quiz_id) {
1199 1199
 
1200
-        $lesson_id =  Sensei()->quiz->get_lesson_id( $quiz_id );
1201
-        $status = WooThemes_Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() );
1202
-        echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
1200
+        $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id);
1201
+        $status = WooThemes_Sensei_Utils::sensei_user_quiz_status_message($lesson_id, get_current_user_id());
1202
+        echo '<div class="sensei-message '.$status['box_class'].'">'.$status['message'].'</div>';
1203 1203
 
1204 1204
     }
1205 1205
 
@@ -1210,9 +1210,9 @@  discard block
 block discarded – undo
1210 1210
       * @since 1.9.0
1211 1211
       * @deprecated
1212 1212
       */
1213
-     public static function deprecate_sensei_quiz_action_buttons_hook(){
1213
+     public static function deprecate_sensei_quiz_action_buttons_hook() {
1214 1214
 
1215
-         sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after');
1215
+         sensei_do_deprecated_action('sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after');
1216 1216
 
1217 1217
      }
1218 1218
 
@@ -1226,50 +1226,50 @@  discard block
 block discarded – undo
1226 1226
 
1227 1227
          global $post, $current_user;
1228 1228
 
1229
-         $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true );
1230
-         $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true );
1231
-         $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
1229
+         $lesson_id = (int) get_post_meta($post->ID, '_quiz_lesson', true);
1230
+         $lesson_course_id = (int) get_post_meta($lesson_id, '_lesson_course', true);
1231
+         $lesson_prerequisite = (int) get_post_meta($lesson_id, '_lesson_prerequisite', true);
1232 1232
          $show_actions = true;
1233
-         $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID );
1233
+         $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_id, $current_user->ID);
1234 1234
 
1235 1235
          //setup quiz grade
1236 1236
          $user_quiz_grade = '';
1237
-         if( ! empty( $user_lesson_status  ) ){
1238
-             $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1237
+         if ( ! empty($user_lesson_status)) {
1238
+             $user_quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true);
1239 1239
          }
1240 1240
 
1241 1241
 
1242
-         if( intval( $lesson_prerequisite ) > 0 ) {
1242
+         if (intval($lesson_prerequisite) > 0) {
1243 1243
 
1244 1244
              // If the user hasn't completed the prereq then hide the current actions
1245
-             $show_actions = WooThemes_Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID );
1245
+             $show_actions = WooThemes_Sensei_Utils::user_completed_lesson($lesson_prerequisite, $current_user->ID);
1246 1246
 
1247 1247
          }
1248
-         if ( $show_actions && is_user_logged_in() && WooThemes_Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) {
1248
+         if ($show_actions && is_user_logged_in() && WooThemes_Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID)) {
1249 1249
 
1250 1250
              // Get Reset Settings
1251
-             $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?>
1251
+             $reset_quiz_allowed = get_post_meta($post->ID, '_enable_quiz_reset', true); ?>
1252 1252
 
1253 1253
              <!-- Action Nonce's -->
1254 1254
              <input type="hidden" name="woothemes_sensei_complete_quiz_nonce" id="woothemes_sensei_complete_quiz_nonce"
1255
-                    value="<?php echo esc_attr(  wp_create_nonce( 'woothemes_sensei_complete_quiz_nonce' ) ); ?>" />
1255
+                    value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_complete_quiz_nonce')); ?>" />
1256 1256
              <input type="hidden" name="woothemes_sensei_reset_quiz_nonce" id="woothemes_sensei_reset_quiz_nonce"
1257
-                    value="<?php echo esc_attr(  wp_create_nonce( 'woothemes_sensei_reset_quiz_nonce' ) ); ?>" />
1257
+                    value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_reset_quiz_nonce')); ?>" />
1258 1258
              <input type="hidden" name="woothemes_sensei_save_quiz_nonce" id="woothemes_sensei_save_quiz_nonce"
1259
-                    value="<?php echo esc_attr(  wp_create_nonce( 'woothemes_sensei_save_quiz_nonce' ) ); ?>" />
1259
+                    value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_save_quiz_nonce')); ?>" />
1260 1260
              <!--#end Action Nonce's -->
1261 1261
 
1262
-             <?php if ( '' == $user_quiz_grade) { ?>
1262
+             <?php if ('' == $user_quiz_grade) { ?>
1263 1263
 
1264
-                 <span><input type="submit" name="quiz_complete" class="quiz-submit complete" value="<?php  _e( 'Complete Quiz', 'woothemes-sensei' ); ?>"/></span>
1264
+                 <span><input type="submit" name="quiz_complete" class="quiz-submit complete" value="<?php  _e('Complete Quiz', 'woothemes-sensei'); ?>"/></span>
1265 1265
 
1266
-                 <span><input type="submit" name="quiz_save" class="quiz-submit save" value="<?php _e( 'Save Quiz', 'woothemes-sensei' ); ?>"/></span>
1266
+                 <span><input type="submit" name="quiz_save" class="quiz-submit save" value="<?php _e('Save Quiz', 'woothemes-sensei'); ?>"/></span>
1267 1267
 
1268 1268
              <?php } // End If Statement ?>
1269 1269
 
1270
-             <?php if ( isset( $reset_quiz_allowed ) && $reset_quiz_allowed ) { ?>
1270
+             <?php if (isset($reset_quiz_allowed) && $reset_quiz_allowed) { ?>
1271 1271
 
1272
-                 <span><input type="submit" name="quiz_reset" class="quiz-submit reset" value="<?php _e( 'Reset Quiz', 'woothemes-sensei' ); ?>"/></span>
1272
+                 <span><input type="submit" name="quiz_reset" class="quiz-submit reset" value="<?php _e('Reset Quiz', 'woothemes-sensei'); ?>"/></span>
1273 1273
 
1274 1274
              <?php } ?>
1275 1275
 
@@ -1287,13 +1287,13 @@  discard block
 block discarded – undo
1287 1287
       *
1288 1288
       * @return double $user_quiz_grade
1289 1289
       */
1290
-     public static function get_user_quiz_grade( $lesson_id, $user_id ){
1290
+     public static function get_user_quiz_grade($lesson_id, $user_id) {
1291 1291
 
1292 1292
          // get the quiz grade
1293
-         $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
1293
+         $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
1294 1294
          $user_quiz_grade = 0;
1295
-         if( isset( $user_lesson_status->comment_ID ) ) {
1296
-             $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1295
+         if (isset($user_lesson_status->comment_ID)) {
1296
+             $user_quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true);
1297 1297
          }
1298 1298
 
1299 1299
          return (double) $user_quiz_grade;
@@ -1311,13 +1311,13 @@  discard block
 block discarded – undo
1311 1311
       * @param int $lesson_id
1312 1312
       * @return bool
1313 1313
       */
1314
-     public static function is_reset_allowed( $lesson_id ){
1314
+     public static function is_reset_allowed($lesson_id) {
1315 1315
 
1316
-         $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1316
+         $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
1317 1317
 
1318
-         $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true );
1318
+         $reset_allowed = get_post_meta($quiz_id, '_enable_quiz_reset', true);
1319 1319
          //backwards compatibility
1320
-         if( 'on' == $reset_allowed ) {
1320
+         if ('on' == $reset_allowed) {
1321 1321
              $reset_allowed = 1;
1322 1322
          }
1323 1323
 
@@ -1334,4 +1334,4 @@  discard block
 block discarded – undo
1334 1334
  * for backward compatibility
1335 1335
  * @since 1.9.0
1336 1336
  */
1337
-class WooThemes_Sensei_Quiz extends Sensei_Quiz{}
1337
+class WooThemes_Sensei_Quiz extends Sensei_Quiz {}
Please login to merge, or discard this patch.
Braces   +7 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Quiz Class
@@ -104,7 +107,7 @@  discard block
 block discarded – undo
104 107
 			global $post;
105 108
 			if( 'quiz' == get_post_type( $post ) ){
106 109
 				$quiz_id = $post->ID;
107
-			}else{
110
+			} else{
108 111
 				return false;
109 112
 			}
110 113
 
@@ -234,7 +237,7 @@  discard block
 block discarded – undo
234 237
 
235 238
             $encoded_user_answers = $transient_cached_answers;
236 239
 
237
-        }else{
240
+        } else{
238 241
 
239 242
             $encoded_user_answers = WooThemes_Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id  , $user_id );
240 243
 
@@ -424,7 +427,7 @@  discard block
 block discarded – undo
424 427
             // compress the answer for saving
425 428
 			if( 'multi-line' == $question_type ) {
426 429
                 $answer = esc_html( $answer );
427
-            }elseif( 'file-upload' == $question_type  ){
430
+            } elseif( 'file-upload' == $question_type  ){
428 431
                 $file_key = 'file_upload_' . $question_id;
429 432
                 if( isset( $files[ $file_key ] ) ) {
430 433
                         $attachment_id = WooThemes_Sensei_Utils::upload_file(  $files[ $file_key ] );
Please login to merge, or discard this patch.
includes/class-sensei-settings-api.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -793,7 +793,7 @@
 block discarded – undo
793 793
 	 * Return an array of field types expecting an array value returned.
794 794
 	 * @access protected
795 795
 	 * @since  1.0.0
796
-	 * @return void
796
+	 * @return string[]
797 797
 	 */
798 798
 	protected function get_array_field_types () {
799 799
 		return array( 'multicheck' );
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -416,9 +416,9 @@
 block discarded – undo
416 416
 		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";
417 417
 		if ( $has_description ) {
418 418
 			echo wp_kses( $args['data']['description'], array( 'a' => array(
419
-																	        'href' => array(),
420
-																	        'title' => array()
421
-																	    )
419
+																			'href' => array(),
420
+																			'title' => array()
421
+																		)
422 422
 															)
423 423
 						) . '</label>' . "\n";
424 424
 		}
Please login to merge, or discard this patch.
Spacing   +228 added lines, -228 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Settings API Class
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 * @since  1.0.0
35 35
 	 * @return void
36 36
 	 */
37
-	public function __construct () {
37
+	public function __construct() {
38 38
 		$this->token = 'woothemes-sensei';
39 39
 		$this->page_slug = 'woothemes-sensei-settings-api';
40 40
 
@@ -56,10 +56,10 @@  discard block
 block discarded – undo
56 56
 	 * @since  1.0.0
57 57
 	 * @return void
58 58
 	 */
59
-	public function setup_settings () {
60
-		add_action( 'admin_menu', array( $this, 'register_settings_screen' ), 60 );
61
-		add_action( 'admin_init', array( $this, 'settings_fields' ) );
62
-		add_action( 'init', array( $this, 'general_init' ) );
59
+	public function setup_settings() {
60
+		add_action('admin_menu', array($this, 'register_settings_screen'), 60);
61
+		add_action('admin_init', array($this, 'settings_fields'));
62
+		add_action('init', array($this, 'general_init'));
63 63
 	} // End setup_settings()
64 64
 
65 65
 	/**
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 		$this->init_sections();
73 73
 		$this->init_fields();
74 74
 		$this->get_settings();
75
-		if ( $this->has_tabs == true ) {
75
+		if ($this->has_tabs == true) {
76 76
 			$this->create_tabs();
77 77
 		} // End If Statement
78 78
 	} // End general_init()
@@ -83,9 +83,9 @@  discard block
 block discarded – undo
83 83
 	 * @since  1.0.0
84 84
 	 * @return void
85 85
 	 */
86
-	public function init_sections () {
86
+	public function init_sections() {
87 87
 		// Override this function in your class and assign the array of sections to $this->sections.
88
-		_e( 'Override init_sections() in your class.', 'woothemes-sensei' );
88
+		_e('Override init_sections() in your class.', 'woothemes-sensei');
89 89
 	} // End init_sections()
90 90
 
91 91
 	/**
@@ -94,9 +94,9 @@  discard block
 block discarded – undo
94 94
 	 * @since  1.0.0
95 95
 	 * @return void
96 96
 	 */
97
-	public function init_fields () {
97
+	public function init_fields() {
98 98
 		// Override this function in your class and assign the array of sections to $this->fields.
99
-		_e( 'Override init_fields() in your class.', 'woothemes-sensei' );
99
+		_e('Override init_fields() in your class.', 'woothemes-sensei');
100 100
 	} // End init_fields()
101 101
 
102 102
 	/**
@@ -105,33 +105,33 @@  discard block
 block discarded – undo
105 105
 	 * @since  1.1.0
106 106
 	 * @return void
107 107
 	 */
108
-	public function settings_tabs () {
109
-		if ( ! $this->has_tabs ) { return; }
108
+	public function settings_tabs() {
109
+		if ( ! $this->has_tabs) { return; }
110 110
 
111
-		if ( count( $this->tabs ) > 0 ) {
111
+		if (count($this->tabs) > 0) {
112 112
 			$html = '';
113 113
 
114
-			$html .= '<ul id="settings-sections" class="subsubsub hide-if-no-js">' . "\n";
114
+			$html .= '<ul id="settings-sections" class="subsubsub hide-if-no-js">'."\n";
115 115
 
116 116
 			$sections = array(
117
-						'all' => array( 'href' => '#all', 'name' => __( 'All', 'woothemes-sensei' ), 'class' => 'current all tab' )
117
+						'all' => array('href' => '#all', 'name' => __('All', 'woothemes-sensei'), 'class' => 'current all tab')
118 118
 					);
119 119
 
120
-			foreach ( $this->tabs as $k => $v ) {
121
-				$sections[$k] = array( 'href' => '#' . esc_attr( $k ), 'name' => esc_attr( $v['name'] ), 'class' => 'tab' );
120
+			foreach ($this->tabs as $k => $v) {
121
+				$sections[$k] = array('href' => '#'.esc_attr($k), 'name' => esc_attr($v['name']), 'class' => 'tab');
122 122
 			}
123 123
 
124 124
 			$count = 1;
125
-			foreach ( $sections as $k => $v ) {
125
+			foreach ($sections as $k => $v) {
126 126
 				$count++;
127
-				$html .= '<li><a href="' . $v['href'] . '"';
128
-				if ( isset( $v['class'] ) && ( $v['class'] != '' ) ) { $html .= ' class="' . esc_attr( $v['class'] ) . '"'; }
129
-				$html .= '>' . esc_attr( $v['name'] ) . '</a>';
130
-				if ( $count <= count( $sections ) ) { $html .= ' | '; }
131
-				$html .= '</li>' . "\n";
127
+				$html .= '<li><a href="'.$v['href'].'"';
128
+				if (isset($v['class']) && ($v['class'] != '')) { $html .= ' class="'.esc_attr($v['class']).'"'; }
129
+				$html .= '>'.esc_attr($v['name']).'</a>';
130
+				if ($count <= count($sections)) { $html .= ' | '; }
131
+				$html .= '</li>'."\n";
132 132
 			}
133 133
 
134
-			$html .= '</ul><div class="clear"></div>' . "\n";
134
+			$html .= '</ul><div class="clear"></div>'."\n";
135 135
 
136 136
 			echo $html;
137 137
 		}
@@ -143,10 +143,10 @@  discard block
 block discarded – undo
143 143
 	 * @since  1.1.0
144 144
 	 * @return void
145 145
 	 */
146
-	private function create_tabs () {
147
-		if ( count( $this->sections ) > 0 ) {
146
+	private function create_tabs() {
147
+		if (count($this->sections) > 0) {
148 148
 			$tabs = array();
149
-			foreach ( $this->sections as $k => $v ) {
149
+			foreach ($this->sections as $k => $v) {
150 150
 				$tabs[$k] = $v;
151 151
 			}
152 152
 
@@ -160,10 +160,10 @@  discard block
 block discarded – undo
160 160
 	 * @since  1.0.0
161 161
 	 * @return void
162 162
 	 */
163
-	public function create_sections () {
164
-		if ( count( $this->sections ) > 0 ) {
165
-			foreach ( $this->sections as $k => $v ) {
166
-				add_settings_section( $k, $v['name'], array( $this, 'section_description' ), $this->token );
163
+	public function create_sections() {
164
+		if (count($this->sections) > 0) {
165
+			foreach ($this->sections as $k => $v) {
166
+				add_settings_section($k, $v['name'], array($this, 'section_description'), $this->token);
167 167
 			}
168 168
 		}
169 169
 	} // End create_sections()
@@ -174,18 +174,18 @@  discard block
 block discarded – undo
174 174
 	 * @since  1.0.0
175 175
 	 * @return void
176 176
 	 */
177
-	public function create_fields () {
178
-		if ( count( $this->sections ) > 0 ) {
177
+	public function create_fields() {
178
+		if (count($this->sections) > 0) {
179 179
 			// $this->parse_fields( $this->fields );
180 180
 
181
-			foreach ( $this->fields as $k => $v ) {
182
-				$method = $this->determine_method( $v, 'form' );
181
+			foreach ($this->fields as $k => $v) {
182
+				$method = $this->determine_method($v, 'form');
183 183
 				$name = $v['name'];
184
-				if ( $v['type'] == 'info' ) { $name = ''; }
185
-				add_settings_field( $k, $name, $method, $this->token, $v['section'], array( 'key' => $k, 'data' => $v ) );
184
+				if ($v['type'] == 'info') { $name = ''; }
185
+				add_settings_field($k, $name, $method, $this->token, $v['section'], array('key' => $k, 'data' => $v));
186 186
 
187 187
 				// Let the API know that we have a colourpicker field.
188
-				if ( $v['type'] == 'range' && $this->has_range == false ) { $this->has_range = true; }
188
+				if ($v['type'] == 'range' && $this->has_range == false) { $this->has_range = true; }
189 189
 			}
190 190
 		}
191 191
 	} // End create_fields()
@@ -197,43 +197,43 @@  discard block
 block discarded – undo
197 197
 	 * @param  array $data
198 198
 	 * @return callable,  array or string
199 199
 	 */
200
-	protected function determine_method ( $data, $type = 'form' ) {
200
+	protected function determine_method($data, $type = 'form') {
201 201
 		$method = '';
202 202
 
203
-		if ( ! in_array( $type, array( 'form', 'validate', 'check' ) ) ) { return; }
203
+		if ( ! in_array($type, array('form', 'validate', 'check'))) { return; }
204 204
 
205 205
 		// Check for custom functions.
206
-		if ( isset( $data[$type] ) ) {
207
-			if ( function_exists( $data[$type] ) ) {
206
+		if (isset($data[$type])) {
207
+			if (function_exists($data[$type])) {
208 208
 				$method = $data[$type];
209 209
 			}
210 210
 
211
-			if ( $method == '' && method_exists( $this, $data[$type] ) ) {
212
-				if ( $type == 'form' ) {
213
-					$method = array( $this, $data[$type] );
211
+			if ($method == '' && method_exists($this, $data[$type])) {
212
+				if ($type == 'form') {
213
+					$method = array($this, $data[$type]);
214 214
 				} else {
215 215
 					$method = $data[$type];
216 216
 				}
217 217
 			}
218 218
 		}
219 219
 
220
-		if ( $method == '' && method_exists ( $this, $type . '_field_' . $data['type'] ) ) {
221
-			if ( $type == 'form' ) {
222
-				$method = array( $this, $type . '_field_' . $data['type'] );
220
+		if ($method == '' && method_exists($this, $type.'_field_'.$data['type'])) {
221
+			if ($type == 'form') {
222
+				$method = array($this, $type.'_field_'.$data['type']);
223 223
 			} else {
224
-				$method = $type . '_field_' . $data['type'];
224
+				$method = $type.'_field_'.$data['type'];
225 225
 			}
226 226
 		}
227 227
 
228
-		if ( $method == '' && function_exists ( $this->token . '_' . $type . '_field_' . $data['type'] ) ) {
229
-			$method = $this->token . '_' . $type . '_field_' . $data['type'];
228
+		if ($method == '' && function_exists($this->token.'_'.$type.'_field_'.$data['type'])) {
229
+			$method = $this->token.'_'.$type.'_field_'.$data['type'];
230 230
 		}
231 231
 
232
-		if ( $method == '' ) {
233
-			if ( $type == 'form' ) {
234
-				$method = array( $this, $type . '_field_text' );
232
+		if ($method == '') {
233
+			if ($type == 'form') {
234
+				$method = array($this, $type.'_field_text');
235 235
 			} else {
236
-				$method = $type . '_field_text';
236
+				$method = $type.'_field_text';
237 237
 			}
238 238
 		}
239 239
 
@@ -247,10 +247,10 @@  discard block
 block discarded – undo
247 247
 	 * @param  array $fields
248 248
 	 * @return void
249 249
 	 */
250
-	public function parse_fields ( $fields ) {
251
-		foreach ( $fields as $k => $v ) {
252
-			if ( isset( $v['section'] ) && ( $v['section'] != '' ) && ( isset( $this->sections[$v['section']] ) ) ) {
253
-				if ( ! isset( $this->sections[$v['section']]['fields'] ) ) {
250
+	public function parse_fields($fields) {
251
+		foreach ($fields as $k => $v) {
252
+			if (isset($v['section']) && ($v['section'] != '') && (isset($this->sections[$v['section']]))) {
253
+				if ( ! isset($this->sections[$v['section']]['fields'])) {
254 254
 					$this->sections[$v['section']]['fields'] = array();
255 255
 				}
256 256
 
@@ -267,19 +267,19 @@  discard block
 block discarded – undo
267 267
 	 * @since 1.0.0
268 268
 	 * @return void
269 269
 	 */
270
-	public function register_settings_screen () {
270
+	public function register_settings_screen() {
271 271
 
272 272
 
273
-		if ( current_user_can( 'manage_sensei' ) ) {
274
-			$hook = add_submenu_page( 'sensei', $this->name, $this->menu_label, 'manage_sensei', $this->page_slug, array( $this, 'settings_screen' ) );
273
+		if (current_user_can('manage_sensei')) {
274
+			$hook = add_submenu_page('sensei', $this->name, $this->menu_label, 'manage_sensei', $this->page_slug, array($this, 'settings_screen'));
275 275
 
276 276
 			$this->hook = $hook;
277 277
 		}
278 278
 
279
-		if ( isset( $_GET['page'] ) && ( $_GET['page'] == $this->page_slug ) ) {
280
-			add_action( 'admin_notices', array( $this, 'settings_errors' ) );
281
-			add_action( 'admin_print_scripts', array( $this, 'enqueue_scripts' ) );
282
-			add_action( 'admin_print_styles', array( $this, 'enqueue_styles' ) );
279
+		if (isset($_GET['page']) && ($_GET['page'] == $this->page_slug)) {
280
+			add_action('admin_notices', array($this, 'settings_errors'));
281
+			add_action('admin_print_scripts', array($this, 'enqueue_scripts'));
282
+			add_action('admin_print_styles', array($this, 'enqueue_styles'));
283 283
 		}
284 284
 	} // End register_settings_screen()
285 285
 
@@ -289,21 +289,21 @@  discard block
 block discarded – undo
289 289
 	 * @since  1.0.0
290 290
 	 * @return void
291 291
 	 */
292
-	public function settings_screen () {
292
+	public function settings_screen() {
293 293
 
294 294
 ?>
295
-<div id="woothemes-sensei" class="wrap <?php echo esc_attr( $this->token ); ?>">
296
-	<?php screen_icon( 'woothemes-sensei' ); ?>
297
-	<h2><?php echo esc_html( $this->name ); ?><?php if ( '' != $this->settings_version ) { echo ' <span class="version">' . $this->settings_version . '</span>'; } ?></h2>
298
-	<p class="powered-by-woo"><?php _e( 'Powered by', 'woothemes-sensei' ); ?><a href="http://www.woothemes.com/" title="WooThemes"><img src="<?php echo Sensei()->plugin_url; ?>assets/images/woothemes.png" alt="WooThemes" /></a></p>
299
-	<?php do_action( 'settings_before_form' ); ?>
295
+<div id="woothemes-sensei" class="wrap <?php echo esc_attr($this->token); ?>">
296
+	<?php screen_icon('woothemes-sensei'); ?>
297
+	<h2><?php echo esc_html($this->name); ?><?php if ('' != $this->settings_version) { echo ' <span class="version">'.$this->settings_version.'</span>'; } ?></h2>
298
+	<p class="powered-by-woo"><?php _e('Powered by', 'woothemes-sensei'); ?><a href="http://www.woothemes.com/" title="WooThemes"><img src="<?php echo Sensei()->plugin_url; ?>assets/images/woothemes.png" alt="WooThemes" /></a></p>
299
+	<?php do_action('settings_before_form'); ?>
300 300
 	<form action="options.php" method="post">
301 301
 		<?php $this->settings_tabs(); ?>
302
-		<?php settings_fields( $this->token ); ?>
303
-		<?php do_settings_sections( $this->token ); ?>
302
+		<?php settings_fields($this->token); ?>
303
+		<?php do_settings_sections($this->token); ?>
304 304
 		<?php submit_button(); ?>
305 305
 	</form>
306
-	<?php do_action( 'settings_after_form' ); ?>
306
+	<?php do_action('settings_after_form'); ?>
307 307
 </div><!--/#woothemes-sensei-->
308 308
 <?php
309 309
 	} // End settings_screen()
@@ -314,16 +314,16 @@  discard block
 block discarded – undo
314 314
 	 * @since  1.0.0
315 315
 	 * @return void
316 316
 	 */
317
-	public function get_settings () {
318
-		if ( ! is_array( $this->settings ) ) {
319
-			$this->settings = get_option( $this->token, array() );
317
+	public function get_settings() {
318
+		if ( ! is_array($this->settings)) {
319
+			$this->settings = get_option($this->token, array());
320 320
 		}
321 321
 
322
-		foreach ( $this->fields as $k => $v ) {
323
-			if ( ! isset( $this->settings[$k] ) && isset( $v['default'] ) ) {
322
+		foreach ($this->fields as $k => $v) {
323
+			if ( ! isset($this->settings[$k]) && isset($v['default'])) {
324 324
 				$this->settings[$k] = $v['default'];
325 325
 			}
326
-			if ( $v['type'] == 'checkbox' && $this->settings[$k] != true ) {
326
+			if ($v['type'] == 'checkbox' && $this->settings[$k] != true) {
327 327
 				$this->settings[$k] = 0;
328 328
 			}
329 329
 		}
@@ -337,8 +337,8 @@  discard block
 block discarded – undo
337 337
 	 * @since  1.0.0
338 338
 	 * @return void
339 339
 	 */
340
-	public function settings_fields () {
341
-		register_setting( $this->token, $this->token, array( $this, 'validate_fields' ) );
340
+	public function settings_fields() {
341
+		register_setting($this->token, $this->token, array($this, 'validate_fields'));
342 342
 		$this->create_sections();
343 343
 		$this->create_fields();
344 344
 	} // End settings_fields()
@@ -349,8 +349,8 @@  discard block
 block discarded – undo
349 349
 	 * @since  1.0.0
350 350
 	 * @return void
351 351
 	 */
352
-	public function settings_errors () {
353
-		echo settings_errors( $this->token . '-errors' );
352
+	public function settings_errors() {
353
+		echo settings_errors($this->token.'-errors');
354 354
 	} // End settings_errors()
355 355
 
356 356
 	/**
@@ -359,9 +359,9 @@  discard block
 block discarded – undo
359 359
 	 * @since  1.0.0
360 360
 	 * @return void
361 361
 	 */
362
-	public function section_description ( $section ) {
363
-		if ( isset( $this->sections[$section['id']]['description'] ) ) {
364
-			echo wpautop( $this->sections[$section['id']]['description'] );
362
+	public function section_description($section) {
363
+		if (isset($this->sections[$section['id']]['description'])) {
364
+			echo wpautop($this->sections[$section['id']]['description']);
365 365
 		}
366 366
 	} // End section_description_main()
367 367
 
@@ -372,12 +372,12 @@  discard block
 block discarded – undo
372 372
 	 * @param  array $args
373 373
 	 * @return void
374 374
 	 */
375
-	public function form_field_text ( $args ) {
375
+	public function form_field_text($args) {
376 376
 		$options = $this->get_settings();
377 377
 
378
-		echo '<input id="' . esc_attr( $args['key'] ) . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" size="40" type="text" value="' . esc_attr( $options[$args['key']] ) . '" />' . "\n";
379
-		if ( isset( $args['data']['description'] ) ) {
380
-			echo '<span class="description">' . $args['data']['description'] . '</span>' . "\n";
378
+		echo '<input id="'.esc_attr($args['key']).'" name="'.$this->token.'['.esc_attr($args['key']).']" size="40" type="text" value="'.esc_attr($options[$args['key']]).'" />'."\n";
379
+		if (isset($args['data']['description'])) {
380
+			echo '<span class="description">'.$args['data']['description'].'</span>'."\n";
381 381
 		}
382 382
 	} // End form_field_text()
383 383
 
@@ -388,13 +388,13 @@  discard block
 block discarded – undo
388 388
 	 * @param  array $args
389 389
 	 * @return void
390 390
 	 */
391
-	public function form_field_color ( $args ) {
391
+	public function form_field_color($args) {
392 392
 		$options = $this->get_settings();
393 393
 
394
-		echo '<input id="' . esc_attr( $args['key'] ) . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" size="40" type="text" class="color" value="' . esc_attr( $options[$args['key']] ) . '" />' . "\n";
394
+		echo '<input id="'.esc_attr($args['key']).'" name="'.$this->token.'['.esc_attr($args['key']).']" size="40" type="text" class="color" value="'.esc_attr($options[$args['key']]).'" />'."\n";
395 395
 		echo '<div style="position:absolute;background:#FFF;z-index:99;border-radius:100%;" class="colorpicker"></div>';
396
-		if ( isset( $args['data']['description'] ) ) {
397
-			echo '<span class="description">' . $args['data']['description'] . '</span>' . "\n";
396
+		if (isset($args['data']['description'])) {
397
+			echo '<span class="description">'.$args['data']['description'].'</span>'."\n";
398 398
 		}
399 399
 	} // End form_field_text()
400 400
 
@@ -405,22 +405,22 @@  discard block
 block discarded – undo
405 405
 	 * @param  array $args
406 406
 	 * @return void
407 407
 	 */
408
-	public function form_field_checkbox ( $args ) {
408
+	public function form_field_checkbox($args) {
409 409
 		$options = $this->get_settings();
410 410
 
411 411
 		$has_description = false;
412
-		if ( isset( $args['data']['description'] ) ) {
412
+		if (isset($args['data']['description'])) {
413 413
 			$has_description = true;
414
-			echo '<label for="' . esc_attr( $args['key'] ) . '">' . "\n";
414
+			echo '<label for="'.esc_attr($args['key']).'">'."\n";
415 415
 		}
416
-		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";
417
-		if ( $has_description ) {
418
-			echo wp_kses( $args['data']['description'], array( 'a' => array(
416
+		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";
417
+		if ($has_description) {
418
+			echo wp_kses($args['data']['description'], array('a' => array(
419 419
 																	        'href' => array(),
420 420
 																	        'title' => array()
421 421
 																	    )
422 422
 															)
423
-						) . '</label>' . "\n";
423
+						).'</label>'."\n";
424 424
 		}
425 425
 	} // End form_field_checkbox()
426 426
 
@@ -431,12 +431,12 @@  discard block
 block discarded – undo
431 431
 	 * @param  array $args
432 432
 	 * @return void
433 433
 	 */
434
-	public function form_field_textarea ( $args ) {
434
+	public function form_field_textarea($args) {
435 435
 		$options = $this->get_settings();
436 436
 
437
-		echo '<textarea id="' . esc_attr( $args['key'] ) . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" cols="42" rows="5">' . esc_html( $options[$args['key']] ) . '</textarea>' . "\n";
438
-		if ( isset( $args['data']['description'] ) ) {
439
-			echo '<p><span class="description">' . esc_html( $args['data']['description'] ) . '</span></p>' . "\n";
437
+		echo '<textarea id="'.esc_attr($args['key']).'" name="'.$this->token.'['.esc_attr($args['key']).']" cols="42" rows="5">'.esc_html($options[$args['key']]).'</textarea>'."\n";
438
+		if (isset($args['data']['description'])) {
439
+			echo '<p><span class="description">'.esc_html($args['data']['description']).'</span></p>'."\n";
440 440
 		}
441 441
 	} // End form_field_textarea()
442 442
 
@@ -447,20 +447,20 @@  discard block
 block discarded – undo
447 447
 	 * @param  array $args
448 448
 	 * @return void
449 449
 	 */
450
-	public function form_field_select ( $args ) {
450
+	public function form_field_select($args) {
451 451
 		$options = $this->get_settings();
452 452
 
453
-		if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) {
453
+		if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) {
454 454
 			$html = '';
455
-			$html .= '<select class="" id="' . esc_attr( $args['key'] ) . '" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . ']">' . "\n";
456
-				foreach ( $args['data']['options'] as $k => $v ) {
457
-					$html .= '<option value="' . esc_attr( $k ) . '"' . selected( esc_attr( $options[$args['key']] ), $k, false ) . '>' . $v . '</option>' . "\n";
455
+			$html .= '<select class="" id="'.esc_attr($args['key']).'" name="'.esc_attr($this->token).'['.esc_attr($args['key']).']">'."\n";
456
+				foreach ($args['data']['options'] as $k => $v) {
457
+					$html .= '<option value="'.esc_attr($k).'"'.selected(esc_attr($options[$args['key']]), $k, false).'>'.$v.'</option>'."\n";
458 458
 				}
459
-			$html .= '</select>' . "\n";
459
+			$html .= '</select>'."\n";
460 460
 			echo $html;
461 461
 
462
-			if ( isset( $args['data']['description'] ) ) {
463
-				echo '<p><span class="description">' . esc_html( $args['data']['description'] ) . '</span></p>' . "\n";
462
+			if (isset($args['data']['description'])) {
463
+				echo '<p><span class="description">'.esc_html($args['data']['description']).'</span></p>'."\n";
464 464
 			}
465 465
 		}
466 466
 	} // End form_field_select()
@@ -472,18 +472,18 @@  discard block
 block discarded – undo
472 472
 	 * @param  array $args
473 473
 	 * @return void
474 474
 	 */
475
-	public function form_field_radio ( $args ) {
475
+	public function form_field_radio($args) {
476 476
 		$options = $this->get_settings();
477 477
 
478
-		if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) {
478
+		if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) {
479 479
 			$html = '';
480
-			foreach ( $args['data']['options'] as $k => $v ) {
481
-				$html .= '<input type="radio" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" value="' . esc_attr( $k ) . '"' . checked( esc_attr( $options[$args['key']] ), $k, false ) . ' /> ' . $v . '<br />' . "\n";
480
+			foreach ($args['data']['options'] as $k => $v) {
481
+				$html .= '<input type="radio" name="'.$this->token.'['.esc_attr($args['key']).']" value="'.esc_attr($k).'"'.checked(esc_attr($options[$args['key']]), $k, false).' /> '.$v.'<br />'."\n";
482 482
 			}
483 483
 			echo $html;
484 484
 
485
-			if ( isset( $args['data']['description'] ) ) {
486
-				echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n";
485
+			if (isset($args['data']['description'])) {
486
+				echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n";
487 487
 			}
488 488
 		}
489 489
 	} // End form_field_radio()
@@ -495,28 +495,28 @@  discard block
 block discarded – undo
495 495
 	 * @param  array $args
496 496
 	 * @return void
497 497
 	 */
498
-	public function form_field_multicheck ( $args ) {
498
+	public function form_field_multicheck($args) {
499 499
 		$options = $this->get_settings();
500 500
 
501
-		if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) {
502
-			$html = '<div class="multicheck-container" style="margin-bottom:10px;">' . "\n";
503
-			foreach ( $args['data']['options'] as $k => $v ) {
501
+		if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) {
502
+			$html = '<div class="multicheck-container" style="margin-bottom:10px;">'."\n";
503
+			foreach ($args['data']['options'] as $k => $v) {
504 504
 				$checked = '';
505 505
 
506
-				if( isset( $options[ $args['key'] ] ) ) {
507
-					if ( in_array( $k, (array)$options[ $args['key'] ] ) ) { $checked = ' checked="checked"'; }
506
+				if (isset($options[$args['key']])) {
507
+					if (in_array($k, (array) $options[$args['key']])) { $checked = ' checked="checked"'; }
508 508
 				} else {
509
-					if ( in_array( $k, $args['data']['defaults'] ) ) { $checked = ' checked="checked"'; }
509
+					if (in_array($k, $args['data']['defaults'])) { $checked = ' checked="checked"'; }
510 510
 				}
511
-				$html .= '<label for="checkbox-' . esc_attr( $k ) . '">' . "\n";
512
-				$html .= '<input type="checkbox" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . '][]" class="multicheck multicheck-' . esc_attr( $args['key'] ) . '" value="' . esc_attr( $k ) . '" id="checkbox-' . esc_attr( $k ) . '" ' . $checked . ' /> ' . $v . "\n";
513
-				$html .= '</label><br />' . "\n";
511
+				$html .= '<label for="checkbox-'.esc_attr($k).'">'."\n";
512
+				$html .= '<input type="checkbox" name="'.esc_attr($this->token).'['.esc_attr($args['key']).'][]" class="multicheck multicheck-'.esc_attr($args['key']).'" value="'.esc_attr($k).'" id="checkbox-'.esc_attr($k).'" '.$checked.' /> '.$v."\n";
513
+				$html .= '</label><br />'."\n";
514 514
 			}
515
-			$html .= '</div>' . "\n";
515
+			$html .= '</div>'."\n";
516 516
 			echo $html;
517 517
 
518
-			if ( isset( $args['data']['description'] ) ) {
519
-				echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n";
518
+			if (isset($args['data']['description'])) {
519
+				echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n";
520 520
 			}
521 521
 		}
522 522
 	} // End form_field_multicheck()
@@ -528,20 +528,20 @@  discard block
 block discarded – undo
528 528
 	 * @param  array $args
529 529
 	 * @return void
530 530
 	 */
531
-	public function form_field_range ( $args ) {
531
+	public function form_field_range($args) {
532 532
 		$options = $this->get_settings();
533 533
 
534
-		if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) {
534
+		if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) {
535 535
 			$html = '';
536
-			$html .= '<select id="' . esc_attr( $args['key'] ) . '" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . ']" class="range-input">' . "\n";
537
-				foreach ( $args['data']['options'] as $k => $v ) {
538
-					$html .= '<option value="' . esc_attr( $k ) . '"' . selected( esc_attr( $options[$args['key']] ), $k, false ) . '>' . $v . '</option>' . "\n";
536
+			$html .= '<select id="'.esc_attr($args['key']).'" name="'.esc_attr($this->token).'['.esc_attr($args['key']).']" class="range-input">'."\n";
537
+				foreach ($args['data']['options'] as $k => $v) {
538
+					$html .= '<option value="'.esc_attr($k).'"'.selected(esc_attr($options[$args['key']]), $k, false).'>'.$v.'</option>'."\n";
539 539
 				}
540
-			$html .= '</select>' . "\n";
540
+			$html .= '</select>'."\n";
541 541
 			echo $html;
542 542
 
543
-			if ( isset( $args['data']['description'] ) ) {
544
-				echo '<p><span class="description">' . esc_html( $args['data']['description'] ) . '</span></p>' . "\n";
543
+			if (isset($args['data']['description'])) {
544
+				echo '<p><span class="description">'.esc_html($args['data']['description']).'</span></p>'."\n";
545 545
 			}
546 546
 		}
547 547
 	} // End form_field_range()
@@ -553,18 +553,18 @@  discard block
 block discarded – undo
553 553
 	 * @param  array $args
554 554
 	 * @return void
555 555
 	 */
556
-	public function form_field_images ( $args ) {
556
+	public function form_field_images($args) {
557 557
 		$options = $this->get_settings();
558 558
 
559
-		if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) {
559
+		if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) {
560 560
 			$html = '';
561
-			foreach ( $args['data']['options'] as $k => $v ) {
562
-				$html .= '<input type="radio" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . ']" value="' . esc_attr( $k ) . '"' . checked( esc_attr( $options[$args['key']] ), $k, false ) . ' /> ' . $v . '<br />' . "\n";
561
+			foreach ($args['data']['options'] as $k => $v) {
562
+				$html .= '<input type="radio" name="'.esc_attr($this->token).'['.esc_attr($args['key']).']" value="'.esc_attr($k).'"'.checked(esc_attr($options[$args['key']]), $k, false).' /> '.$v.'<br />'."\n";
563 563
 			}
564 564
 			echo $html;
565 565
 
566
-			if ( isset( $args['data']['description'] ) ) {
567
-				echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n";
566
+			if (isset($args['data']['description'])) {
567
+				echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n";
568 568
 			}
569 569
 		}
570 570
 	} // End form_field_images()
@@ -576,19 +576,19 @@  discard block
 block discarded – undo
576 576
 	 * @param  array $args
577 577
 	 * @return void
578 578
 	 */
579
-	public function form_field_info ( $args ) {
579
+	public function form_field_info($args) {
580 580
 		$class = '';
581
-		if ( isset( $args['data']['class'] ) ) {
582
-			$class = ' ' . esc_attr( $args['data']['class'] );
581
+		if (isset($args['data']['class'])) {
582
+			$class = ' '.esc_attr($args['data']['class']);
583 583
 		}
584
-		$html = '<div id="' . $args['key'] . '" class="info-box' . $class . '">' . "\n";
585
-		if ( isset( $args['data']['name'] ) && ( $args['data']['name'] != '' ) ) {
586
-			$html .= '<h3 class="title">' . esc_html( $args['data']['name'] ) . '</h3>' . "\n";
584
+		$html = '<div id="'.$args['key'].'" class="info-box'.$class.'">'."\n";
585
+		if (isset($args['data']['name']) && ($args['data']['name'] != '')) {
586
+			$html .= '<h3 class="title">'.esc_html($args['data']['name']).'</h3>'."\n";
587 587
 		}
588
-		if ( isset( $args['data']['description'] ) && ( $args['data']['description'] != '' ) ) {
589
-			$html .= '<p>' . esc_html( $args['data']['description'] ) . '</p>' . "\n";
588
+		if (isset($args['data']['description']) && ($args['data']['description'] != '')) {
589
+			$html .= '<p>'.esc_html($args['data']['description']).'</p>'."\n";
590 590
 		}
591
-		$html .= '</div>' . "\n";
591
+		$html .= '</div>'."\n";
592 592
 
593 593
 		echo $html;
594 594
 	} // End form_field_info()
@@ -600,14 +600,14 @@  discard block
 block discarded – undo
600 600
 	 * @since  1.9.0
601 601
 	 * @param  array $args
602 602
 	 */
603
-	public function form_field_button( $args ) {
603
+	public function form_field_button($args) {
604 604
 		$options = $this->get_settings();
605 605
 
606
-		if ( isset( $args['data']['target'] ) && isset( $args['data']['label'] ) ) {
607
-			printf( '<a href="%s" class="button button-secondary">%s</a> ', esc_url( $args['data']['target'] ), esc_html( $args['data']['label'] ) );
606
+		if (isset($args['data']['target']) && isset($args['data']['label'])) {
607
+			printf('<a href="%s" class="button button-secondary">%s</a> ', esc_url($args['data']['target']), esc_html($args['data']['label']));
608 608
 
609
-			if ( isset( $args['data']['description'] ) ) {
610
-				echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n";
609
+			if (isset($args['data']['description'])) {
610
+				echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n";
611 611
 			}
612 612
 		}
613 613
 	} // End form_field_button()
@@ -621,23 +621,23 @@  discard block
 block discarded – undo
621 621
 	 * @uses   $this->parse_errors()
622 622
 	 * @return array $options
623 623
 	 */
624
-	public function validate_fields ( $input ) {
624
+	public function validate_fields($input) {
625 625
 		$options = $this->get_settings();
626 626
 
627
-		foreach ( $this->fields as $k => $v ) {
627
+		foreach ($this->fields as $k => $v) {
628 628
 			// Make sure checkboxes are present even when false.
629
-			if ( $v['type'] == 'checkbox' && ! isset( $input[$k] ) ) { $input[$k] = false; }
630
-			if ( $v['type'] == 'multicheck' && ! isset( $input[$k] ) ) { $input[$k] = false; }
629
+			if ($v['type'] == 'checkbox' && ! isset($input[$k])) { $input[$k] = false; }
630
+			if ($v['type'] == 'multicheck' && ! isset($input[$k])) { $input[$k] = false; }
631 631
 
632
-			if ( isset( $input[$k] ) ) {
632
+			if (isset($input[$k])) {
633 633
 				// Perform checks on required fields.
634
-				if ( isset( $v['required'] ) && ( $v['required'] == true ) ) {
635
-					if ( in_array( $v['type'], $this->get_array_field_types() ) && ( count( (array) $input[$k] ) <= 0 ) ) {
636
-						$this->add_error( $k, $v );
634
+				if (isset($v['required']) && ($v['required'] == true)) {
635
+					if (in_array($v['type'], $this->get_array_field_types()) && (count((array) $input[$k]) <= 0)) {
636
+						$this->add_error($k, $v);
637 637
 						continue;
638 638
 					} else {
639
-						if ( $input[$k] == '' ) {
640
-							$this->add_error( $k, $v );
639
+						if ($input[$k] == '') {
640
+							$this->add_error($k, $v);
641 641
 							continue;
642 642
 						}
643 643
 					}
@@ -646,28 +646,28 @@  discard block
 block discarded – undo
646 646
 				$value = $input[$k];
647 647
 
648 648
 				// Check if the field is valid.
649
-				$method = $this->determine_method( $v, 'check' );
649
+				$method = $this->determine_method($v, 'check');
650 650
 
651
-				if ( function_exists ( $method ) ) {
652
-					$is_valid = $method( $value );
651
+				if (function_exists($method)) {
652
+					$is_valid = $method($value);
653 653
 				} else {
654
-					if ( method_exists( $this, $method ) ) {
655
-						$is_valid = $this->$method( $value );
654
+					if (method_exists($this, $method)) {
655
+						$is_valid = $this->$method($value);
656 656
 					}
657 657
 				}
658 658
 
659
-				if ( ! $is_valid ) {
660
-					$this->add_error( $k, $v );
659
+				if ( ! $is_valid) {
660
+					$this->add_error($k, $v);
661 661
 					continue;
662 662
 				}
663 663
 
664
-				$method = $this->determine_method( $v, 'validate' );
664
+				$method = $this->determine_method($v, 'validate');
665 665
 
666
-				if ( function_exists ( $method ) ) {
667
-					$options[$k] = $method( $value );
666
+				if (function_exists($method)) {
667
+					$options[$k] = $method($value);
668 668
 				} else {
669
-					if ( method_exists( $this, $method ) ) {
670
-						$options[$k] = $this->$method( $value );
669
+					if (method_exists($this, $method)) {
670
+						$options[$k] = $this->$method($value);
671 671
 					}
672 672
 				}
673 673
 			}
@@ -685,8 +685,8 @@  discard block
 block discarded – undo
685 685
 	 * @param  string $input
686 686
 	 * @return string
687 687
 	 */
688
-	public function validate_field_text ( $input ) {
689
-		return trim( esc_attr( $input ) );
688
+	public function validate_field_text($input) {
689
+		return trim(esc_attr($input));
690 690
 	} // End validate_field_text()
691 691
 
692 692
 	/**
@@ -696,11 +696,11 @@  discard block
 block discarded – undo
696 696
 	 * @param  string $input
697 697
 	 * @return string
698 698
 	 */
699
-	public function validate_field_checkbox ( $input ) {
700
-		if ( ! isset( $input ) ) {
699
+	public function validate_field_checkbox($input) {
700
+		if ( ! isset($input)) {
701 701
 			return 0;
702 702
 		} else {
703
-			return (bool)$input;
703
+			return (bool) $input;
704 704
 		}
705 705
 	} // End validate_field_checkbox()
706 706
 
@@ -711,10 +711,10 @@  discard block
 block discarded – undo
711 711
 	 * @param  string $input
712 712
 	 * @return string
713 713
 	 */
714
-	public function validate_field_multicheck ( $input ) {
714
+	public function validate_field_multicheck($input) {
715 715
 		$input = (array) $input;
716 716
 
717
-		$input = array_map( 'esc_attr', $input );
717
+		$input = array_map('esc_attr', $input);
718 718
 
719 719
 		return $input;
720 720
 	} // End validate_field_multicheck()
@@ -726,8 +726,8 @@  discard block
 block discarded – undo
726 726
 	 * @param  string $input
727 727
 	 * @return string
728 728
 	 */
729
-	public function validate_field_range ( $input ) {
730
-		$input = number_format( floatval( $input ), 0 );
729
+	public function validate_field_range($input) {
730
+		$input = number_format(floatval($input), 0);
731 731
 
732 732
 		return $input;
733 733
 	} // End validate_field_range()
@@ -739,8 +739,8 @@  discard block
 block discarded – undo
739 739
 	 * @param  string $input
740 740
 	 * @return string
741 741
 	 */
742
-	public function validate_field_url ( $input ) {
743
-		return trim( esc_url( $input ) );
742
+	public function validate_field_url($input) {
743
+		return trim(esc_url($input));
744 744
 	} // End validate_field_url()
745 745
 
746 746
 	/**
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
 	 * @since  1.1.0
750 750
 	 * @return boolean Is the value valid?
751 751
 	 */
752
-	public function check_field_text ( $input ) {
752
+	public function check_field_text($input) {
753 753
 		$is_valid = true;
754 754
 
755 755
 		return $is_valid;
@@ -763,11 +763,11 @@  discard block
 block discarded – undo
763 763
 	 * @param  array $data
764 764
 	 * @return void
765 765
 	 */
766
-	protected function add_error ( $key, $data ) {
767
-		if ( isset( $data['error_message'] ) ) {
766
+	protected function add_error($key, $data) {
767
+		if (isset($data['error_message'])) {
768 768
 			$message = $data['error_message'];
769 769
 		} else {
770
-			$message = sprintf( __( '%s is a required field', 'woothemes-sensei' ), $data['name'] );
770
+			$message = sprintf(__('%s is a required field', 'woothemes-sensei'), $data['name']);
771 771
 		}
772 772
 		$this->errors[$key] = $message;
773 773
 	} // End add_error()
@@ -778,14 +778,14 @@  discard block
 block discarded – undo
778 778
 	 * @since   1.0.0
779 779
 	 * @return  void
780 780
 	 */
781
-	protected function parse_errors () {
782
-		if ( count ( $this->errors ) > 0 ) {
783
-			foreach ( $this->errors as $k => $v ) {
784
-				add_settings_error( $this->token . '-errors', $k, $v, 'error' );
781
+	protected function parse_errors() {
782
+		if (count($this->errors) > 0) {
783
+			foreach ($this->errors as $k => $v) {
784
+				add_settings_error($this->token.'-errors', $k, $v, 'error');
785 785
 			}
786 786
 		} else {
787
-			$message = sprintf( __( '%s updated', 'woothemes-sensei' ), $this->name );
788
-			add_settings_error( $this->token . '-errors', $this->token, $message, 'updated' );
787
+			$message = sprintf(__('%s updated', 'woothemes-sensei'), $this->name);
788
+			add_settings_error($this->token.'-errors', $this->token, $message, 'updated');
789 789
 		}
790 790
 	} // End parse_errors()
791 791
 
@@ -795,8 +795,8 @@  discard block
 block discarded – undo
795 795
 	 * @since  1.0.0
796 796
 	 * @return void
797 797
 	 */
798
-	protected function get_array_field_types () {
799
-		return array( 'multicheck' );
798
+	protected function get_array_field_types() {
799
+		return array('multicheck');
800 800
 	} // End get_array_field_types()
801 801
 
802 802
 	/**
@@ -805,22 +805,22 @@  discard block
 block discarded – undo
805 805
 	 * @since  1.0.0
806 806
 	 * @return void
807 807
 	 */
808
-	public function enqueue_scripts () {
808
+	public function enqueue_scripts() {
809 809
 
810 810
 
811
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
811
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
812 812
 
813
-		wp_enqueue_script( 'farbtastic' );
814
-		wp_enqueue_script( 'woothemes-sensei-settings', esc_url( Sensei()->plugin_url . 'assets/js/settings' . $suffix . '.js' ), array( 'jquery', 'farbtastic' ), Sensei()->version );
813
+		wp_enqueue_script('farbtastic');
814
+		wp_enqueue_script('woothemes-sensei-settings', esc_url(Sensei()->plugin_url.'assets/js/settings'.$suffix.'.js'), array('jquery', 'farbtastic'), Sensei()->version);
815 815
 
816
-		if ( $this->has_range ) {
817
-			wp_enqueue_script( 'woothemes-sensei-settings-ranges', esc_url( Sensei()->plugin_url . 'assets/js/ranges' . $suffix . '.js' ), array( 'jquery-ui-slider' ), Sensei()->version );
816
+		if ($this->has_range) {
817
+			wp_enqueue_script('woothemes-sensei-settings-ranges', esc_url(Sensei()->plugin_url.'assets/js/ranges'.$suffix.'.js'), array('jquery-ui-slider'), Sensei()->version);
818 818
 		}
819 819
 
820
-		wp_register_script( 'woothemes-sensei-settings-imageselectors', esc_url( Sensei()->plugin_url . 'assets/js/image-selectors' . $suffix . '.js' ), array( 'jquery' ), Sensei()->version );
820
+		wp_register_script('woothemes-sensei-settings-imageselectors', esc_url(Sensei()->plugin_url.'assets/js/image-selectors'.$suffix.'.js'), array('jquery'), Sensei()->version);
821 821
 
822
-		if ( $this->has_imageselector ) {
823
-			wp_enqueue_script( 'woothemes-sensei-settings-imageselectors' );
822
+		if ($this->has_imageselector) {
823
+			wp_enqueue_script('woothemes-sensei-settings-imageselectors');
824 824
 		}
825 825
 
826 826
 	} // End enqueue_scripts()
@@ -831,12 +831,12 @@  discard block
 block discarded – undo
831 831
 	 * @since  1.0.0
832 832
 	 * @return void
833 833
 	 */
834
-	public function enqueue_styles () {
834
+	public function enqueue_styles() {
835 835
 
836
-		wp_enqueue_style( Sensei()->token . '-admin' );
836
+		wp_enqueue_style(Sensei()->token.'-admin');
837 837
 
838
-		wp_enqueue_style( 'farbtastic' );
839
-		wp_enqueue_style( 'woothemes-sensei-settings-api', esc_url( Sensei()->plugin_url . 'assets/css/settings.css' ), array( 'farbtastic' ), Sensei()->version );
838
+		wp_enqueue_style('farbtastic');
839
+		wp_enqueue_style('woothemes-sensei-settings-api', esc_url(Sensei()->plugin_url.'assets/css/settings.css'), array('farbtastic'), Sensei()->version);
840 840
 
841 841
 		$this->enqueue_field_styles();
842 842
 	} // End enqueue_styles()
@@ -847,17 +847,17 @@  discard block
 block discarded – undo
847 847
 	 * @since  1.0.0
848 848
 	 * @return void
849 849
 	 */
850
-	public function enqueue_field_styles () {
850
+	public function enqueue_field_styles() {
851 851
 
852 852
 
853
-		if ( $this->has_range ) {
854
-			wp_enqueue_style( 'woothemes-sensei-settings-ranges', esc_url( Sensei()->plugin_url . 'assets/css/ranges.css' ), '', Sensei()->version );
853
+		if ($this->has_range) {
854
+			wp_enqueue_style('woothemes-sensei-settings-ranges', esc_url(Sensei()->plugin_url.'assets/css/ranges.css'), '', Sensei()->version);
855 855
 		}
856 856
 
857
-		wp_register_style( 'woothemes-sensei-settings-imageselectors', esc_url( Sensei()->plugin_url . 'assets/css/image-selectors.css' ), '', Sensei()->version );
857
+		wp_register_style('woothemes-sensei-settings-imageselectors', esc_url(Sensei()->plugin_url.'assets/css/image-selectors.css'), '', Sensei()->version);
858 858
 
859
-		if ( $this->has_imageselector ) {
860
-			wp_enqueue_style( 'woothemes-sensei-settings-imageselectors' );
859
+		if ($this->has_imageselector) {
860
+			wp_enqueue_style('woothemes-sensei-settings-imageselectors');
861 861
 		}
862 862
 	} // End enqueue_field_styles()
863 863
 } // End Class
@@ -867,4 +867,4 @@  discard block
 block discarded – undo
867 867
  * for backward compatibility
868 868
  * @since 1.9.0
869 869
  */
870
-class WooThemes_Sensei_Settings_API extends Sensei_Settings_API{}
870
+class WooThemes_Sensei_Settings_API extends Sensei_Settings_API {}
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Analysis User Profile List Table Class
Please login to merge, or discard this patch.
includes/class-sensei-teacher.php 4 patches
Doc Comments   +3 added lines, -4 removed lines patch added patch discarded remove patch
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
      *
364 364
      * @param $course_id
365 365
      * @param $new_teacher_id
366
-     * @return void
366
+     * @return false|null
367 367
      */
368 368
     public static function update_course_modules_author( $course_id ,$new_teacher_id ){
369 369
 
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
      * @since 1.8.0
455 455
      * @access public
456 456
      * @parameters
457
-     * @return array $users user id array
457
+     * @return boolean $users user id array
458 458
      */
459 459
     public function update_course_lessons_author ( $course_id, $new_author  ){
460 460
 
@@ -843,8 +843,7 @@  discard block
 block discarded – undo
843 843
      * This function hooks into wp_insert_post
844 844
      *
845 845
      * @since 1.8.0
846
-     * @param int $course_id
847
-     * @return bool
846
+     * @return false|null
848 847
      */
849 848
     public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){
850 849
 
Please login to merge, or discard this patch.
Indentation   +1339 added lines, -1339 removed lines patch added patch discarded remove patch
@@ -14,251 +14,251 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class Sensei_Teacher {
16 16
 
17
-    /**
18
-     * $teacher_role
19
-     *
20
-     * Keeps a reference to the teacher role object
21
-     *
22
-     * @access protected
23
-     * @since 1.8.0
24
-     */
25
-    protected $teacher_role;
26
-
27
-    /**
28
-     * $token
29
-     *
30
-     * Keeps a reference to the global sensei token
31
-     *
32
-     * @access protected
33
-     * @since 1.8.0
34
-     */
35
-    public  $token;
36
-
37
-    /**
38
-     * Sensei_Teacher::__constructor
39
-     *
40
-     * Constructor Function
41
-     *
42
-     * @since 1.8.0
43
-     * @access public
44
-     */
45
-    public function __construct ( ) {
46
-
47
-        add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 );
48
-        add_action( 'save_post',  array( $this, 'save_teacher_meta_box' ) );
49
-        add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' ));
50
-        add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) );
51
-        add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 );
52
-
53
-        add_action( 'pre_get_posts', array( $this, 'filter_queries' ) );
54
-
55
-        //filter the quiz submissions
56
-        add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') );
57
-
58
-        //grading totals count only those belonging to the teacher
59
-        add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) );
60
-
61
-        // show the courses owned by a user on his author archive page
62
-        add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) );
63
-
64
-        // notify admin when a teacher creates a course
65
-        add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 );
66
-
67
-        // limit the analysis view to only the users taking courses belong to this teacher
68
-        add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 );
69
-
70
-        // give teacher access to question post type
71
-        add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 );
72
-
73
-        // Teacher column on the courses list on the admin edit screen
74
-        add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 );
75
-        add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 );
76
-
77
-        //admin edit messages query limit teacher
78
-        add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) );
79
-
80
-        //add filter by teacher on courses list
81
-        add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) );
82
-        add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) );
83
-
84
-        // Handle media library restrictions
85
-        add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 );
86
-        add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 );
87
-
88
-        // update lesson owner to course teacher when saved
89
-        add_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
90
-
91
-        // If a Teacher logs in, redirect to /wp-admin/
92
-        add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 );
93
-
94
-
95
-        add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10);
96
-        add_filter('pre_get_comments',  array ($this, 'restrict_comment_moderation'), 10, 1);
97
-
98
-
99
-    } // end __constructor()
100
-
101
-    /**
102
-     * Sensei_Teacher::create_teacher_role
103
-     *
104
-     * This function checks if the role exist, if not it creates it.
105
-     * for the teacher role
106
-     *
107
-     * @since 1.8.0
108
-     * @access public
109
-     * @return void
110
-     */
111
-    public function create_role ( ) {
112
-
113
-        // check if the role exists
114
-        $this->teacher_role = get_role( 'teacher' );
115
-
116
-        // if the the teacher is not a valid WordPress role create it
117
-       if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) {
118
-           // create the role
119
-           $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) );
120
-       }
121
-
122
-       // add the capabilities before returning
123
-        $this->add_capabilities();
124
-
125
-    }// end create_teacher_role
126
-
127
-    /**
128
-     * Sensei_Teacher::add_capabilities
129
-     *
130
-     * @since 1.8.0
131
-     * @access protected
132
-     */
133
-    protected function add_capabilities ( ) {
134
-
135
-        // if this is not a valid WP_Role object exit without adding anything
136
-        if(  ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) {
137
-            return;
138
-        }
139
-
140
-        /**
141
-         * Sensei teachers capabilities array filter
142
-         *
143
-         * These capabilities will be applied to the teacher role
144
-         * @param array $capabilities
145
-         * keys: (string) $cap_name => (bool) $grant
146
-         */
147
-        $caps = apply_filters( 'sensei_teacher_role_capabilities', array(
148
-            // General access rules
149
-            'read' => true,
150
-            'manage_sensei_grades' => true,
151
-            'moderate_comments'=> true,
152
-            'upload_files'	=> true,
153
-            'edit_files'	=> true,
154
-
155
-            //Lessons
156
-            'publish_lessons'	 => true,
157
-            'manage_lesson_categories'	 => true,
158
-            'edit_lessons'	 => true,
159
-            'edit_published_lessons'  => true,
160
-            'edit_private_lessons' => true,
161
-            'read_private_lessons' => true,
162
-            'delete_published_lessons' => true,
163
-
164
-            // Courses
165
-            'create_courses' => true,
166
-            'publish_courses'	 => false,
167
-            'manage_course_categories'	 => true,
168
-            'edit_courses'	 => true,
169
-            'edit_published_courses'  => true,
170
-            'edit_private_courses' => true,
171
-            'read_private_courses' => true,
172
-            'delete_published_courses' => true,
173
-
174
-            // Quiz
175
-            'publish_quizzes'	 => true,
176
-            'edit_quizzes'	 => true,
177
-            'edit_published_quizzes'  => true,
178
-            'edit_private_quizzes' => true,
179
-            'read_private_quizzes' => true,
180
-
181
-            // Questions
182
-            'publish_questions'	 => true,
183
-            'edit_questions'	 => true,
184
-            'edit_published_questions'  => true,
185
-            'edit_private_questions' => true,
186
-            'read_private_questions' => true,
187
-
188
-            //messages
189
-            'publish_sensei_messages'	 => true,
190
-            'edit_sensei_messages'	 => true,
191
-            'edit_published_sensei_messages'  => true,
192
-            'edit_private_sensei_messages' => true,
193
-            'read_private_sensei_messages' => true,
194
-
195
-            // Comments -
196
-            // Necessary cap so Teachers can moderate comments
197
-            // on their own lessons. We restrict access to other
198
-            // post types in $this->restrict_posts_menu_page()
199
-
200
-            'edit_posts' => true,
201
-
202
-        ));
203
-
204
-        foreach ( $caps as $cap => $grant ) {
205
-
206
-            // load the capability on to the teacher role
207
-            $this->teacher_role->add_cap($cap, $grant);
208
-
209
-        } // end for each
210
-
211
-    }// end add_cap
212
-
213
-    /**
214
-     * Sensei_Teacher::teacher_meta_box
215
-     *
216
-     * Add the teacher metabox to the course post type edit screen
217
-     *
218
-     * @since 1.8.0
219
-     * @access public
220
-     * @parameter string $post_type
221
-     * @parameter WP_Post $post
222
-     * @return void
223
-     */
224
-    public function add_teacher_meta_boxes ( $post ) {
225
-
226
-        if( !current_user_can('manage_options') ){
227
-            return;
228
-        }
229
-        add_meta_box( 'sensei-teacher',  __( 'Teacher' , $this->token ),  array( $this , 'teacher_meta_box_content' ),
230
-            'course',
231
-            'side',
232
-            'core'
233
-        );
234
-
235
-    } // end teacher_meta_box()
236
-
237
-    /**
238
-     * Sensei_Teacher::teacher_meta_box_content
239
-     *
240
-     * Render the teacher meta box markup
241
-     *
242
-     * @since 1.8.0
243
-     * @access public
244
-     * @parameters
245
-     */
246
-    public function teacher_meta_box_content ( $post ) {
247
-
248
-        // get the current author
249
-        $current_author = $post->post_author;
250
-
251
-        //get the users authorised to author courses
252
-        $users = $this->get_teachers_and_authors();
253
-
254
-    ?>
17
+	/**
18
+	 * $teacher_role
19
+	 *
20
+	 * Keeps a reference to the teacher role object
21
+	 *
22
+	 * @access protected
23
+	 * @since 1.8.0
24
+	 */
25
+	protected $teacher_role;
26
+
27
+	/**
28
+	 * $token
29
+	 *
30
+	 * Keeps a reference to the global sensei token
31
+	 *
32
+	 * @access protected
33
+	 * @since 1.8.0
34
+	 */
35
+	public  $token;
36
+
37
+	/**
38
+	 * Sensei_Teacher::__constructor
39
+	 *
40
+	 * Constructor Function
41
+	 *
42
+	 * @since 1.8.0
43
+	 * @access public
44
+	 */
45
+	public function __construct ( ) {
46
+
47
+		add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 );
48
+		add_action( 'save_post',  array( $this, 'save_teacher_meta_box' ) );
49
+		add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' ));
50
+		add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) );
51
+		add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 );
52
+
53
+		add_action( 'pre_get_posts', array( $this, 'filter_queries' ) );
54
+
55
+		//filter the quiz submissions
56
+		add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') );
57
+
58
+		//grading totals count only those belonging to the teacher
59
+		add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) );
60
+
61
+		// show the courses owned by a user on his author archive page
62
+		add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) );
63
+
64
+		// notify admin when a teacher creates a course
65
+		add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 );
66
+
67
+		// limit the analysis view to only the users taking courses belong to this teacher
68
+		add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 );
69
+
70
+		// give teacher access to question post type
71
+		add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 );
72
+
73
+		// Teacher column on the courses list on the admin edit screen
74
+		add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 );
75
+		add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 );
76
+
77
+		//admin edit messages query limit teacher
78
+		add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) );
79
+
80
+		//add filter by teacher on courses list
81
+		add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) );
82
+		add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) );
83
+
84
+		// Handle media library restrictions
85
+		add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 );
86
+		add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 );
87
+
88
+		// update lesson owner to course teacher when saved
89
+		add_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
90
+
91
+		// If a Teacher logs in, redirect to /wp-admin/
92
+		add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 );
93
+
94
+
95
+		add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10);
96
+		add_filter('pre_get_comments',  array ($this, 'restrict_comment_moderation'), 10, 1);
97
+
98
+
99
+	} // end __constructor()
100
+
101
+	/**
102
+	 * Sensei_Teacher::create_teacher_role
103
+	 *
104
+	 * This function checks if the role exist, if not it creates it.
105
+	 * for the teacher role
106
+	 *
107
+	 * @since 1.8.0
108
+	 * @access public
109
+	 * @return void
110
+	 */
111
+	public function create_role ( ) {
112
+
113
+		// check if the role exists
114
+		$this->teacher_role = get_role( 'teacher' );
115
+
116
+		// if the the teacher is not a valid WordPress role create it
117
+	   if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) {
118
+		   // create the role
119
+		   $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) );
120
+	   }
121
+
122
+	   // add the capabilities before returning
123
+		$this->add_capabilities();
124
+
125
+	}// end create_teacher_role
126
+
127
+	/**
128
+	 * Sensei_Teacher::add_capabilities
129
+	 *
130
+	 * @since 1.8.0
131
+	 * @access protected
132
+	 */
133
+	protected function add_capabilities ( ) {
134
+
135
+		// if this is not a valid WP_Role object exit without adding anything
136
+		if(  ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) {
137
+			return;
138
+		}
139
+
140
+		/**
141
+		 * Sensei teachers capabilities array filter
142
+		 *
143
+		 * These capabilities will be applied to the teacher role
144
+		 * @param array $capabilities
145
+		 * keys: (string) $cap_name => (bool) $grant
146
+		 */
147
+		$caps = apply_filters( 'sensei_teacher_role_capabilities', array(
148
+			// General access rules
149
+			'read' => true,
150
+			'manage_sensei_grades' => true,
151
+			'moderate_comments'=> true,
152
+			'upload_files'	=> true,
153
+			'edit_files'	=> true,
154
+
155
+			//Lessons
156
+			'publish_lessons'	 => true,
157
+			'manage_lesson_categories'	 => true,
158
+			'edit_lessons'	 => true,
159
+			'edit_published_lessons'  => true,
160
+			'edit_private_lessons' => true,
161
+			'read_private_lessons' => true,
162
+			'delete_published_lessons' => true,
163
+
164
+			// Courses
165
+			'create_courses' => true,
166
+			'publish_courses'	 => false,
167
+			'manage_course_categories'	 => true,
168
+			'edit_courses'	 => true,
169
+			'edit_published_courses'  => true,
170
+			'edit_private_courses' => true,
171
+			'read_private_courses' => true,
172
+			'delete_published_courses' => true,
173
+
174
+			// Quiz
175
+			'publish_quizzes'	 => true,
176
+			'edit_quizzes'	 => true,
177
+			'edit_published_quizzes'  => true,
178
+			'edit_private_quizzes' => true,
179
+			'read_private_quizzes' => true,
180
+
181
+			// Questions
182
+			'publish_questions'	 => true,
183
+			'edit_questions'	 => true,
184
+			'edit_published_questions'  => true,
185
+			'edit_private_questions' => true,
186
+			'read_private_questions' => true,
187
+
188
+			//messages
189
+			'publish_sensei_messages'	 => true,
190
+			'edit_sensei_messages'	 => true,
191
+			'edit_published_sensei_messages'  => true,
192
+			'edit_private_sensei_messages' => true,
193
+			'read_private_sensei_messages' => true,
194
+
195
+			// Comments -
196
+			// Necessary cap so Teachers can moderate comments
197
+			// on their own lessons. We restrict access to other
198
+			// post types in $this->restrict_posts_menu_page()
199
+
200
+			'edit_posts' => true,
201
+
202
+		));
203
+
204
+		foreach ( $caps as $cap => $grant ) {
205
+
206
+			// load the capability on to the teacher role
207
+			$this->teacher_role->add_cap($cap, $grant);
208
+
209
+		} // end for each
210
+
211
+	}// end add_cap
212
+
213
+	/**
214
+	 * Sensei_Teacher::teacher_meta_box
215
+	 *
216
+	 * Add the teacher metabox to the course post type edit screen
217
+	 *
218
+	 * @since 1.8.0
219
+	 * @access public
220
+	 * @parameter string $post_type
221
+	 * @parameter WP_Post $post
222
+	 * @return void
223
+	 */
224
+	public function add_teacher_meta_boxes ( $post ) {
225
+
226
+		if( !current_user_can('manage_options') ){
227
+			return;
228
+		}
229
+		add_meta_box( 'sensei-teacher',  __( 'Teacher' , $this->token ),  array( $this , 'teacher_meta_box_content' ),
230
+			'course',
231
+			'side',
232
+			'core'
233
+		);
234
+
235
+	} // end teacher_meta_box()
236
+
237
+	/**
238
+	 * Sensei_Teacher::teacher_meta_box_content
239
+	 *
240
+	 * Render the teacher meta box markup
241
+	 *
242
+	 * @since 1.8.0
243
+	 * @access public
244
+	 * @parameters
245
+	 */
246
+	public function teacher_meta_box_content ( $post ) {
247
+
248
+		// get the current author
249
+		$current_author = $post->post_author;
250
+
251
+		//get the users authorised to author courses
252
+		$users = $this->get_teachers_and_authors();
253
+
254
+	?>
255 255
         <select name="sensei-course-teacher-author" class="sensei course teacher">
256 256
 
257 257
             <?php foreach ( $users as $user_id ) { ?>
258 258
 
259 259
                     <?php
260
-                        $user = get_user_by('id', $user_id);
261
-                    ?>
260
+						$user = get_user_by('id', $user_id);
261
+					?>
262 262
                     <option <?php selected(  $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" >
263 263
                         <?php echo  $user->display_name; ?>
264 264
                     </option>
@@ -269,1289 +269,1289 @@  discard block
 block discarded – undo
269 269
 
270 270
         <?php
271 271
 
272
-    } // end render_teacher_meta_box()
273
-
274
-    /**
275
-     * Sensei_Teacher::get_teachers_and_authors
276
-     *
277
-     * Get a list of users who can author courses, lessons and quizes.
278
-     *
279
-     * @since 1.8.0
280
-     * @access public
281
-     * @parameters
282
-     * @return array $users user id array
283
-     */
284
-    public function get_teachers_and_authors ( ){
285
-
286
-        $author_query_args = array(
287
-            'blog_id'      => $GLOBALS['blog_id'],
288
-            'fields'       => 'any',
289
-            'who'          => 'authors'
290
-        );
291
-
292
-        $authors = get_users( $author_query_args );
293
-
294
-        $teacher_query_args = array(
295
-            'blog_id'      => $GLOBALS['blog_id'],
296
-            'fields'       => 'any',
297
-            'role'         => 'teacher',
298
-        );
299
-
300
-        $teachers = get_users( $teacher_query_args );
301
-
302
-        return  array_unique( array_merge( $teachers, $authors ) );
303
-
304
-    }// end get_teachers_and_authors
305
-
306
-    /**
307
-     * Sensei_Teacher::save_teacher_meta_box
308
-     *
309
-     * Save the new teacher / author to course and all lessons
310
-     *
311
-     * Hooked into admin_init
312
-     *
313
-     * @since 1.8.0
314
-     * @access public
315
-     * @parameters
316
-     * @return array $users user id array
317
-     */
318
-    public function save_teacher_meta_box ( $course_id ){
272
+	} // end render_teacher_meta_box()
273
+
274
+	/**
275
+	 * Sensei_Teacher::get_teachers_and_authors
276
+	 *
277
+	 * Get a list of users who can author courses, lessons and quizes.
278
+	 *
279
+	 * @since 1.8.0
280
+	 * @access public
281
+	 * @parameters
282
+	 * @return array $users user id array
283
+	 */
284
+	public function get_teachers_and_authors ( ){
285
+
286
+		$author_query_args = array(
287
+			'blog_id'      => $GLOBALS['blog_id'],
288
+			'fields'       => 'any',
289
+			'who'          => 'authors'
290
+		);
291
+
292
+		$authors = get_users( $author_query_args );
293
+
294
+		$teacher_query_args = array(
295
+			'blog_id'      => $GLOBALS['blog_id'],
296
+			'fields'       => 'any',
297
+			'role'         => 'teacher',
298
+		);
299
+
300
+		$teachers = get_users( $teacher_query_args );
301
+
302
+		return  array_unique( array_merge( $teachers, $authors ) );
303
+
304
+	}// end get_teachers_and_authors
305
+
306
+	/**
307
+	 * Sensei_Teacher::save_teacher_meta_box
308
+	 *
309
+	 * Save the new teacher / author to course and all lessons
310
+	 *
311
+	 * Hooked into admin_init
312
+	 *
313
+	 * @since 1.8.0
314
+	 * @access public
315
+	 * @parameters
316
+	 * @return array $users user id array
317
+	 */
318
+	public function save_teacher_meta_box ( $course_id ){
319 319
 
320
-        // check if this is a post from saving the teacher, if not exit early
321
-        if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] )  ){
322
-            return;
323
-        }
320
+		// check if this is a post from saving the teacher, if not exit early
321
+		if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] )  ){
322
+			return;
323
+		}
324 324
 
325
-        //don't fire this hook again
326
-        remove_action('save_post', array( $this, 'save_teacher_meta_box' ) );
325
+		//don't fire this hook again
326
+		remove_action('save_post', array( $this, 'save_teacher_meta_box' ) );
327 327
 
328
-        // get the current post object
329
-        $post = get_post( $course_id );
328
+		// get the current post object
329
+		$post = get_post( $course_id );
330 330
 
331
-        // get the current teacher/author
332
-        $current_author = absint( $post->post_author );
333
-        $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] );
331
+		// get the current teacher/author
332
+		$current_author = absint( $post->post_author );
333
+		$new_author = absint( $_POST[ 'sensei-course-teacher-author' ] );
334 334
 
335
-        // loop through all post lessons to update their authors as well
336
-        $this->update_course_lessons_author( $course_id , $new_author );
335
+		// loop through all post lessons to update their authors as well
336
+		$this->update_course_lessons_author( $course_id , $new_author );
337 337
 
338
-        // do not do any processing if the selected author is the same as the current author
339
-        if( $current_author == $new_author ){
340
-            return;
341
-        }
338
+		// do not do any processing if the selected author is the same as the current author
339
+		if( $current_author == $new_author ){
340
+			return;
341
+		}
342 342
 
343
-        // save the course  author
344
-        $post_updates = array(
345
-            'ID' => $post->ID ,
346
-            'post_author' => $new_author
347
-        );
348
-        wp_update_post( $post_updates );
343
+		// save the course  author
344
+		$post_updates = array(
345
+			'ID' => $post->ID ,
346
+			'post_author' => $new_author
347
+		);
348
+		wp_update_post( $post_updates );
349 349
 
350
-        // ensure the the modules are update so that then new teacher has access to them
351
-        Sensei_Teacher::update_course_modules_author( $course_id, $new_author );
350
+		// ensure the the modules are update so that then new teacher has access to them
351
+		Sensei_Teacher::update_course_modules_author( $course_id, $new_author );
352 352
 
353
-        // notify the new teacher
354
-        $this->teacher_course_assigned_notification( $new_author, $course_id );
353
+		// notify the new teacher
354
+		$this->teacher_course_assigned_notification( $new_author, $course_id );
355 355
 
356
-    } // end save_teacher_meta_box
356
+	} // end save_teacher_meta_box
357 357
 
358
-    /**
359
-     * Update all the course terms set(selected) on the given course. Moving course term ownership to
360
-     * the new author. Making sure the course terms are maintained.
361
-     *
362
-     * This function also checks if terms are shared, with other courses
363
-     *
364
-     * @param $course_id
365
-     * @param $new_teacher_id
366
-     * @return void
367
-     */
368
-    public static function update_course_modules_author( $course_id ,$new_teacher_id ){
358
+	/**
359
+	 * Update all the course terms set(selected) on the given course. Moving course term ownership to
360
+	 * the new author. Making sure the course terms are maintained.
361
+	 *
362
+	 * This function also checks if terms are shared, with other courses
363
+	 *
364
+	 * @param $course_id
365
+	 * @param $new_teacher_id
366
+	 * @return void
367
+	 */
368
+	public static function update_course_modules_author( $course_id ,$new_teacher_id ){
369 369
 
370
-        if( empty( $course_id ) || empty( $new_teacher_id ) ){
371
-            return false;
372
-        }
370
+		if( empty( $course_id ) || empty( $new_teacher_id ) ){
371
+			return false;
372
+		}
373 373
 
374
-        $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' );
374
+		$terms_selected_on_course = wp_get_object_terms( $course_id, 'module' );
375 375
 
376
-        if( empty( $terms_selected_on_course ) ){
377
-            return;
378
-        }
376
+		if( empty( $terms_selected_on_course ) ){
377
+			return;
378
+		}
379 379
 
380
-        foreach( $terms_selected_on_course as $term ){
380
+		foreach( $terms_selected_on_course as $term ){
381 381
 
382
-            $term_author = Sensei_Core_Modules::get_term_author( $term->slug );
383
-            if( $new_teacher_id != $term_author->ID  ){
382
+			$term_author = Sensei_Core_Modules::get_term_author( $term->slug );
383
+			if( $new_teacher_id != $term_author->ID  ){
384 384
 
385
-                $new_term = '';
385
+				$new_term = '';
386 386
 
387
-                //if the new teacher is admin first check to see if the term with this name already exists
388
-                if( user_can( $new_teacher_id, 'manage_options' ) ){
387
+				//if the new teacher is admin first check to see if the term with this name already exists
388
+				if( user_can( $new_teacher_id, 'manage_options' ) ){
389 389
 
390
-                    $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) );
391
-                    $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, );
392
-                    $existing_admin_terms = get_terms( 'module', $term_args );
393
-                    if( !empty( $existing_admin_terms ) ){
394
-                        // insert it even if it exists
395
-                        $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A );
396
-                    }
397
-                }
390
+					$slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) );
391
+					$term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, );
392
+					$existing_admin_terms = get_terms( 'module', $term_args );
393
+					if( !empty( $existing_admin_terms ) ){
394
+						// insert it even if it exists
395
+						$new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A );
396
+					}
397
+				}
398 398
 
399
-                if( empty ( $new_term ) ){
399
+				if( empty ( $new_term ) ){
400 400
 
401
-                   //setup the new slug
402
-                   $new_author_term_slug =  $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) );
403
-
404
-                   // create new term and set it
405
-                   $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug )  );
406
-
407
-                }
401
+				   //setup the new slug
402
+				   $new_author_term_slug =  $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) );
403
+
404
+				   // create new term and set it
405
+				   $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug )  );
406
+
407
+				}
408 408
 
409 409
 
410 410
 
411
-                // if term exists
412
-                if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){
411
+				// if term exists
412
+				if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){
413 413
 
414
-                    $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module');
415
-                    $term_id = $existing_term->term_id;
414
+					$existing_term = get_term_by( 'slug', $new_author_term_slug, 'module');
415
+					$term_id = $existing_term->term_id;
416 416
 
417
-                }else{
417
+				}else{
418 418
 
419
-                    // for a new term simply get the term from the returned value
420
-                    $term_id = $new_term['term_id'];
419
+					// for a new term simply get the term from the returned value
420
+					$term_id = $new_term['term_id'];
421 421
 
422
-                } // end if term exist
422
+				} // end if term exist
423 423
 
424
-                // set the terms selected on the course
425
-                wp_set_object_terms( $course_id, $term_id , 'module', true );
424
+				// set the terms selected on the course
425
+				wp_set_object_terms( $course_id, $term_id , 'module', true );
426 426
 
427
-                // remove old term
428
-                wp_remove_object_terms( $course_id, $term->term_id, 'module' );
427
+				// remove old term
428
+				wp_remove_object_terms( $course_id, $term->term_id, 'module' );
429 429
 
430
-                // update the lessons within the current module term
431
-                $lessons = Sensei()->course->course_lessons( $course_id );
432
-                foreach( $lessons as $lesson  ){
430
+				// update the lessons within the current module term
431
+				$lessons = Sensei()->course->course_lessons( $course_id );
432
+				foreach( $lessons as $lesson  ){
433 433
 
434
-                    if( has_term( $term->slug, 'module', $lesson ) ){
434
+					if( has_term( $term->slug, 'module', $lesson ) ){
435 435
 
436
-                        // add the new term, the false at the end says to replace all terms on this module
437
-                        // with the new term.
438
-                        wp_set_object_terms( $lesson->ID, $term_id , 'module', false );
439
-                        update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 );
440
-                    }
436
+						// add the new term, the false at the end says to replace all terms on this module
437
+						// with the new term.
438
+						wp_set_object_terms( $lesson->ID, $term_id , 'module', false );
439
+						update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 );
440
+					}
441 441
 
442
-                }// end for each
442
+				}// end for each
443 443
 
444
-            }
445
-        }
444
+			}
445
+		}
446 446
 
447
-    }// end update_course_module_terms_author
447
+	}// end update_course_module_terms_author
448 448
 
449
-    /**
450
-     * Sensei_Teacher::update_course_lessons_author
451
-     *
452
-     * Update all course lessons and their quiz with a new author
453
-     *
454
-     * @since 1.8.0
455
-     * @access public
456
-     * @parameters
457
-     * @return array $users user id array
458
-     */
459
-    public function update_course_lessons_author ( $course_id, $new_author  ){
449
+	/**
450
+	 * Sensei_Teacher::update_course_lessons_author
451
+	 *
452
+	 * Update all course lessons and their quiz with a new author
453
+	 *
454
+	 * @since 1.8.0
455
+	 * @access public
456
+	 * @parameters
457
+	 * @return array $users user id array
458
+	 */
459
+	public function update_course_lessons_author ( $course_id, $new_author  ){
460 460
 
461 461
 
462
-        if( empty( $course_id ) || empty( $new_author ) ){
463
-            return false;
464
-        }
462
+		if( empty( $course_id ) || empty( $new_author ) ){
463
+			return false;
464
+		}
465 465
 
466
-        //get a list of course lessons
467
-        $lessons = Sensei()->course->course_lessons( $course_id );
466
+		//get a list of course lessons
467
+		$lessons = Sensei()->course->course_lessons( $course_id );
468 468
 
469
-        if( empty( $lessons )  ||  ! is_array( $lessons )  ){
470
-            return false;
471
-        }
469
+		if( empty( $lessons )  ||  ! is_array( $lessons )  ){
470
+			return false;
471
+		}
472 472
 
473
-        // update each lesson and quiz author
474
-        foreach( $lessons as $lesson ){
473
+		// update each lesson and quiz author
474
+		foreach( $lessons as $lesson ){
475 475
 
476
-            // don't update if the author is tha same as the new author
477
-            if( $new_author == $lesson->post_author ){
478
-                continue;
479
-            }
476
+			// don't update if the author is tha same as the new author
477
+			if( $new_author == $lesson->post_author ){
478
+				continue;
479
+			}
480 480
 
481
-            // update lesson author
482
-            wp_update_post( array(
483
-                'ID'=> $lesson->ID,
484
-                'post_author' => $new_author
485
-                ) );
481
+			// update lesson author
482
+			wp_update_post( array(
483
+				'ID'=> $lesson->ID,
484
+				'post_author' => $new_author
485
+				) );
486 486
 
487
-            // update quiz author
488
-            //get the lessons quiz
489
-            $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID );
490
-            if( is_array( $lesson_quizzes ) ){
491
-                foreach ( $lesson_quizzes as $quiz_id ) {
492
-                    // update quiz with new author
493
-                    wp_update_post( array(
494
-                        'ID'           => $quiz_id,
495
-                        'post_author' =>  $new_author
496
-                    ) );
497
-                }
498
-            }else{
499
-                wp_update_post( array(
500
-                    'ID'           => $lesson_quizzes,
501
-                    'post_author' =>  $new_author
502
-                ) );
503
-            }
487
+			// update quiz author
488
+			//get the lessons quiz
489
+			$lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID );
490
+			if( is_array( $lesson_quizzes ) ){
491
+				foreach ( $lesson_quizzes as $quiz_id ) {
492
+					// update quiz with new author
493
+					wp_update_post( array(
494
+						'ID'           => $quiz_id,
495
+						'post_author' =>  $new_author
496
+					) );
497
+				}
498
+			}else{
499
+				wp_update_post( array(
500
+					'ID'           => $lesson_quizzes,
501
+					'post_author' =>  $new_author
502
+				) );
503
+			}
504 504
 
505
-        } // end for each lessons
505
+		} // end for each lessons
506 506
 
507
-        return true;
507
+		return true;
508 508
 
509
-    }// end update_course_lessons_author
510
-
511
-
512
-
513
-    /**
514
-     * Sensei_Teacher::course_analysis_teacher_access_limit
515
-     *
516
-     * Alter the query so that users can only see their courses on the analysis page
517
-     *
518
-     * @since 1.8.0
519
-     * @access public
520
-     * @parameters $query
521
-     * @return array $users user id array
522
-     */
523
-    public function course_analysis_teacher_access_limit ( $query ) {
524
-
525
-        if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
526
-            return $query;
527
-        }
528
-
529
-        if ( ! function_exists( 'get_current_screen' ) ) {
530
-            return $query;
531
-        }
532
-
533
-        $screen = get_current_screen();
534
-        $sensei_post_types = array('course', 'lesson', 'question' );
535
-
536
-        // exit early for the following conditions
537
-        $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' );
538
-
539
-        if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids )
540
-            || ! in_array( $query->query['post_type'], $sensei_post_types ) ){
541
-            return $query;
542
-        }
543
-
544
-        global $current_user;
545
-        // set the query author to the current user to only show those those posts
546
-        $query->set( 'author', $current_user->ID );
547
-        return $query;
548
-
549
-    }// end course_analysis_teacher_access_limit
550
-
551
-
552
-    /**
553
-     * Sensei_Teacher::limit_teacher_edit_screen_post_types
554
-     *
555
-     * Determine if we're in admin and the current logged in use is a teacher
556
-     *
557
-     * @since 1.8.0
558
-     * @access public
559
-     * @parameters array $wp_query
560
-     * @return bool $is_admin_teacher
561
-     */
562
-    public function is_admin_teacher ( ){
563
-
564
-        if( ! is_user_logged_in()){
565
-            return false;
566
-        }
567
-        $is_admin_teacher = false;
568
-
569
-        if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() )  ){
570
-
571
-            $is_admin_teacher = true;
572
-
573
-        }
574
-
575
-        return $is_admin_teacher;
576
-
577
-    } // end is_admin_teacher
578
-
579
-    /**
580
-     * Show correct post counts on list table for Sensei post types
581
-     *
582
-     * @since 1.8.0
583
-     *
584
-     * @param  object $counts Default status counts
585
-     * @param  string $type   Current post type
586
-     * @param  string $perm   User permission level
587
-     * @return object         Modified status counts
588
-     */
589
-    public function list_table_counts( $counts, $type, $perm ) {
590
-        global $current_user;
591
-
592
-        if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) {
593
-            return $counts;
594
-        }
595
-
596
-        if( ! $this->is_admin_teacher() ) {
597
-            return $counts;
598
-        }
599
-
600
-        $args = array(
601
-            'post_type' => $type,
602
-            'author' => $current_user->ID,
603
-            'posts_per_page' => -1
604
-        );
605
-
606
-         // Get all available statuses
607
-        $stati = get_post_stati();
608
-
609
-        // Update count object
610
-        foreach( $stati as $status ) {
611
-            $args['post_status'] = $status;
612
-            $posts = get_posts( $args );
613
-            $counts->$status = count( $posts );
614
-        }
615
-
616
-        return $counts;
617
-    }
618
-
619
-    /**
620
-     * Filter the post queries to show
621
-     * only lesson /course and users that belong
622
-     * to the current logged teacher.
623
-     *
624
-     * @since 1.8.0
625
-     *
626
-     */
627
-    public function filter_queries ( $query ) {
628
-        global $current_user;
629
-
630
-        if( ! $this->is_admin_teacher() ) {
631
-            return;
632
-        }
633
-
634
-        if ( ! function_exists( 'get_current_screen' ) ) {
635
-            return;
636
-        }
637
-
638
-        $screen = get_current_screen();
639
-        if( empty( $screen ) ) {
640
-            return $query;
641
-        }
642
-        switch( $screen->id ) {
643
-            case 'sensei_page_sensei_grading':
644
-            case 'sensei_page_sensei_analysis':
645
-            case 'sensei_page_sensei_learners':
646
-            case 'lesson':
647
-            case 'course':
648
-            case 'question':
649
-            case 'lesson_page_module-order':
650
-
651
-            /**
652
-             * sensei_filter_queries_set_author
653
-             * Filter the author Sensei set for queries
654
-             *
655
-             * @since 1.8.0
656
-             *
657
-             * @param int $user_id
658
-             * @param string $screen_id
659
-             *
660
-             */
661
-            $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) );
662
-            break;
663
-        }
664
-    }
665
-
666
-    /**
667
-     * Limit grading quizzes to only those within courses belonging to the current teacher
668
-     * . This excludes the admin user.
669
-     *
670
-     * @since 1.8.0
671
-     * @hooked into the_comments
672
-     * @param array  $comments
673
-     *
674
-     * @return array $comments
675
-     */
676
-    public function filter_grading_activity_queries( $comments ){
677
-
678
-        if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){
679
-            return $comments ;
680
-        }
681
-
682
-        //check if we're on the grading screen
683
-        $screen = get_current_screen();
684
-
685
-        if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){
686
-            return $comments;
687
-        }
688
-
689
-        // get the course and determine if the current teacher is the owner
690
-        // if not remove it from the list of comments to be returned
691
-        foreach( $comments as $key => $comment){
692
-            $lesson = get_post( $comment->comment_post_ID );
693
-            $course_id = Sensei()->lesson->get_course_id( $lesson->ID );
694
-            $course = get_post( $course_id );
695
-            if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){
696
-                //remove this as the teacher should see this.
697
-                unset( $comments[ $key ] );
698
-            }
699
-        }
700
-        return $comments ;
701
-
702
-    }// end function filter grading
703
-
704
-    /**
705
-     * Limit the grading screen totals to only show lessons in the course
706
-     * belonging to the currently logged in teacher. This only applies to
707
-     * the teacher role.
708
-     *
709
-     * @since 1.8.0
710
-     *
711
-     * @hooked into sensei_count_statuses_args
712
-     * @param array $args
713
-     *
714
-     * @return array  $args
715
-     */
716
-    public function limit_grading_totals( $args ){
717
-
718
-        if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){
719
-            return $args ;
720
-        }
721
-
722
-        //get the teachers courses
723
-        // the query is already filtered to only the teacher
724
-        $courses =  Sensei()->course->get_all_courses();
725
-
726
-        if( empty(  $courses ) || ! is_array( $courses ) ){
727
-            return $args;
728
-        }
729
-
730
-        //setup the lessons quizzes  to limit the grading totals to
731
-        $quiz_scope = array();
732
-        foreach( $courses as $course ){
733
-
734
-            $course_lessons = Sensei()->course->course_lessons( $course->ID );
735
-
736
-            if( ! empty( $course_lessons ) && is_array( $course_lessons  ) ){
737
-
738
-                foreach(  $course_lessons as $lesson ){
739
-
740
-                    $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID );
741
-                    if( !empty( $quiz_id ) ) {
742
-
743
-                        array_push( $quiz_scope, $quiz_id );
744
-
745
-                    }
746
-
747
-                }
748
-
749
-            }
750
-
751
-        }
752
-
753
-        $args['post__in'] = $quiz_scope;
754
-
755
-        return $args;
756
-    }
757
-
758
-    /**
759
-     * It ensures that the author archive shows course by the current user.
760
-     *
761
-     * This function is hooked into the pre_get_posts filter
762
-     *
763
-     * @param WP_Query $query
764
-     * @return WP_Query $query
765
-     */
766
-    public function add_courses_to_author_archive( $query ) {
767
-
768
-        if ( is_admin() || ! $query->is_author() ){
769
-            return $query;
770
-        }
771
-
772
-        // this should only apply to users with the teacher role
773
-        $current_page_user = get_user_by('login', $query->get('author_name') );
774
-        if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) )     {
775
-
776
-            return $query;
777
-
778
-        }
779
-
780
-        // Change post types depending on what is set already
781
-        $current_post_types = $query->get( 'post_type' );
782
-        if( empty( $current_post_types  ) ){
783
-
784
-            // if empty it means post by default, so add post so that it also includes that for now
785
-            $new_post_types = array( 'post', 'course' );
786
-
787
-        } elseif( is_array( $current_post_types  ) ) {
788
-
789
-            // merge the post types instead of overwriting it
790
-            $new_post_types = array_merge( $current_post_types, array( 'course' ) );
791
-
792
-        }else{
793
-
794
-            // in this instance it is probably just one post type in string format
795
-            $new_post_types =  array( $current_post_types , 'course');
796
-
797
-        }
798
-
799
-        // change the query before returning it
800
-        $query->set('post_type', $new_post_types );
801
-
802
-        /**
803
-         * Change the query on the teacher author archive template
804
-         *
805
-         * @since 1.8.4
806
-         * @param WP_Query $query
807
-         */
808
-        return apply_filters( 'sensei_teacher_archive_query', $query );
809
-
810
-    }
811
-
812
-    /**
813
-     * Notify teacher when someone assigns a course to their account.
814
-     *
815
-     * @since 1.8.0
816
-     *
817
-     * @param $teacher_id
818
-     * @param $course_id
819
-     * @return bool
820
-     */
821
-    public function teacher_course_assigned_notification( $teacher_id, $course_id ){
822
-
823
-        if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){
824
-            return false;
825
-        }
826
-
827
-        // if new user is the same as the current logged user, they don't need an email
828
-        if( $teacher_id == get_current_user_id() ){
829
-            return true;
830
-        }
831
-
832
-        // load the email class
833
-        include('emails/class-woothemes-sensei-teacher-new-course-assignment.php');
834
-        $email = new Teacher_New_Course_Assignment();
835
-        $email->trigger( $teacher_id, $course_id );
836
-
837
-        return true;
838
-    } // end  teacher_course_assigned_notification
839
-
840
-    /**
841
-     * Email the admin when a teacher creates a new course
842
-     *
843
-     * This function hooks into wp_insert_post
844
-     *
845
-     * @since 1.8.0
846
-     * @param int $course_id
847
-     * @return bool
848
-     */
849
-    public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){
850
-
851
-        $course_id = $post->ID;
852
-
853
-        if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id )
854
-            || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) {
855
-
856
-            return false;
857
-
858
-        }
859
-
860
-        /**
861
-         * Filter the option to send admin notification emails when teachers creation
862
-         * course.
863
-         *
864
-         * @since 1.8.0
865
-         *
866
-         * @param bool $on default true
867
-         */
868
-        if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){
869
-            return false;
870
-        }
871
-
872
-        // setting up the data needed by the email template
873
-        global $sensei_email_data;
874
-        $template = 'admin-teacher-new-course-created';
875
-        $course = get_post( $course_id );
876
-        $teacher = new WP_User( $course->post_author );
877
-        $recipient = get_option('admin_email', true);
878
-
879
-        // don't send if the course is created by admin
880
-        if( $recipient == $teacher->user_email ){
881
-            return;
882
-        }
883
-
884
-        /**
885
-         * Filter the email Header for the admin-teacher-new-course-created template
886
-         *
887
-         * @since 1.8.0
888
-         * @param string $template
889
-         */
890
-        $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template );
891
-
892
-        /**
893
-         * Filter the email subject for the the
894
-         * admin-teacher-new-course-created template
895
-         *
896
-         * @since 1.8.0
897
-         * @param string $subject default New course assigned to you
898
-         * @param string $template
899
-         */
900
-        $subject = apply_filters('sensei_email_subject',
901
-                                '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name ,
902
-                                $template );
903
-
904
-        //course edit link
905
-        $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' );
906
-
907
-        // Construct data array
908
-        $email_data = array(
909
-            'template'			=> $template,
910
-            'heading' =>  $heading,
911
-            'teacher'		=> $teacher,
912
-            'course_id'			=> $course_id,
913
-            'course_name'			=> $course->post_title,
914
-            'course_edit_link' => $course_edit_link,
915
-        );
916
-
917
-        /**
918
-         * Filter the sensei email data for the admin-teacher-new-course-created template
919
-         *
920
-         * @since 1.8.0
921
-         * @param array $email_data
922
-         * @param string $template
923
-         */
924
-        $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template );
925
-
926
-        // Send mail
927
-        Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) );
928
-
929
-    }// end notify admin of course creation
930
-
931
-    /**
932
-     * Limit the analysis view to only the users taking courses belong to this teacher
933
-     *
934
-     * Hooked into sensei_analysis_get_learners
935
-     * @param array $args WP_User_Query arguments
936
-     * @return array $learners_query_results
937
-     */
938
-    public function limit_analysis_learners( $args ){
939
-
940
-        // show default for none teachers
941
-        if( ! Sensei()->teacher->is_admin_teacher() ) {
942
-                return $args;
943
-        }
944
-
945
-        // for teachers all courses only return those which belong to the teacher
946
-        // as they don't have access to course belonging to other users
947
-        $teacher_courses = Sensei()->course->get_all_courses();
509
+	}// end update_course_lessons_author
510
+
511
+
512
+
513
+	/**
514
+	 * Sensei_Teacher::course_analysis_teacher_access_limit
515
+	 *
516
+	 * Alter the query so that users can only see their courses on the analysis page
517
+	 *
518
+	 * @since 1.8.0
519
+	 * @access public
520
+	 * @parameters $query
521
+	 * @return array $users user id array
522
+	 */
523
+	public function course_analysis_teacher_access_limit ( $query ) {
524
+
525
+		if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
526
+			return $query;
527
+		}
528
+
529
+		if ( ! function_exists( 'get_current_screen' ) ) {
530
+			return $query;
531
+		}
532
+
533
+		$screen = get_current_screen();
534
+		$sensei_post_types = array('course', 'lesson', 'question' );
535
+
536
+		// exit early for the following conditions
537
+		$limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' );
538
+
539
+		if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids )
540
+			|| ! in_array( $query->query['post_type'], $sensei_post_types ) ){
541
+			return $query;
542
+		}
543
+
544
+		global $current_user;
545
+		// set the query author to the current user to only show those those posts
546
+		$query->set( 'author', $current_user->ID );
547
+		return $query;
548
+
549
+	}// end course_analysis_teacher_access_limit
550
+
551
+
552
+	/**
553
+	 * Sensei_Teacher::limit_teacher_edit_screen_post_types
554
+	 *
555
+	 * Determine if we're in admin and the current logged in use is a teacher
556
+	 *
557
+	 * @since 1.8.0
558
+	 * @access public
559
+	 * @parameters array $wp_query
560
+	 * @return bool $is_admin_teacher
561
+	 */
562
+	public function is_admin_teacher ( ){
563
+
564
+		if( ! is_user_logged_in()){
565
+			return false;
566
+		}
567
+		$is_admin_teacher = false;
568
+
569
+		if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() )  ){
570
+
571
+			$is_admin_teacher = true;
572
+
573
+		}
574
+
575
+		return $is_admin_teacher;
576
+
577
+	} // end is_admin_teacher
578
+
579
+	/**
580
+	 * Show correct post counts on list table for Sensei post types
581
+	 *
582
+	 * @since 1.8.0
583
+	 *
584
+	 * @param  object $counts Default status counts
585
+	 * @param  string $type   Current post type
586
+	 * @param  string $perm   User permission level
587
+	 * @return object         Modified status counts
588
+	 */
589
+	public function list_table_counts( $counts, $type, $perm ) {
590
+		global $current_user;
591
+
592
+		if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) {
593
+			return $counts;
594
+		}
595
+
596
+		if( ! $this->is_admin_teacher() ) {
597
+			return $counts;
598
+		}
599
+
600
+		$args = array(
601
+			'post_type' => $type,
602
+			'author' => $current_user->ID,
603
+			'posts_per_page' => -1
604
+		);
605
+
606
+		 // Get all available statuses
607
+		$stati = get_post_stati();
608
+
609
+		// Update count object
610
+		foreach( $stati as $status ) {
611
+			$args['post_status'] = $status;
612
+			$posts = get_posts( $args );
613
+			$counts->$status = count( $posts );
614
+		}
615
+
616
+		return $counts;
617
+	}
618
+
619
+	/**
620
+	 * Filter the post queries to show
621
+	 * only lesson /course and users that belong
622
+	 * to the current logged teacher.
623
+	 *
624
+	 * @since 1.8.0
625
+	 *
626
+	 */
627
+	public function filter_queries ( $query ) {
628
+		global $current_user;
629
+
630
+		if( ! $this->is_admin_teacher() ) {
631
+			return;
632
+		}
633
+
634
+		if ( ! function_exists( 'get_current_screen' ) ) {
635
+			return;
636
+		}
637
+
638
+		$screen = get_current_screen();
639
+		if( empty( $screen ) ) {
640
+			return $query;
641
+		}
642
+		switch( $screen->id ) {
643
+			case 'sensei_page_sensei_grading':
644
+			case 'sensei_page_sensei_analysis':
645
+			case 'sensei_page_sensei_learners':
646
+			case 'lesson':
647
+			case 'course':
648
+			case 'question':
649
+			case 'lesson_page_module-order':
650
+
651
+			/**
652
+			 * sensei_filter_queries_set_author
653
+			 * Filter the author Sensei set for queries
654
+			 *
655
+			 * @since 1.8.0
656
+			 *
657
+			 * @param int $user_id
658
+			 * @param string $screen_id
659
+			 *
660
+			 */
661
+			$query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) );
662
+			break;
663
+		}
664
+	}
665
+
666
+	/**
667
+	 * Limit grading quizzes to only those within courses belonging to the current teacher
668
+	 * . This excludes the admin user.
669
+	 *
670
+	 * @since 1.8.0
671
+	 * @hooked into the_comments
672
+	 * @param array  $comments
673
+	 *
674
+	 * @return array $comments
675
+	 */
676
+	public function filter_grading_activity_queries( $comments ){
677
+
678
+		if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){
679
+			return $comments ;
680
+		}
681
+
682
+		//check if we're on the grading screen
683
+		$screen = get_current_screen();
684
+
685
+		if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){
686
+			return $comments;
687
+		}
688
+
689
+		// get the course and determine if the current teacher is the owner
690
+		// if not remove it from the list of comments to be returned
691
+		foreach( $comments as $key => $comment){
692
+			$lesson = get_post( $comment->comment_post_ID );
693
+			$course_id = Sensei()->lesson->get_course_id( $lesson->ID );
694
+			$course = get_post( $course_id );
695
+			if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){
696
+				//remove this as the teacher should see this.
697
+				unset( $comments[ $key ] );
698
+			}
699
+		}
700
+		return $comments ;
701
+
702
+	}// end function filter grading
703
+
704
+	/**
705
+	 * Limit the grading screen totals to only show lessons in the course
706
+	 * belonging to the currently logged in teacher. This only applies to
707
+	 * the teacher role.
708
+	 *
709
+	 * @since 1.8.0
710
+	 *
711
+	 * @hooked into sensei_count_statuses_args
712
+	 * @param array $args
713
+	 *
714
+	 * @return array  $args
715
+	 */
716
+	public function limit_grading_totals( $args ){
717
+
718
+		if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){
719
+			return $args ;
720
+		}
721
+
722
+		//get the teachers courses
723
+		// the query is already filtered to only the teacher
724
+		$courses =  Sensei()->course->get_all_courses();
725
+
726
+		if( empty(  $courses ) || ! is_array( $courses ) ){
727
+			return $args;
728
+		}
729
+
730
+		//setup the lessons quizzes  to limit the grading totals to
731
+		$quiz_scope = array();
732
+		foreach( $courses as $course ){
733
+
734
+			$course_lessons = Sensei()->course->course_lessons( $course->ID );
735
+
736
+			if( ! empty( $course_lessons ) && is_array( $course_lessons  ) ){
737
+
738
+				foreach(  $course_lessons as $lesson ){
739
+
740
+					$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID );
741
+					if( !empty( $quiz_id ) ) {
742
+
743
+						array_push( $quiz_scope, $quiz_id );
744
+
745
+					}
746
+
747
+				}
748
+
749
+			}
750
+
751
+		}
752
+
753
+		$args['post__in'] = $quiz_scope;
754
+
755
+		return $args;
756
+	}
757
+
758
+	/**
759
+	 * It ensures that the author archive shows course by the current user.
760
+	 *
761
+	 * This function is hooked into the pre_get_posts filter
762
+	 *
763
+	 * @param WP_Query $query
764
+	 * @return WP_Query $query
765
+	 */
766
+	public function add_courses_to_author_archive( $query ) {
767
+
768
+		if ( is_admin() || ! $query->is_author() ){
769
+			return $query;
770
+		}
771
+
772
+		// this should only apply to users with the teacher role
773
+		$current_page_user = get_user_by('login', $query->get('author_name') );
774
+		if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) )     {
775
+
776
+			return $query;
777
+
778
+		}
779
+
780
+		// Change post types depending on what is set already
781
+		$current_post_types = $query->get( 'post_type' );
782
+		if( empty( $current_post_types  ) ){
783
+
784
+			// if empty it means post by default, so add post so that it also includes that for now
785
+			$new_post_types = array( 'post', 'course' );
786
+
787
+		} elseif( is_array( $current_post_types  ) ) {
788
+
789
+			// merge the post types instead of overwriting it
790
+			$new_post_types = array_merge( $current_post_types, array( 'course' ) );
791
+
792
+		}else{
793
+
794
+			// in this instance it is probably just one post type in string format
795
+			$new_post_types =  array( $current_post_types , 'course');
796
+
797
+		}
798
+
799
+		// change the query before returning it
800
+		$query->set('post_type', $new_post_types );
801
+
802
+		/**
803
+		 * Change the query on the teacher author archive template
804
+		 *
805
+		 * @since 1.8.4
806
+		 * @param WP_Query $query
807
+		 */
808
+		return apply_filters( 'sensei_teacher_archive_query', $query );
809
+
810
+	}
811
+
812
+	/**
813
+	 * Notify teacher when someone assigns a course to their account.
814
+	 *
815
+	 * @since 1.8.0
816
+	 *
817
+	 * @param $teacher_id
818
+	 * @param $course_id
819
+	 * @return bool
820
+	 */
821
+	public function teacher_course_assigned_notification( $teacher_id, $course_id ){
822
+
823
+		if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){
824
+			return false;
825
+		}
826
+
827
+		// if new user is the same as the current logged user, they don't need an email
828
+		if( $teacher_id == get_current_user_id() ){
829
+			return true;
830
+		}
831
+
832
+		// load the email class
833
+		include('emails/class-woothemes-sensei-teacher-new-course-assignment.php');
834
+		$email = new Teacher_New_Course_Assignment();
835
+		$email->trigger( $teacher_id, $course_id );
836
+
837
+		return true;
838
+	} // end  teacher_course_assigned_notification
839
+
840
+	/**
841
+	 * Email the admin when a teacher creates a new course
842
+	 *
843
+	 * This function hooks into wp_insert_post
844
+	 *
845
+	 * @since 1.8.0
846
+	 * @param int $course_id
847
+	 * @return bool
848
+	 */
849
+	public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){
850
+
851
+		$course_id = $post->ID;
852
+
853
+		if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id )
854
+			|| 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) {
855
+
856
+			return false;
857
+
858
+		}
859
+
860
+		/**
861
+		 * Filter the option to send admin notification emails when teachers creation
862
+		 * course.
863
+		 *
864
+		 * @since 1.8.0
865
+		 *
866
+		 * @param bool $on default true
867
+		 */
868
+		if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){
869
+			return false;
870
+		}
871
+
872
+		// setting up the data needed by the email template
873
+		global $sensei_email_data;
874
+		$template = 'admin-teacher-new-course-created';
875
+		$course = get_post( $course_id );
876
+		$teacher = new WP_User( $course->post_author );
877
+		$recipient = get_option('admin_email', true);
878
+
879
+		// don't send if the course is created by admin
880
+		if( $recipient == $teacher->user_email ){
881
+			return;
882
+		}
883
+
884
+		/**
885
+		 * Filter the email Header for the admin-teacher-new-course-created template
886
+		 *
887
+		 * @since 1.8.0
888
+		 * @param string $template
889
+		 */
890
+		$heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template );
891
+
892
+		/**
893
+		 * Filter the email subject for the the
894
+		 * admin-teacher-new-course-created template
895
+		 *
896
+		 * @since 1.8.0
897
+		 * @param string $subject default New course assigned to you
898
+		 * @param string $template
899
+		 */
900
+		$subject = apply_filters('sensei_email_subject',
901
+								'['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name ,
902
+								$template );
903
+
904
+		//course edit link
905
+		$course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' );
906
+
907
+		// Construct data array
908
+		$email_data = array(
909
+			'template'			=> $template,
910
+			'heading' =>  $heading,
911
+			'teacher'		=> $teacher,
912
+			'course_id'			=> $course_id,
913
+			'course_name'			=> $course->post_title,
914
+			'course_edit_link' => $course_edit_link,
915
+		);
916
+
917
+		/**
918
+		 * Filter the sensei email data for the admin-teacher-new-course-created template
919
+		 *
920
+		 * @since 1.8.0
921
+		 * @param array $email_data
922
+		 * @param string $template
923
+		 */
924
+		$sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template );
925
+
926
+		// Send mail
927
+		Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) );
928
+
929
+	}// end notify admin of course creation
930
+
931
+	/**
932
+	 * Limit the analysis view to only the users taking courses belong to this teacher
933
+	 *
934
+	 * Hooked into sensei_analysis_get_learners
935
+	 * @param array $args WP_User_Query arguments
936
+	 * @return array $learners_query_results
937
+	 */
938
+	public function limit_analysis_learners( $args ){
939
+
940
+		// show default for none teachers
941
+		if( ! Sensei()->teacher->is_admin_teacher() ) {
942
+				return $args;
943
+		}
944
+
945
+		// for teachers all courses only return those which belong to the teacher
946
+		// as they don't have access to course belonging to other users
947
+		$teacher_courses = Sensei()->course->get_all_courses();
948 948
 
949
-        // if the user has no courses they should see no users
950
-        if( empty( $teacher_courses ) ||  ! is_array( $teacher_courses ) ){
951
-            // tell the query to return 0 students
952
-            $args[ 'include'] = array( 0 );
953
-            return $args;
954
-
955
-        }
956
-
957
-        $learner_ids_for_teacher_courses = array();
958
-        foreach( $teacher_courses as $course ){
959
-
960
-            $course_learner_ids = array();
961
-            $activity_comments =  WooThemes_Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true );
962
-
963
-            if( empty( $activity_comments ) ||  ( is_array( $activity_comments  ) && ! ( count( $activity_comments ) > 0 ) ) ){
964
-                continue; // skip to the next course as there are no users on this course
965
-            }
966
-
967
-            // it could be an array of comments or a single comment
968
-            if( is_array( $activity_comments ) ){
949
+		// if the user has no courses they should see no users
950
+		if( empty( $teacher_courses ) ||  ! is_array( $teacher_courses ) ){
951
+			// tell the query to return 0 students
952
+			$args[ 'include'] = array( 0 );
953
+			return $args;
954
+
955
+		}
956
+
957
+		$learner_ids_for_teacher_courses = array();
958
+		foreach( $teacher_courses as $course ){
959
+
960
+			$course_learner_ids = array();
961
+			$activity_comments =  WooThemes_Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true );
962
+
963
+			if( empty( $activity_comments ) ||  ( is_array( $activity_comments  ) && ! ( count( $activity_comments ) > 0 ) ) ){
964
+				continue; // skip to the next course as there are no users on this course
965
+			}
966
+
967
+			// it could be an array of comments or a single comment
968
+			if( is_array( $activity_comments ) ){
969 969
 
970
-                foreach( $activity_comments as $comment ){
970
+				foreach( $activity_comments as $comment ){
971 971
 
972
-                    $user = get_userdata( $comment->user_id );
972
+					$user = get_userdata( $comment->user_id );
973 973
 
974
-                    if( empty( $user ) ){
975
-                        // next comment in this array
976
-                        continue;
977
-                    }
974
+					if( empty( $user ) ){
975
+						// next comment in this array
976
+						continue;
977
+					}
978 978
 
979
-                    $course_learner_ids[] = $user->ID;
980
-                }
979
+					$course_learner_ids[] = $user->ID;
980
+				}
981 981
 
982
-            }else{
982
+			}else{
983 983
 
984
-                $user = get_userdata( $activity_comments->user_id );
985
-                $course_learner_ids[] = $user->ID;
984
+				$user = get_userdata( $activity_comments->user_id );
985
+				$course_learner_ids[] = $user->ID;
986 986
 
987
-            }
987
+			}
988 988
 
989
-            // add learners on this course to the all courses learner list
990
-            $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids );
989
+			// add learners on this course to the all courses learner list
990
+			$learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids );
991 991
 
992
-        }
992
+		}
993 993
 
994
-        // if there are no students taking the courses by this teacher don't show them any of the other users
995
-        if( empty( $learner_ids_for_teacher_courses ) ){
994
+		// if there are no students taking the courses by this teacher don't show them any of the other users
995
+		if( empty( $learner_ids_for_teacher_courses ) ){
996 996
 
997
-            $args[ 'include'] = array( 0 );
997
+			$args[ 'include'] = array( 0 );
998 998
 
999
-        }else{
999
+		}else{
1000 1000
 
1001
-            $args[ 'include'] = $learner_ids_for_teacher_courses;
1001
+			$args[ 'include'] = $learner_ids_for_teacher_courses;
1002 1002
 
1003
-        }
1003
+		}
1004 1004
 
1005
-        // return the WP_Use_Query arguments
1006
-        return $args;
1005
+		// return the WP_Use_Query arguments
1006
+		return $args;
1007 1007
 
1008
-    }// end limit_analysis_learners
1008
+	}// end limit_analysis_learners
1009 1009
 
1010
-    /**
1011
-     * Give teacher full admin access to the question post type
1012
-     * in certain cases.
1013
-     *
1014
-     * @since 1.8.0
1015
-     * @param $questions
1016
-     * @return mixed
1017
-     */
1018
-    public function allow_teacher_access_to_questions( $questions, $quiz_id ){
1010
+	/**
1011
+	 * Give teacher full admin access to the question post type
1012
+	 * in certain cases.
1013
+	 *
1014
+	 * @since 1.8.0
1015
+	 * @param $questions
1016
+	 * @return mixed
1017
+	 */
1018
+	public function allow_teacher_access_to_questions( $questions, $quiz_id ){
1019 1019
 
1020
-        if( ! $this->is_admin_teacher() ){
1021
-            return $questions;
1022
-        }
1020
+		if( ! $this->is_admin_teacher() ){
1021
+			return $questions;
1022
+		}
1023 1023
 
1024
-        $screen = get_current_screen();
1024
+		$screen = get_current_screen();
1025 1025
 
1026
-        // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions
1027
-        remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 );
1026
+		// don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions
1027
+		remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 );
1028 1028
 
1029
-        if( ! empty( $screen ) && 'lesson'== $screen->post_type ){
1029
+		if( ! empty( $screen ) && 'lesson'== $screen->post_type ){
1030 1030
 
1031
-            $admin_user = get_user_by('email', get_bloginfo('admin_email'));
1032
-            if( ! empty($admin_user) ){
1031
+			$admin_user = get_user_by('email', get_bloginfo('admin_email'));
1032
+			if( ! empty($admin_user) ){
1033 1033
 
1034
-                $current_teacher_id = get_current_user_id();
1034
+				$current_teacher_id = get_current_user_id();
1035 1035
 
1036
-                // set current user to admin so teacher can view all questions
1037
-                wp_set_current_user( $admin_user->ID  );
1038
-                $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id  );
1036
+				// set current user to admin so teacher can view all questions
1037
+				wp_set_current_user( $admin_user->ID  );
1038
+				$questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id  );
1039 1039
 
1040
-                // set the teacher as the current use again
1041
-                wp_set_current_user( $current_teacher_id );
1042
-            }
1040
+				// set the teacher as the current use again
1041
+				wp_set_current_user( $current_teacher_id );
1042
+			}
1043 1043
 
1044
-        }
1045
-        // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions
1046
-        add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 );
1044
+		}
1045
+		// attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions
1046
+		add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 );
1047 1047
 
1048
-        return $questions;
1049
-    }
1048
+		return $questions;
1049
+	}
1050 1050
 
1051
-    /**
1052
-     * Give the teacher role access to questions from the question bank
1053
-     *
1054
-     * @since 1.8.0
1055
-     * @param $wp_query
1056
-     * @return mixed
1057
-     */
1058
-    public function give_access_to_all_questions( $wp_query ){
1051
+	/**
1052
+	 * Give the teacher role access to questions from the question bank
1053
+	 *
1054
+	 * @since 1.8.0
1055
+	 * @param $wp_query
1056
+	 * @return mixed
1057
+	 */
1058
+	public function give_access_to_all_questions( $wp_query ){
1059 1059
 
1060
-        if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){
1060
+		if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){
1061 1061
 
1062
-            return $wp_query;
1063
-        }
1062
+			return $wp_query;
1063
+		}
1064 1064
 
1065
-        $screen = get_current_screen();
1066
-        if( ( isset($screen->id) && 'lesson' == $screen->id )
1067
-            || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){
1065
+		$screen = get_current_screen();
1066
+		if( ( isset($screen->id) && 'lesson' == $screen->id )
1067
+			|| ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){
1068 1068
 
1069
-            $admin_user = get_user_by('email', get_bloginfo('admin_email'));
1070
-            if( ! empty($admin_user) ){
1069
+			$admin_user = get_user_by('email', get_bloginfo('admin_email'));
1070
+			if( ! empty($admin_user) ){
1071 1071
 
1072
-                $current_teacher_id = get_current_user_id();
1072
+				$current_teacher_id = get_current_user_id();
1073 1073
 
1074
-                // set current user to admin so teacher can view all questions
1075
-                wp_set_current_user( $admin_user->ID  );
1074
+				// set current user to admin so teacher can view all questions
1075
+				wp_set_current_user( $admin_user->ID  );
1076 1076
 
1077
-                //run new query as admin
1078
-                $wp_query = new WP_Query( $wp_query->query );
1077
+				//run new query as admin
1078
+				$wp_query = new WP_Query( $wp_query->query );
1079 1079
 
1080
-                //set the teache as current use again
1081
-                wp_set_current_user( $current_teacher_id );
1080
+				//set the teache as current use again
1081
+				wp_set_current_user( $current_teacher_id );
1082 1082
 
1083
-            }
1084
-        }
1083
+			}
1084
+		}
1085 1085
 
1086
-        return $wp_query;
1087
-    }// end give_access_to_all_questions
1086
+		return $wp_query;
1087
+	}// end give_access_to_all_questions
1088 1088
 
1089
-    /**
1090
-     * Add new column heading to the course admin edit list
1091
-     *
1092
-     * @since 1.8.0
1093
-     * @param $columns
1094
-     * @return array
1095
-     */
1096
-    public function course_column_heading($columns) {
1089
+	/**
1090
+	 * Add new column heading to the course admin edit list
1091
+	 *
1092
+	 * @since 1.8.0
1093
+	 * @param $columns
1094
+	 * @return array
1095
+	 */
1096
+	public function course_column_heading($columns) {
1097 1097
 
1098
-        if( $this->is_admin_teacher() ){
1099
-            return $columns;
1100
-        }
1101
-        $new_columns = array(
1102
-            'teacher' => __('Teacher', 'woothemes-sensei'),
1103
-        );
1104
-        return array_merge($columns, $new_columns);
1098
+		if( $this->is_admin_teacher() ){
1099
+			return $columns;
1100
+		}
1101
+		$new_columns = array(
1102
+			'teacher' => __('Teacher', 'woothemes-sensei'),
1103
+		);
1104
+		return array_merge($columns, $new_columns);
1105 1105
 
1106
-    }// end teacher column add
1106
+	}// end teacher column add
1107 1107
 
1108
-    /**
1109
-     * Print out  teacher column data
1110
-     *
1111
-     * @since 1.8.0
1112
-     * @param $column
1113
-     * @param $course_id
1114
-     */
1115
-    public function course_column_data( $column, $course_id  ){
1108
+	/**
1109
+	 * Print out  teacher column data
1110
+	 *
1111
+	 * @since 1.8.0
1112
+	 * @param $column
1113
+	 * @param $course_id
1114
+	 */
1115
+	public function course_column_data( $column, $course_id  ){
1116 1116
 
1117
-        if( $this->is_admin_teacher() || 'teacher' != $column  ){
1118
-            return;
1119
-        }
1117
+		if( $this->is_admin_teacher() || 'teacher' != $column  ){
1118
+			return;
1119
+		}
1120 1120
 
1121
-        $course = get_post( $course_id );
1122
-        $teacher = get_userdata( $course->post_author );
1121
+		$course = get_post( $course_id );
1122
+		$teacher = get_userdata( $course->post_author );
1123 1123
 
1124
-        if( !$teacher ){
1125
-            return;
1126
-        }
1124
+		if( !$teacher ){
1125
+			return;
1126
+		}
1127 1127
 
1128
-        echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>';
1128
+		echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>';
1129 1129
 
1130
-    }// end course_column_ data
1130
+	}// end course_column_ data
1131 1131
 
1132
-    /**
1133
-     * Return only courses belonging to the given teacher.
1134
-     *
1135
-     *
1136
-     * @since 1.8.0
1137
-     *
1138
-     * @param int $teacher_id
1139
-     * @param bool $return_ids_only
1140
-     *
1141
-     * @return array $teachers_courses
1142
-     */
1143
-    public function get_teacher_courses( $teacher_id, $return_ids_only= false){
1132
+	/**
1133
+	 * Return only courses belonging to the given teacher.
1134
+	 *
1135
+	 *
1136
+	 * @since 1.8.0
1137
+	 *
1138
+	 * @param int $teacher_id
1139
+	 * @param bool $return_ids_only
1140
+	 *
1141
+	 * @return array $teachers_courses
1142
+	 */
1143
+	public function get_teacher_courses( $teacher_id, $return_ids_only= false){
1144 1144
 
1145
-        $teachers_courses = array();
1145
+		$teachers_courses = array();
1146 1146
 
1147
-        if( empty( $teacher_id  ) ){
1148
-            $teacher_id = get_current_user_id();
1149
-        }
1147
+		if( empty( $teacher_id  ) ){
1148
+			$teacher_id = get_current_user_id();
1149
+		}
1150 1150
 
1151
-        $all_courses = Sensei()->course->get_all_courses();
1151
+		$all_courses = Sensei()->course->get_all_courses();
1152 1152
 
1153
-        if( empty( $all_courses ) ){
1154
-            return $all_courses;
1155
-        }
1153
+		if( empty( $all_courses ) ){
1154
+			return $all_courses;
1155
+		}
1156 1156
 
1157
-        foreach( $all_courses as $course ){
1157
+		foreach( $all_courses as $course ){
1158 1158
 
1159
-            if( $course->post_author != $teacher_id  ){
1160
-                continue;
1161
-            }
1159
+			if( $course->post_author != $teacher_id  ){
1160
+				continue;
1161
+			}
1162 1162
 
1163
-            if( $return_ids_only ){
1163
+			if( $return_ids_only ){
1164 1164
 
1165
-                $teachers_courses[] = $course->ID;
1165
+				$teachers_courses[] = $course->ID;
1166 1166
 
1167
-            }else{
1167
+			}else{
1168 1168
 
1169
-                $teachers_courses[] = $course;
1169
+				$teachers_courses[] = $course;
1170 1170
 
1171
-            }
1171
+			}
1172 1172
 
1173
-        }
1173
+		}
1174 1174
 
1175
-        return $teachers_courses;
1175
+		return $teachers_courses;
1176 1176
 
1177
-    }
1177
+	}
1178 1178
 
1179
-    /**
1180
-     * Limit the message display to only those sent to the current teacher
1181
-     *
1182
-     * @since 1.8.0
1183
-     *
1184
-     * @param $query
1185
-     * @return mixed
1186
-     */
1187
-    public function limit_edit_messages_query( $query ){
1188
-        if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){
1189
-            return $query;
1190
-        }
1191
-
1192
-        $teacher = wp_get_current_user();
1193
-
1194
-        $query->set( 'meta_key', '_receiver' );
1195
-        $meta_query_args = array(
1196
-            'key'     => '_receiver',
1197
-            'value'   => $teacher->get('user_login') ,
1198
-            'compare' => '='
1199
-        );
1179
+	/**
1180
+	 * Limit the message display to only those sent to the current teacher
1181
+	 *
1182
+	 * @since 1.8.0
1183
+	 *
1184
+	 * @param $query
1185
+	 * @return mixed
1186
+	 */
1187
+	public function limit_edit_messages_query( $query ){
1188
+		if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){
1189
+			return $query;
1190
+		}
1191
+
1192
+		$teacher = wp_get_current_user();
1193
+
1194
+		$query->set( 'meta_key', '_receiver' );
1195
+		$meta_query_args = array(
1196
+			'key'     => '_receiver',
1197
+			'value'   => $teacher->get('user_login') ,
1198
+			'compare' => '='
1199
+		);
1200 1200
 
1201
-        $query->set('meta_query', $meta_query_args  );
1201
+		$query->set('meta_query', $meta_query_args  );
1202 1202
 
1203
-        return $query;
1204
-    }
1203
+		return $query;
1204
+	}
1205 1205
 
1206 1206
 
1207
-    /**
1208
-     * Add options to filter courses by teacher
1209
-     *
1210
-     * @since 1.8.0
1211
-     *
1212
-     * @return void
1213
-     */
1214
-    public function course_teacher_filter_options() {
1215
-        global $typenow;
1207
+	/**
1208
+	 * Add options to filter courses by teacher
1209
+	 *
1210
+	 * @since 1.8.0
1211
+	 *
1212
+	 * @return void
1213
+	 */
1214
+	public function course_teacher_filter_options() {
1215
+		global $typenow;
1216 1216
 
1217
-        if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) {
1218
-            return;
1219
-        }
1217
+		if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) {
1218
+			return;
1219
+		}
1220 1220
 
1221
-        // get all roles
1222
-        $roles = get_editable_roles();
1221
+		// get all roles
1222
+		$roles = get_editable_roles();
1223 1223
 
1224
-        // get roles with the course edit capability
1225
-        // and then get the users with those roles
1226
-        $users_who_can_edit_courses = array();
1227
-        foreach( $roles as $role_item ){
1224
+		// get roles with the course edit capability
1225
+		// and then get the users with those roles
1226
+		$users_who_can_edit_courses = array();
1227
+		foreach( $roles as $role_item ){
1228 1228
 
1229
-            $role = get_role( strtolower( $role_item['name'] ) );
1229
+			$role = get_role( strtolower( $role_item['name'] ) );
1230 1230
 
1231
-            if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){
1231
+			if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){
1232 1232
 
1233
-                $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) );
1234
-                $role_users_who_can_edit_courses = get_users( $user_query_args );
1233
+				$user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) );
1234
+				$role_users_who_can_edit_courses = get_users( $user_query_args );
1235 1235
 
1236
-                // add user from the current $user_role to all users
1237
-                $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses );
1236
+				// add user from the current $user_role to all users
1237
+				$users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses );
1238 1238
 
1239
-            }
1239
+			}
1240 1240
 
1241
-        }
1241
+		}
1242 1242
 
1243
-        // Create the select element with the given users who can edit course
1244
-        $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1245
-        $course_options = '';
1246
-        foreach( $users_who_can_edit_courses as $user ) {
1247
-            $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' .  $user->display_name . '</option>';
1248
-        }
1243
+		// Create the select element with the given users who can edit course
1244
+		$selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1245
+		$course_options = '';
1246
+		foreach( $users_who_can_edit_courses as $user ) {
1247
+			$course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' .  $user->display_name . '</option>';
1248
+		}
1249 1249
 
1250
-        $output = '<select name="course_teacher" id="dropdown_course_teachers">';
1251
-        $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>';
1252
-        $output .= $course_options;
1253
-        $output .= '</select>';
1250
+		$output = '<select name="course_teacher" id="dropdown_course_teachers">';
1251
+		$output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>';
1252
+		$output .= $course_options;
1253
+		$output .= '</select>';
1254 1254
 
1255
-        echo $output;
1256
-    }
1255
+		echo $output;
1256
+	}
1257 1257
 
1258
-    /**
1259
-     * Modify the main query on the admin course list screen
1260
-     *
1261
-     * @since 1.8.0
1262
-     *
1263
-     * @param $query
1264
-     * @return $query
1265
-     */
1266
-    public function teacher_filter_query_modify( $query ){
1267
-        global $typenow;
1258
+	/**
1259
+	 * Modify the main query on the admin course list screen
1260
+	 *
1261
+	 * @since 1.8.0
1262
+	 *
1263
+	 * @param $query
1264
+	 * @return $query
1265
+	 */
1266
+	public function teacher_filter_query_modify( $query ){
1267
+		global $typenow;
1268 1268
 
1269
-        if( ! is_admin() && 'course' != $typenow  || ! current_user_can('manage_sensei')  ) {
1270
-            return $query;
1271
-        }
1272
-        $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1273
-
1274
-        if( empty( $course_teacher ) ) {
1275
-            return $query;
1276
-        }
1277
-
1278
-        $query['author'] = $course_teacher;
1279
-        return $query;
1280
-    }
1281
-
1282
-    /**
1283
-     * Only show current teacher's media in the media library
1284
-     * @param  array $request Default request arguments
1285
-     * @return array          Modified request arguments
1286
-     */
1287
-    public function restrict_media_library( $request = array() ) {
1288
-
1289
-        if( ! is_admin() ) {
1290
-            return $request;
1291
-        }
1292
-
1293
-        if( ! $this->is_admin_teacher() ) {
1294
-            return $request;
1295
-        }
1296
-
1297
-        $screen = get_current_screen();
1298
-
1299
-        if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) {
1300
-            $teacher = intval( get_current_user_id() );
1301
-
1302
-            if( $teacher ) {
1303
-                $request['author__in'] = array( $teacher );
1304
-            }
1305
-        }
1306
-
1307
-        return $request;
1308
-    } // End restrict_media_library()
1309
-
1310
-    /**
1311
-     * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen
1312
-     * @param  array $query Default query arguments
1313
-     * @return array        Modified query arguments
1314
-     */
1315
-    public function restrict_media_library_modal( $query = array() ) {
1316
-
1317
-        if( ! is_admin() ) {
1318
-            return $query;
1319
-        }
1320
-
1321
-        if( ! $this->is_admin_teacher() ) {
1322
-            return $query;
1323
-        }
1324
-
1325
-        $teacher = intval( get_current_user_id() );
1326
-
1327
-        if( $teacher ) {
1328
-            $query['author__in'] = array( $teacher );
1329
-        }
1330
-
1331
-        return $query;
1332
-    } // End restrict_media_library_modal()
1333
-
1334
-    /**
1335
-     * When saving the lesson, update the teacher if the lesson belongs to a course
1336
-     *
1337
-     * @since 1.8.0
1338
-     *
1339
-     * @param int $lesson_id
1340
-     */
1341
-    public function update_lesson_teacher( $lesson_id ){
1342
-
1343
-        if( 'lesson'!= get_post_type() ){
1344
-            return;
1345
-        }
1269
+		if( ! is_admin() && 'course' != $typenow  || ! current_user_can('manage_sensei')  ) {
1270
+			return $query;
1271
+		}
1272
+		$course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1273
+
1274
+		if( empty( $course_teacher ) ) {
1275
+			return $query;
1276
+		}
1277
+
1278
+		$query['author'] = $course_teacher;
1279
+		return $query;
1280
+	}
1281
+
1282
+	/**
1283
+	 * Only show current teacher's media in the media library
1284
+	 * @param  array $request Default request arguments
1285
+	 * @return array          Modified request arguments
1286
+	 */
1287
+	public function restrict_media_library( $request = array() ) {
1288
+
1289
+		if( ! is_admin() ) {
1290
+			return $request;
1291
+		}
1292
+
1293
+		if( ! $this->is_admin_teacher() ) {
1294
+			return $request;
1295
+		}
1296
+
1297
+		$screen = get_current_screen();
1298
+
1299
+		if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) {
1300
+			$teacher = intval( get_current_user_id() );
1301
+
1302
+			if( $teacher ) {
1303
+				$request['author__in'] = array( $teacher );
1304
+			}
1305
+		}
1306
+
1307
+		return $request;
1308
+	} // End restrict_media_library()
1309
+
1310
+	/**
1311
+	 * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen
1312
+	 * @param  array $query Default query arguments
1313
+	 * @return array        Modified query arguments
1314
+	 */
1315
+	public function restrict_media_library_modal( $query = array() ) {
1316
+
1317
+		if( ! is_admin() ) {
1318
+			return $query;
1319
+		}
1320
+
1321
+		if( ! $this->is_admin_teacher() ) {
1322
+			return $query;
1323
+		}
1324
+
1325
+		$teacher = intval( get_current_user_id() );
1326
+
1327
+		if( $teacher ) {
1328
+			$query['author__in'] = array( $teacher );
1329
+		}
1330
+
1331
+		return $query;
1332
+	} // End restrict_media_library_modal()
1333
+
1334
+	/**
1335
+	 * When saving the lesson, update the teacher if the lesson belongs to a course
1336
+	 *
1337
+	 * @since 1.8.0
1338
+	 *
1339
+	 * @param int $lesson_id
1340
+	 */
1341
+	public function update_lesson_teacher( $lesson_id ){
1342
+
1343
+		if( 'lesson'!= get_post_type() ){
1344
+			return;
1345
+		}
1346 1346
 
1347
-        // this should only run once per request cycle
1348
-        remove_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
1347
+		// this should only run once per request cycle
1348
+		remove_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
1349 1349
 
1350
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
1350
+		$course_id = Sensei()->lesson->get_course_id( $lesson_id );
1351 1351
 
1352
-        if(  empty( $course_id ) || ! $course_id ){
1353
-            return;
1354
-        }
1352
+		if(  empty( $course_id ) || ! $course_id ){
1353
+			return;
1354
+		}
1355 1355
 
1356
-        $course = get_post( $course_id );
1356
+		$course = get_post( $course_id );
1357 1357
 
1358
-        $lesson_update_args= array(
1359
-            'ID' => $lesson_id ,
1360
-            'post_author' => $course->post_author
1361
-        );
1362
-        wp_update_post( $lesson_update_args );
1358
+		$lesson_update_args= array(
1359
+			'ID' => $lesson_id ,
1360
+			'post_author' => $course->post_author
1361
+		);
1362
+		wp_update_post( $lesson_update_args );
1363 1363
 
1364
-    } // end update_lesson_teacher
1364
+	} // end update_lesson_teacher
1365 1365
 
1366
-    /**
1367
-     * Sensei_Teacher::limit_teacher_edit_screen_post_types
1368
-     *
1369
-     * Limit teachers to only see their courses, lessons and questions
1370
-     *
1371
-     * @since 1.8.0
1372
-     * @access public
1373
-     * @parameters array $wp_query
1374
-     * @return WP_Query $wp_query
1375
-     */
1376
-    public function limit_teacher_edit_screen_post_types( $wp_query ) {
1377
-        global $current_user;
1366
+	/**
1367
+	 * Sensei_Teacher::limit_teacher_edit_screen_post_types
1368
+	 *
1369
+	 * Limit teachers to only see their courses, lessons and questions
1370
+	 *
1371
+	 * @since 1.8.0
1372
+	 * @access public
1373
+	 * @parameters array $wp_query
1374
+	 * @return WP_Query $wp_query
1375
+	 */
1376
+	public function limit_teacher_edit_screen_post_types( $wp_query ) {
1377
+		global $current_user;
1378 1378
 
1379
-        //exit early
1380
-        if( ! $this->is_admin_teacher() ){
1381
-            return $wp_query;
1382
-        }
1379
+		//exit early
1380
+		if( ! $this->is_admin_teacher() ){
1381
+			return $wp_query;
1382
+		}
1383 1383
 
1384
-        if ( ! function_exists( 'get_current_screen' ) ) {
1385
-            return $wp_query;
1386
-        }
1384
+		if ( ! function_exists( 'get_current_screen' ) ) {
1385
+			return $wp_query;
1386
+		}
1387 1387
 
1388
-        $screen = get_current_screen();
1388
+		$screen = get_current_screen();
1389 1389
 
1390
-        if( empty( $screen ) ){
1391
-            return $wp_query;
1392
-        }
1390
+		if( empty( $screen ) ){
1391
+			return $wp_query;
1392
+		}
1393 1393
 
1394
-        // for any of these conditions limit what the teacher will see
1395
-        $limit_screens = array(
1396
-            'edit-lesson',
1397
-            'edit-course',
1398
-            'edit-question',
1399
-            'course_page_course-order',
1400
-            'lesson_page_lesson-order',
1401
-        );
1394
+		// for any of these conditions limit what the teacher will see
1395
+		$limit_screens = array(
1396
+			'edit-lesson',
1397
+			'edit-course',
1398
+			'edit-question',
1399
+			'course_page_course-order',
1400
+			'lesson_page_lesson-order',
1401
+		);
1402 1402
 
1403
-        if(  in_array($screen->id  , $limit_screens ) ) {
1403
+		if(  in_array($screen->id  , $limit_screens ) ) {
1404 1404
 
1405
-            // set the query author to the current user to only show those those posts
1406
-            $wp_query->set( 'author', $current_user->ID );
1407
-        }
1405
+			// set the query author to the current user to only show those those posts
1406
+			$wp_query->set( 'author', $current_user->ID );
1407
+		}
1408 1408
 
1409
-        return $wp_query;
1409
+		return $wp_query;
1410 1410
 
1411
-    } // end limit_teacher_edit_screen_post_types()
1411
+	} // end limit_teacher_edit_screen_post_types()
1412 1412
 
1413 1413
 
1414
-    /**
1415
-     * Sensei_Teacher::teacher_login_redirect
1416
-     *
1417
-     * Redirect teachers to /wp-admin/ after login
1418
-     *
1419
-     * @since 1.8.7
1420
-     * @access public
1421
-     * @param string $user_login
1422
-     * @param object $user
1423
-     * @return void
1424
-     */
1414
+	/**
1415
+	 * Sensei_Teacher::teacher_login_redirect
1416
+	 *
1417
+	 * Redirect teachers to /wp-admin/ after login
1418
+	 *
1419
+	 * @since 1.8.7
1420
+	 * @access public
1421
+	 * @param string $user_login
1422
+	 * @param object $user
1423
+	 * @return void
1424
+	 */
1425 1425
 
1426
-    public function teacher_login_redirect( $user_login, $user  ) {
1426
+	public function teacher_login_redirect( $user_login, $user  ) {
1427 1427
 
1428
-        if (user_can($user, 'edit_courses')) {
1428
+		if (user_can($user, 'edit_courses')) {
1429 1429
 
1430
-            if (isset($_POST['redirect_to'])) {
1430
+			if (isset($_POST['redirect_to'])) {
1431 1431
 
1432
-                wp_redirect($_POST['redirect_to'], 303);
1432
+				wp_redirect($_POST['redirect_to'], 303);
1433 1433
 
1434
-                exit;
1434
+				exit;
1435 1435
 
1436
-            } else {
1436
+			} else {
1437 1437
 
1438
-                wp_redirect(admin_url(), 303);
1438
+				wp_redirect(admin_url(), 303);
1439 1439
 
1440
-                exit;
1440
+				exit;
1441 1441
 
1442
-            }
1443
-        }
1442
+			}
1443
+		}
1444 1444
 
1445
-    } // end teacher_login_redirect()
1445
+	} // end teacher_login_redirect()
1446 1446
 
1447 1447
 
1448 1448
 
1449
-    /**
1450
-     * Sensei_Teacher::restrict_posts_menu_page()
1451
-     *
1452
-     * Remove the Posts menu page for teachers and restrict access to it.
1453
-     * We have to do this because we give teachers the 'edit_posts' cap
1454
-     * so they can 'moderate_comments' as well.
1455
-     *
1456
-     * @since 1.8.7
1457
-     * @access public
1458
-     * @parameters void
1459
-     * @return void
1460
-     */
1449
+	/**
1450
+	 * Sensei_Teacher::restrict_posts_menu_page()
1451
+	 *
1452
+	 * Remove the Posts menu page for teachers and restrict access to it.
1453
+	 * We have to do this because we give teachers the 'edit_posts' cap
1454
+	 * so they can 'moderate_comments' as well.
1455
+	 *
1456
+	 * @since 1.8.7
1457
+	 * @access public
1458
+	 * @parameters void
1459
+	 * @return void
1460
+	 */
1461 1461
 
1462
-    public function restrict_posts_menu_page() {
1462
+	public function restrict_posts_menu_page() {
1463 1463
 
1464
-        global $pagenow, $typenow;
1464
+		global $pagenow, $typenow;
1465 1465
 
1466
-        $user = wp_get_current_user();
1466
+		$user = wp_get_current_user();
1467 1467
 
1468
-        /**
1469
-         * Filter the option to hide the Posts menu page.
1470
-         *
1471
-         * @since 1.8.7
1472
-         *
1473
-         * @param bool $restrict default true
1474
-         */
1468
+		/**
1469
+		 * Filter the option to hide the Posts menu page.
1470
+		 *
1471
+		 * @since 1.8.7
1472
+		 *
1473
+		 * @param bool $restrict default true
1474
+		 */
1475 1475
 
1476
-        $restrict = apply_filters('sensei_restrict_posts_menu_page', true );
1476
+		$restrict = apply_filters('sensei_restrict_posts_menu_page', true );
1477 1477
 
1478
-        if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) {
1478
+		if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) {
1479 1479
 
1480
-            remove_menu_page('edit.php');
1480
+			remove_menu_page('edit.php');
1481 1481
 
1482
-            if ($pagenow == "edit.php" || $pagenow == "post-new.php") {
1482
+			if ($pagenow == "edit.php" || $pagenow == "post-new.php") {
1483 1483
 
1484
-                if ($typenow == '' || $typenow == 'post' || $typenow == 'page') {
1484
+				if ($typenow == '' || $typenow == 'post' || $typenow == 'page') {
1485 1485
 
1486
-                    wp_die('You do not have sufficient permissions to access this page.');
1486
+					wp_die('You do not have sufficient permissions to access this page.');
1487 1487
 
1488
-                }
1488
+				}
1489 1489
 
1490
-            }
1490
+			}
1491 1491
 
1492
-        }
1492
+		}
1493 1493
 
1494
-    } // end restrict_posts_menu_page()
1494
+	} // end restrict_posts_menu_page()
1495 1495
 
1496
-    /**
1497
-     * Sensei_Teacher::restrict_comment_moderation()
1498
-     *
1499
-     * Restrict commendation moderation for teachers
1500
-     * so they can only moderate comments made to posts they own.
1501
-     *
1502
-     * @since 1.8.7
1503
-     * @access public
1504
-     * @parameters obj $clauses
1505
-     * @return obj $clauses
1506
-     */
1496
+	/**
1497
+	 * Sensei_Teacher::restrict_comment_moderation()
1498
+	 *
1499
+	 * Restrict commendation moderation for teachers
1500
+	 * so they can only moderate comments made to posts they own.
1501
+	 *
1502
+	 * @since 1.8.7
1503
+	 * @access public
1504
+	 * @parameters obj $clauses
1505
+	 * @return obj $clauses
1506
+	 */
1507 1507
 
1508
-    public function restrict_comment_moderation($clauses) {
1508
+	public function restrict_comment_moderation($clauses) {
1509 1509
 
1510
-        global $pagenow;
1510
+		global $pagenow;
1511 1511
 
1512
-        if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") {
1512
+		if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") {
1513 1513
 
1514
-            $clauses->query_vars['post_author'] = get_current_user_id();
1514
+			$clauses->query_vars['post_author'] = get_current_user_id();
1515 1515
 
1516
-        }
1516
+		}
1517 1517
 
1518
-        return $clauses;
1518
+		return $clauses;
1519 1519
 
1520
-    }   // end restrict_comment_moderation()
1520
+	}   // end restrict_comment_moderation()
1521 1521
 
1522
-    /**
1523
-     * Determine if a user is a teacher by ID
1524
-     *
1525
-     * @param int $user_id
1526
-     *
1527
-     * @return bool
1528
-     */
1529
-    public static function is_a_teacher( $user_id ){
1522
+	/**
1523
+	 * Determine if a user is a teacher by ID
1524
+	 *
1525
+	 * @param int $user_id
1526
+	 *
1527
+	 * @return bool
1528
+	 */
1529
+	public static function is_a_teacher( $user_id ){
1530 1530
 
1531
-        $user = get_user_by('id', $user_id);
1531
+		$user = get_user_by('id', $user_id);
1532 1532
 
1533
-        if( isset( $user->roles ) && in_array(  'teacher',  $user->roles )   ){
1533
+		if( isset( $user->roles ) && in_array(  'teacher',  $user->roles )   ){
1534 1534
 
1535
-            return true;
1535
+			return true;
1536 1536
 
1537
-        }else{
1537
+		}else{
1538 1538
 
1539
-            return false;
1539
+			return false;
1540 1540
 
1541
-        }
1541
+		}
1542 1542
 
1543
-    }// end is_a_teacher
1543
+	}// end is_a_teacher
1544 1544
 
1545
-    /**
1546
-     * The archive title on the teacher archive filter
1547
-     *
1548
-     * @since 1.9.0
1549
-     */
1550
-    public static function archive_title(){
1545
+	/**
1546
+	 * The archive title on the teacher archive filter
1547
+	 *
1548
+	 * @since 1.9.0
1549
+	 */
1550
+	public static function archive_title(){
1551 1551
 
1552
-        $author = get_user_by( 'id', get_query_var( 'author' ) );
1553
-        $author_name = $author->display_name;
1554
-        ?>
1552
+		$author = get_user_by( 'id', get_query_var( 'author' ) );
1553
+		$author_name = $author->display_name;
1554
+		?>
1555 1555
             <h2 class="teacher-archive-title">
1556 1556
 
1557 1557
                 <?php echo sprintf( __( 'All courses by %s', 'woothemes-sensei') , $author_name ); ?>
@@ -1559,17 +1559,17 @@  discard block
 block discarded – undo
1559 1559
             </h2>
1560 1560
         <?php
1561 1561
 
1562
-    }// archive title
1562
+	}// archive title
1563 1563
 
1564
-    /**
1565
-     * Removing course meta on the teacher archive page
1566
-     *
1567
-     * @since 1.9.0
1568
-     */
1569
-    public static function remove_course_meta_on_teacher_archive(){
1564
+	/**
1565
+	 * Removing course meta on the teacher archive page
1566
+	 *
1567
+	 * @since 1.9.0
1568
+	 */
1569
+	public static function remove_course_meta_on_teacher_archive(){
1570 1570
 
1571
-        remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) );
1571
+		remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) );
1572 1572
 
1573
-    }
1573
+	}
1574 1574
 
1575 1575
 } // End Class
Please login to merge, or discard this patch.
Spacing   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Teacher class
@@ -42,58 +42,58 @@  discard block
 block discarded – undo
42 42
      * @since 1.8.0
43 43
      * @access public
44 44
      */
45
-    public function __construct ( ) {
45
+    public function __construct( ) {
46 46
 
47
-        add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 );
48
-        add_action( 'save_post',  array( $this, 'save_teacher_meta_box' ) );
49
-        add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' ));
50
-        add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) );
51
-        add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 );
47
+        add_action('add_meta_boxes', array($this, 'add_teacher_meta_boxes'), 10, 2);
48
+        add_action('save_post', array($this, 'save_teacher_meta_box'));
49
+        add_filter('parse_query', array($this, 'limit_teacher_edit_screen_post_types'));
50
+        add_filter('pre_get_posts', array($this, 'course_analysis_teacher_access_limit'));
51
+        add_filter('wp_count_posts', array($this, 'list_table_counts'), 10, 3);
52 52
 
53
-        add_action( 'pre_get_posts', array( $this, 'filter_queries' ) );
53
+        add_action('pre_get_posts', array($this, 'filter_queries'));
54 54
 
55 55
         //filter the quiz submissions
56
-        add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') );
56
+        add_filter('sensei_check_for_activity', array($this, 'filter_grading_activity_queries'));
57 57
 
58 58
         //grading totals count only those belonging to the teacher
59
-        add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) );
59
+        add_filter('sensei_count_statuses_args', array($this, 'limit_grading_totals'));
60 60
 
61 61
         // show the courses owned by a user on his author archive page
62
-        add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) );
62
+        add_filter('pre_get_posts', array($this, 'add_courses_to_author_archive'));
63 63
 
64 64
         // notify admin when a teacher creates a course
65
-        add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 );
65
+        add_action('transition_post_status', array($this, 'notify_admin_teacher_course_creation'), 10, 3);
66 66
 
67 67
         // limit the analysis view to only the users taking courses belong to this teacher
68
-        add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 );
68
+        add_filter('sensei_analysis_overview_filter_users', array($this, 'limit_analysis_learners'), 5, 1);
69 69
 
70 70
         // give teacher access to question post type
71
-        add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 );
71
+        add_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20, 2);
72 72
 
73 73
         // Teacher column on the courses list on the admin edit screen
74
-        add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 );
75
-        add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 );
74
+        add_filter('manage_edit-course_columns', array($this, 'course_column_heading'), 10, 1);
75
+        add_filter('manage_course_posts_custom_column', array($this, 'course_column_data'), 10, 2);
76 76
 
77 77
         //admin edit messages query limit teacher
78
-        add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) );
78
+        add_filter('pre_get_posts', array($this, 'limit_edit_messages_query'));
79 79
 
80 80
         //add filter by teacher on courses list
81
-        add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) );
82
-        add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) );
81
+        add_action('restrict_manage_posts', array($this, 'course_teacher_filter_options'));
82
+        add_filter('request', array($this, 'teacher_filter_query_modify'));
83 83
 
84 84
         // Handle media library restrictions
85
-        add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 );
86
-        add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 );
85
+        add_filter('request', array($this, 'restrict_media_library'), 10, 1);
86
+        add_filter('ajax_query_attachments_args', array($this, 'restrict_media_library_modal'), 10, 1);
87 87
 
88 88
         // update lesson owner to course teacher when saved
89
-        add_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
89
+        add_action('save_post', array($this, 'update_lesson_teacher'));
90 90
 
91 91
         // If a Teacher logs in, redirect to /wp-admin/
92
-        add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 );
92
+        add_filter('wp_login', array($this, 'teacher_login_redirect'), 10, 2);
93 93
 
94 94
 
95
-        add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10);
96
-        add_filter('pre_get_comments',  array ($this, 'restrict_comment_moderation'), 10, 1);
95
+        add_action('admin_menu', array($this, 'restrict_posts_menu_page'), 10);
96
+        add_filter('pre_get_comments', array($this, 'restrict_comment_moderation'), 10, 1);
97 97
 
98 98
 
99 99
     } // end __constructor()
@@ -108,15 +108,15 @@  discard block
 block discarded – undo
108 108
      * @access public
109 109
      * @return void
110 110
      */
111
-    public function create_role ( ) {
111
+    public function create_role( ) {
112 112
 
113 113
         // check if the role exists
114
-        $this->teacher_role = get_role( 'teacher' );
114
+        $this->teacher_role = get_role('teacher');
115 115
 
116 116
         // if the the teacher is not a valid WordPress role create it
117
-       if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) {
117
+       if ( ! is_a($this->teacher_role, 'WP_Role')) {
118 118
            // create the role
119
-           $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) );
119
+           $this->teacher_role = add_role('teacher', __('Teacher', 'woothemes-sensei'));
120 120
        }
121 121
 
122 122
        // add the capabilities before returning
@@ -130,10 +130,10 @@  discard block
 block discarded – undo
130 130
      * @since 1.8.0
131 131
      * @access protected
132 132
      */
133
-    protected function add_capabilities ( ) {
133
+    protected function add_capabilities( ) {
134 134
 
135 135
         // if this is not a valid WP_Role object exit without adding anything
136
-        if(  ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) {
136
+        if ( ! is_a($this->teacher_role, 'WP_Role') || empty($this->teacher_role)) {
137 137
             return;
138 138
         }
139 139
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
          * @param array $capabilities
145 145
          * keys: (string) $cap_name => (bool) $grant
146 146
          */
147
-        $caps = apply_filters( 'sensei_teacher_role_capabilities', array(
147
+        $caps = apply_filters('sensei_teacher_role_capabilities', array(
148 148
             // General access rules
149 149
             'read' => true,
150 150
             'manage_sensei_grades' => true,
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 
202 202
         ));
203 203
 
204
-        foreach ( $caps as $cap => $grant ) {
204
+        foreach ($caps as $cap => $grant) {
205 205
 
206 206
             // load the capability on to the teacher role
207 207
             $this->teacher_role->add_cap($cap, $grant);
@@ -221,12 +221,12 @@  discard block
 block discarded – undo
221 221
      * @parameter WP_Post $post
222 222
      * @return void
223 223
      */
224
-    public function add_teacher_meta_boxes ( $post ) {
224
+    public function add_teacher_meta_boxes($post) {
225 225
 
226
-        if( !current_user_can('manage_options') ){
226
+        if ( ! current_user_can('manage_options')) {
227 227
             return;
228 228
         }
229
-        add_meta_box( 'sensei-teacher',  __( 'Teacher' , $this->token ),  array( $this , 'teacher_meta_box_content' ),
229
+        add_meta_box('sensei-teacher', __('Teacher', $this->token), array($this, 'teacher_meta_box_content'),
230 230
             'course',
231 231
             'side',
232 232
             'core'
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
      * @access public
244 244
      * @parameters
245 245
      */
246
-    public function teacher_meta_box_content ( $post ) {
246
+    public function teacher_meta_box_content($post) {
247 247
 
248 248
         // get the current author
249 249
         $current_author = $post->post_author;
@@ -254,12 +254,12 @@  discard block
 block discarded – undo
254 254
     ?>
255 255
         <select name="sensei-course-teacher-author" class="sensei course teacher">
256 256
 
257
-            <?php foreach ( $users as $user_id ) { ?>
257
+            <?php foreach ($users as $user_id) { ?>
258 258
 
259 259
                     <?php
260 260
                         $user = get_user_by('id', $user_id);
261 261
                     ?>
262
-                    <option <?php selected(  $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" >
262
+                    <option <?php selected($current_author, $user_id, true); ?> value="<?php echo $user_id; ?>" >
263 263
                         <?php echo  $user->display_name; ?>
264 264
                     </option>
265 265
 
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
      * @parameters
282 282
      * @return array $users user id array
283 283
      */
284
-    public function get_teachers_and_authors ( ){
284
+    public function get_teachers_and_authors( ) {
285 285
 
286 286
         $author_query_args = array(
287 287
             'blog_id'      => $GLOBALS['blog_id'],
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
             'who'          => 'authors'
290 290
         );
291 291
 
292
-        $authors = get_users( $author_query_args );
292
+        $authors = get_users($author_query_args);
293 293
 
294 294
         $teacher_query_args = array(
295 295
             'blog_id'      => $GLOBALS['blog_id'],
@@ -297,9 +297,9 @@  discard block
 block discarded – undo
297 297
             'role'         => 'teacher',
298 298
         );
299 299
 
300
-        $teachers = get_users( $teacher_query_args );
300
+        $teachers = get_users($teacher_query_args);
301 301
 
302
-        return  array_unique( array_merge( $teachers, $authors ) );
302
+        return  array_unique(array_merge($teachers, $authors));
303 303
 
304 304
     }// end get_teachers_and_authors
305 305
 
@@ -315,43 +315,43 @@  discard block
 block discarded – undo
315 315
      * @parameters
316 316
      * @return array $users user id array
317 317
      */
318
-    public function save_teacher_meta_box ( $course_id ){
318
+    public function save_teacher_meta_box($course_id) {
319 319
 
320 320
         // check if this is a post from saving the teacher, if not exit early
321
-        if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] )  ){
321
+        if ( ! isset($_POST['sensei-course-teacher-author']) || ! isset($_POST['post_ID'])) {
322 322
             return;
323 323
         }
324 324
 
325 325
         //don't fire this hook again
326
-        remove_action('save_post', array( $this, 'save_teacher_meta_box' ) );
326
+        remove_action('save_post', array($this, 'save_teacher_meta_box'));
327 327
 
328 328
         // get the current post object
329
-        $post = get_post( $course_id );
329
+        $post = get_post($course_id);
330 330
 
331 331
         // get the current teacher/author
332
-        $current_author = absint( $post->post_author );
333
-        $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] );
332
+        $current_author = absint($post->post_author);
333
+        $new_author = absint($_POST['sensei-course-teacher-author']);
334 334
 
335 335
         // loop through all post lessons to update their authors as well
336
-        $this->update_course_lessons_author( $course_id , $new_author );
336
+        $this->update_course_lessons_author($course_id, $new_author);
337 337
 
338 338
         // do not do any processing if the selected author is the same as the current author
339
-        if( $current_author == $new_author ){
339
+        if ($current_author == $new_author) {
340 340
             return;
341 341
         }
342 342
 
343 343
         // save the course  author
344 344
         $post_updates = array(
345
-            'ID' => $post->ID ,
345
+            'ID' => $post->ID,
346 346
             'post_author' => $new_author
347 347
         );
348
-        wp_update_post( $post_updates );
348
+        wp_update_post($post_updates);
349 349
 
350 350
         // ensure the the modules are update so that then new teacher has access to them
351
-        Sensei_Teacher::update_course_modules_author( $course_id, $new_author );
351
+        Sensei_Teacher::update_course_modules_author($course_id, $new_author);
352 352
 
353 353
         // notify the new teacher
354
-        $this->teacher_course_assigned_notification( $new_author, $course_id );
354
+        $this->teacher_course_assigned_notification($new_author, $course_id);
355 355
 
356 356
     } // end save_teacher_meta_box
357 357
 
@@ -365,56 +365,56 @@  discard block
 block discarded – undo
365 365
      * @param $new_teacher_id
366 366
      * @return void
367 367
      */
368
-    public static function update_course_modules_author( $course_id ,$new_teacher_id ){
368
+    public static function update_course_modules_author($course_id, $new_teacher_id) {
369 369
 
370
-        if( empty( $course_id ) || empty( $new_teacher_id ) ){
370
+        if (empty($course_id) || empty($new_teacher_id)) {
371 371
             return false;
372 372
         }
373 373
 
374
-        $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' );
374
+        $terms_selected_on_course = wp_get_object_terms($course_id, 'module');
375 375
 
376
-        if( empty( $terms_selected_on_course ) ){
376
+        if (empty($terms_selected_on_course)) {
377 377
             return;
378 378
         }
379 379
 
380
-        foreach( $terms_selected_on_course as $term ){
380
+        foreach ($terms_selected_on_course as $term) {
381 381
 
382
-            $term_author = Sensei_Core_Modules::get_term_author( $term->slug );
383
-            if( $new_teacher_id != $term_author->ID  ){
382
+            $term_author = Sensei_Core_Modules::get_term_author($term->slug);
383
+            if ($new_teacher_id != $term_author->ID) {
384 384
 
385 385
                 $new_term = '';
386 386
 
387 387
                 //if the new teacher is admin first check to see if the term with this name already exists
388
-                if( user_can( $new_teacher_id, 'manage_options' ) ){
388
+                if (user_can($new_teacher_id, 'manage_options')) {
389 389
 
390
-                    $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) );
391
-                    $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, );
392
-                    $existing_admin_terms = get_terms( 'module', $term_args );
393
-                    if( !empty( $existing_admin_terms ) ){
390
+                    $slug_without_teacher_id = str_ireplace(' ', '-', trim($term->name));
391
+                    $term_args = array('slug'=> $slug_without_teacher_id, 'hide_empty' => false,);
392
+                    $existing_admin_terms = get_terms('module', $term_args);
393
+                    if ( ! empty($existing_admin_terms)) {
394 394
                         // insert it even if it exists
395
-                        $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A );
395
+                        $new_term = get_term($existing_admin_terms[0]->term_id, 'module', ARRAY_A);
396 396
                     }
397 397
                 }
398 398
 
399
-                if( empty ( $new_term ) ){
399
+                if (empty ($new_term)) {
400 400
 
401 401
                    //setup the new slug
402
-                   $new_author_term_slug =  $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) );
402
+                   $new_author_term_slug = $new_teacher_id.'-'.str_ireplace(' ', '-', trim($term->name));
403 403
 
404 404
                    // create new term and set it
405
-                   $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug )  );
405
+                   $new_term = wp_insert_term($term->name, 'module', array('slug'=> $new_author_term_slug));
406 406
 
407 407
                 }
408 408
 
409 409
 
410 410
 
411 411
                 // if term exists
412
-                if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){
412
+                if (is_wp_error($new_term) && isset($new_term->errors['term_exists'])) {
413 413
 
414
-                    $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module');
414
+                    $existing_term = get_term_by('slug', $new_author_term_slug, 'module');
415 415
                     $term_id = $existing_term->term_id;
416 416
 
417
-                }else{
417
+                } else {
418 418
 
419 419
                     // for a new term simply get the term from the returned value
420 420
                     $term_id = $new_term['term_id'];
@@ -422,21 +422,21 @@  discard block
 block discarded – undo
422 422
                 } // end if term exist
423 423
 
424 424
                 // set the terms selected on the course
425
-                wp_set_object_terms( $course_id, $term_id , 'module', true );
425
+                wp_set_object_terms($course_id, $term_id, 'module', true);
426 426
 
427 427
                 // remove old term
428
-                wp_remove_object_terms( $course_id, $term->term_id, 'module' );
428
+                wp_remove_object_terms($course_id, $term->term_id, 'module');
429 429
 
430 430
                 // update the lessons within the current module term
431
-                $lessons = Sensei()->course->course_lessons( $course_id );
432
-                foreach( $lessons as $lesson  ){
431
+                $lessons = Sensei()->course->course_lessons($course_id);
432
+                foreach ($lessons as $lesson) {
433 433
 
434
-                    if( has_term( $term->slug, 'module', $lesson ) ){
434
+                    if (has_term($term->slug, 'module', $lesson)) {
435 435
 
436 436
                         // add the new term, the false at the end says to replace all terms on this module
437 437
                         // with the new term.
438
-                        wp_set_object_terms( $lesson->ID, $term_id , 'module', false );
439
-                        update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 );
438
+                        wp_set_object_terms($lesson->ID, $term_id, 'module', false);
439
+                        update_post_meta($lesson->ID, '_order_module_'.intval($term_id), 0);
440 440
                     }
441 441
 
442 442
                 }// end for each
@@ -456,50 +456,50 @@  discard block
 block discarded – undo
456 456
      * @parameters
457 457
      * @return array $users user id array
458 458
      */
459
-    public function update_course_lessons_author ( $course_id, $new_author  ){
459
+    public function update_course_lessons_author($course_id, $new_author) {
460 460
 
461 461
 
462
-        if( empty( $course_id ) || empty( $new_author ) ){
462
+        if (empty($course_id) || empty($new_author)) {
463 463
             return false;
464 464
         }
465 465
 
466 466
         //get a list of course lessons
467
-        $lessons = Sensei()->course->course_lessons( $course_id );
467
+        $lessons = Sensei()->course->course_lessons($course_id);
468 468
 
469
-        if( empty( $lessons )  ||  ! is_array( $lessons )  ){
469
+        if (empty($lessons) || ! is_array($lessons)) {
470 470
             return false;
471 471
         }
472 472
 
473 473
         // update each lesson and quiz author
474
-        foreach( $lessons as $lesson ){
474
+        foreach ($lessons as $lesson) {
475 475
 
476 476
             // don't update if the author is tha same as the new author
477
-            if( $new_author == $lesson->post_author ){
477
+            if ($new_author == $lesson->post_author) {
478 478
                 continue;
479 479
             }
480 480
 
481 481
             // update lesson author
482
-            wp_update_post( array(
482
+            wp_update_post(array(
483 483
                 'ID'=> $lesson->ID,
484 484
                 'post_author' => $new_author
485
-                ) );
485
+                ));
486 486
 
487 487
             // update quiz author
488 488
             //get the lessons quiz
489
-            $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID );
490
-            if( is_array( $lesson_quizzes ) ){
491
-                foreach ( $lesson_quizzes as $quiz_id ) {
489
+            $lesson_quizzes = Sensei()->lesson->lesson_quizzes($lesson->ID);
490
+            if (is_array($lesson_quizzes)) {
491
+                foreach ($lesson_quizzes as $quiz_id) {
492 492
                     // update quiz with new author
493
-                    wp_update_post( array(
493
+                    wp_update_post(array(
494 494
                         'ID'           => $quiz_id,
495 495
                         'post_author' =>  $new_author
496
-                    ) );
496
+                    ));
497 497
                 }
498
-            }else{
499
-                wp_update_post( array(
498
+            } else {
499
+                wp_update_post(array(
500 500
                     'ID'           => $lesson_quizzes,
501 501
                     'post_author' =>  $new_author
502
-                ) );
502
+                ));
503 503
             }
504 504
 
505 505
         } // end for each lessons
@@ -520,30 +520,30 @@  discard block
 block discarded – undo
520 520
      * @parameters $query
521 521
      * @return array $users user id array
522 522
      */
523
-    public function course_analysis_teacher_access_limit ( $query ) {
523
+    public function course_analysis_teacher_access_limit($query) {
524 524
 
525
-        if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
525
+        if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) {
526 526
             return $query;
527 527
         }
528 528
 
529
-        if ( ! function_exists( 'get_current_screen' ) ) {
529
+        if ( ! function_exists('get_current_screen')) {
530 530
             return $query;
531 531
         }
532 532
 
533 533
         $screen = get_current_screen();
534
-        $sensei_post_types = array('course', 'lesson', 'question' );
534
+        $sensei_post_types = array('course', 'lesson', 'question');
535 535
 
536 536
         // exit early for the following conditions
537
-        $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' );
537
+        $limit_screen_ids = array('sensei_page_sensei_analysis', 'course_page_module-order');
538 538
 
539
-        if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids )
540
-            || ! in_array( $query->query['post_type'], $sensei_post_types ) ){
539
+        if ( ! $this->is_admin_teacher() || empty($screen) || ! in_array($screen->id, $limit_screen_ids)
540
+            || ! in_array($query->query['post_type'], $sensei_post_types)) {
541 541
             return $query;
542 542
         }
543 543
 
544 544
         global $current_user;
545 545
         // set the query author to the current user to only show those those posts
546
-        $query->set( 'author', $current_user->ID );
546
+        $query->set('author', $current_user->ID);
547 547
         return $query;
548 548
 
549 549
     }// end course_analysis_teacher_access_limit
@@ -559,14 +559,14 @@  discard block
 block discarded – undo
559 559
      * @parameters array $wp_query
560 560
      * @return bool $is_admin_teacher
561 561
      */
562
-    public function is_admin_teacher ( ){
562
+    public function is_admin_teacher( ) {
563 563
 
564
-        if( ! is_user_logged_in()){
564
+        if ( ! is_user_logged_in()) {
565 565
             return false;
566 566
         }
567 567
         $is_admin_teacher = false;
568 568
 
569
-        if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() )  ){
569
+        if (is_admin() && Sensei_Teacher::is_a_teacher(get_current_user_id())) {
570 570
 
571 571
             $is_admin_teacher = true;
572 572
 
@@ -586,14 +586,14 @@  discard block
 block discarded – undo
586 586
      * @param  string $perm   User permission level
587 587
      * @return object         Modified status counts
588 588
      */
589
-    public function list_table_counts( $counts, $type, $perm ) {
589
+    public function list_table_counts($counts, $type, $perm) {
590 590
         global $current_user;
591 591
 
592
-        if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) {
592
+        if ( ! in_array($type, array('course', 'lesson', 'question'))) {
593 593
             return $counts;
594 594
         }
595 595
 
596
-        if( ! $this->is_admin_teacher() ) {
596
+        if ( ! $this->is_admin_teacher()) {
597 597
             return $counts;
598 598
         }
599 599
 
@@ -607,10 +607,10 @@  discard block
 block discarded – undo
607 607
         $stati = get_post_stati();
608 608
 
609 609
         // Update count object
610
-        foreach( $stati as $status ) {
610
+        foreach ($stati as $status) {
611 611
             $args['post_status'] = $status;
612
-            $posts = get_posts( $args );
613
-            $counts->$status = count( $posts );
612
+            $posts = get_posts($args);
613
+            $counts->$status = count($posts);
614 614
         }
615 615
 
616 616
         return $counts;
@@ -624,22 +624,22 @@  discard block
 block discarded – undo
624 624
      * @since 1.8.0
625 625
      *
626 626
      */
627
-    public function filter_queries ( $query ) {
627
+    public function filter_queries($query) {
628 628
         global $current_user;
629 629
 
630
-        if( ! $this->is_admin_teacher() ) {
630
+        if ( ! $this->is_admin_teacher()) {
631 631
             return;
632 632
         }
633 633
 
634
-        if ( ! function_exists( 'get_current_screen' ) ) {
634
+        if ( ! function_exists('get_current_screen')) {
635 635
             return;
636 636
         }
637 637
 
638 638
         $screen = get_current_screen();
639
-        if( empty( $screen ) ) {
639
+        if (empty($screen)) {
640 640
             return $query;
641 641
         }
642
-        switch( $screen->id ) {
642
+        switch ($screen->id) {
643 643
             case 'sensei_page_sensei_grading':
644 644
             case 'sensei_page_sensei_analysis':
645 645
             case 'sensei_page_sensei_learners':
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
              * @param string $screen_id
659 659
              *
660 660
              */
661
-            $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) );
661
+            $query->set('author', apply_filters('sensei_filter_queries_set_author', $current_user->ID, $screen->id));
662 662
             break;
663 663
         }
664 664
     }
@@ -673,31 +673,31 @@  discard block
 block discarded – undo
673 673
      *
674 674
      * @return array $comments
675 675
      */
676
-    public function filter_grading_activity_queries( $comments ){
676
+    public function filter_grading_activity_queries($comments) {
677 677
 
678
-        if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){
679
-            return $comments ;
678
+        if ( ! is_admin() || ! $this->is_admin_teacher() || is_numeric($comments) || ! is_array($comments)) {
679
+            return $comments;
680 680
         }
681 681
 
682 682
         //check if we're on the grading screen
683 683
         $screen = get_current_screen();
684 684
 
685
-        if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){
685
+        if (empty($screen) || 'sensei_page_sensei_grading' != $screen->id) {
686 686
             return $comments;
687 687
         }
688 688
 
689 689
         // get the course and determine if the current teacher is the owner
690 690
         // if not remove it from the list of comments to be returned
691
-        foreach( $comments as $key => $comment){
692
-            $lesson = get_post( $comment->comment_post_ID );
693
-            $course_id = Sensei()->lesson->get_course_id( $lesson->ID );
694
-            $course = get_post( $course_id );
695
-            if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){
691
+        foreach ($comments as $key => $comment) {
692
+            $lesson = get_post($comment->comment_post_ID);
693
+            $course_id = Sensei()->lesson->get_course_id($lesson->ID);
694
+            $course = get_post($course_id);
695
+            if ( ! isset($course->post_author) || intval($course->post_author) != intval(get_current_user_id())) {
696 696
                 //remove this as the teacher should see this.
697
-                unset( $comments[ $key ] );
697
+                unset($comments[$key]);
698 698
             }
699 699
         }
700
-        return $comments ;
700
+        return $comments;
701 701
 
702 702
     }// end function filter grading
703 703
 
@@ -713,34 +713,34 @@  discard block
 block discarded – undo
713 713
      *
714 714
      * @return array  $args
715 715
      */
716
-    public function limit_grading_totals( $args ){
716
+    public function limit_grading_totals($args) {
717 717
 
718
-        if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){
719
-            return $args ;
718
+        if ( ! is_admin() || ! $this->is_admin_teacher() || ! is_array($args)) {
719
+            return $args;
720 720
         }
721 721
 
722 722
         //get the teachers courses
723 723
         // the query is already filtered to only the teacher
724
-        $courses =  Sensei()->course->get_all_courses();
724
+        $courses = Sensei()->course->get_all_courses();
725 725
 
726
-        if( empty(  $courses ) || ! is_array( $courses ) ){
726
+        if (empty($courses) || ! is_array($courses)) {
727 727
             return $args;
728 728
         }
729 729
 
730 730
         //setup the lessons quizzes  to limit the grading totals to
731 731
         $quiz_scope = array();
732
-        foreach( $courses as $course ){
732
+        foreach ($courses as $course) {
733 733
 
734
-            $course_lessons = Sensei()->course->course_lessons( $course->ID );
734
+            $course_lessons = Sensei()->course->course_lessons($course->ID);
735 735
 
736
-            if( ! empty( $course_lessons ) && is_array( $course_lessons  ) ){
736
+            if ( ! empty($course_lessons) && is_array($course_lessons)) {
737 737
 
738
-                foreach(  $course_lessons as $lesson ){
738
+                foreach ($course_lessons as $lesson) {
739 739
 
740
-                    $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID );
741
-                    if( !empty( $quiz_id ) ) {
740
+                    $quiz_id = Sensei()->lesson->lesson_quizzes($lesson->ID);
741
+                    if ( ! empty($quiz_id)) {
742 742
 
743
-                        array_push( $quiz_scope, $quiz_id );
743
+                        array_push($quiz_scope, $quiz_id);
744 744
 
745 745
                     }
746 746
 
@@ -763,41 +763,41 @@  discard block
 block discarded – undo
763 763
      * @param WP_Query $query
764 764
      * @return WP_Query $query
765 765
      */
766
-    public function add_courses_to_author_archive( $query ) {
766
+    public function add_courses_to_author_archive($query) {
767 767
 
768
-        if ( is_admin() || ! $query->is_author() ){
768
+        if (is_admin() || ! $query->is_author()) {
769 769
             return $query;
770 770
         }
771 771
 
772 772
         // this should only apply to users with the teacher role
773
-        $current_page_user = get_user_by('login', $query->get('author_name') );
774
-        if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) )     {
773
+        $current_page_user = get_user_by('login', $query->get('author_name'));
774
+        if ( ! $current_page_user || ! in_array('teacher', $current_page_user->roles)) {
775 775
 
776 776
             return $query;
777 777
 
778 778
         }
779 779
 
780 780
         // Change post types depending on what is set already
781
-        $current_post_types = $query->get( 'post_type' );
782
-        if( empty( $current_post_types  ) ){
781
+        $current_post_types = $query->get('post_type');
782
+        if (empty($current_post_types)) {
783 783
 
784 784
             // if empty it means post by default, so add post so that it also includes that for now
785
-            $new_post_types = array( 'post', 'course' );
785
+            $new_post_types = array('post', 'course');
786 786
 
787
-        } elseif( is_array( $current_post_types  ) ) {
787
+        } elseif (is_array($current_post_types)) {
788 788
 
789 789
             // merge the post types instead of overwriting it
790
-            $new_post_types = array_merge( $current_post_types, array( 'course' ) );
790
+            $new_post_types = array_merge($current_post_types, array('course'));
791 791
 
792
-        }else{
792
+        } else {
793 793
 
794 794
             // in this instance it is probably just one post type in string format
795
-            $new_post_types =  array( $current_post_types , 'course');
795
+            $new_post_types = array($current_post_types, 'course');
796 796
 
797 797
         }
798 798
 
799 799
         // change the query before returning it
800
-        $query->set('post_type', $new_post_types );
800
+        $query->set('post_type', $new_post_types);
801 801
 
802 802
         /**
803 803
          * Change the query on the teacher author archive template
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
          * @since 1.8.4
806 806
          * @param WP_Query $query
807 807
          */
808
-        return apply_filters( 'sensei_teacher_archive_query', $query );
808
+        return apply_filters('sensei_teacher_archive_query', $query);
809 809
 
810 810
     }
811 811
 
@@ -818,21 +818,21 @@  discard block
 block discarded – undo
818 818
      * @param $course_id
819 819
      * @return bool
820 820
      */
821
-    public function teacher_course_assigned_notification( $teacher_id, $course_id ){
821
+    public function teacher_course_assigned_notification($teacher_id, $course_id) {
822 822
 
823
-        if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){
823
+        if ('course' != get_post_type($course_id) || ! get_userdata($teacher_id)) {
824 824
             return false;
825 825
         }
826 826
 
827 827
         // if new user is the same as the current logged user, they don't need an email
828
-        if( $teacher_id == get_current_user_id() ){
828
+        if ($teacher_id == get_current_user_id()) {
829 829
             return true;
830 830
         }
831 831
 
832 832
         // load the email class
833 833
         include('emails/class-woothemes-sensei-teacher-new-course-assignment.php');
834 834
         $email = new Teacher_New_Course_Assignment();
835
-        $email->trigger( $teacher_id, $course_id );
835
+        $email->trigger($teacher_id, $course_id);
836 836
 
837 837
         return true;
838 838
     } // end  teacher_course_assigned_notification
@@ -846,12 +846,12 @@  discard block
 block discarded – undo
846 846
      * @param int $course_id
847 847
      * @return bool
848 848
      */
849
-    public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){
849
+    public function notify_admin_teacher_course_creation($new_status, $old_status, $post) {
850 850
 
851 851
         $course_id = $post->ID;
852 852
 
853
-        if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id )
854
-            || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) {
853
+        if ('course' != get_post_type($course_id) || 'auto-draft' == get_post_status($course_id)
854
+            || 'trash' == get_post_status($course_id) || 'draft' == get_post_status($course_id)) {
855 855
 
856 856
             return false;
857 857
 
@@ -865,19 +865,19 @@  discard block
 block discarded – undo
865 865
          *
866 866
          * @param bool $on default true
867 867
          */
868
-        if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){
868
+        if ( ! apply_filters('sensei_notify_admin_new_course_creation', true)) {
869 869
             return false;
870 870
         }
871 871
 
872 872
         // setting up the data needed by the email template
873 873
         global $sensei_email_data;
874 874
         $template = 'admin-teacher-new-course-created';
875
-        $course = get_post( $course_id );
876
-        $teacher = new WP_User( $course->post_author );
875
+        $course = get_post($course_id);
876
+        $teacher = new WP_User($course->post_author);
877 877
         $recipient = get_option('admin_email', true);
878 878
 
879 879
         // don't send if the course is created by admin
880
-        if( $recipient == $teacher->user_email ){
880
+        if ($recipient == $teacher->user_email) {
881 881
             return;
882 882
         }
883 883
 
@@ -887,7 +887,7 @@  discard block
 block discarded – undo
887 887
          * @since 1.8.0
888 888
          * @param string $template
889 889
          */
890
-        $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template );
890
+        $heading = apply_filters('sensei_email_heading', __('New course created.', 'woothemes-sensei'), $template);
891 891
 
892 892
         /**
893 893
          * Filter the email subject for the the
@@ -898,11 +898,11 @@  discard block
 block discarded – undo
898 898
          * @param string $template
899 899
          */
900 900
         $subject = apply_filters('sensei_email_subject',
901
-                                '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name ,
902
-                                $template );
901
+                                '['.get_bloginfo('name', 'display').'] '.__('New course created by', 'woothemes-sensei').' '.$teacher->display_name,
902
+                                $template);
903 903
 
904 904
         //course edit link
905
-        $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' );
905
+        $course_edit_link = admin_url('post.php?post='.$course_id.'&action=edit');
906 906
 
907 907
         // Construct data array
908 908
         $email_data = array(
@@ -921,10 +921,10 @@  discard block
 block discarded – undo
921 921
          * @param array $email_data
922 922
          * @param string $template
923 923
          */
924
-        $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template );
924
+        $sensei_email_data = apply_filters('sensei_email_data', $email_data, $template);
925 925
 
926 926
         // Send mail
927
-        Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) );
927
+        Sensei()->emails->send($recipient, $subject, Sensei()->emails->get_content($template));
928 928
 
929 929
     }// end notify admin of course creation
930 930
 
@@ -935,10 +935,10 @@  discard block
 block discarded – undo
935 935
      * @param array $args WP_User_Query arguments
936 936
      * @return array $learners_query_results
937 937
      */
938
-    public function limit_analysis_learners( $args ){
938
+    public function limit_analysis_learners($args) {
939 939
 
940 940
         // show default for none teachers
941
-        if( ! Sensei()->teacher->is_admin_teacher() ) {
941
+        if ( ! Sensei()->teacher->is_admin_teacher()) {
942 942
                 return $args;
943 943
         }
944 944
 
@@ -947,31 +947,31 @@  discard block
 block discarded – undo
947 947
         $teacher_courses = Sensei()->course->get_all_courses();
948 948
 
949 949
         // if the user has no courses they should see no users
950
-        if( empty( $teacher_courses ) ||  ! is_array( $teacher_courses ) ){
950
+        if (empty($teacher_courses) || ! is_array($teacher_courses)) {
951 951
             // tell the query to return 0 students
952
-            $args[ 'include'] = array( 0 );
952
+            $args['include'] = array(0);
953 953
             return $args;
954 954
 
955 955
         }
956 956
 
957 957
         $learner_ids_for_teacher_courses = array();
958
-        foreach( $teacher_courses as $course ){
958
+        foreach ($teacher_courses as $course) {
959 959
 
960 960
             $course_learner_ids = array();
961
-            $activity_comments =  WooThemes_Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true );
961
+            $activity_comments = WooThemes_Sensei_Utils::sensei_check_for_activity(array('post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id'), true);
962 962
 
963
-            if( empty( $activity_comments ) ||  ( is_array( $activity_comments  ) && ! ( count( $activity_comments ) > 0 ) ) ){
963
+            if (empty($activity_comments) || (is_array($activity_comments) && ! (count($activity_comments) > 0))) {
964 964
                 continue; // skip to the next course as there are no users on this course
965 965
             }
966 966
 
967 967
             // it could be an array of comments or a single comment
968
-            if( is_array( $activity_comments ) ){
968
+            if (is_array($activity_comments)) {
969 969
 
970
-                foreach( $activity_comments as $comment ){
970
+                foreach ($activity_comments as $comment) {
971 971
 
972
-                    $user = get_userdata( $comment->user_id );
972
+                    $user = get_userdata($comment->user_id);
973 973
 
974
-                    if( empty( $user ) ){
974
+                    if (empty($user)) {
975 975
                         // next comment in this array
976 976
                         continue;
977 977
                     }
@@ -979,26 +979,26 @@  discard block
 block discarded – undo
979 979
                     $course_learner_ids[] = $user->ID;
980 980
                 }
981 981
 
982
-            }else{
982
+            } else {
983 983
 
984
-                $user = get_userdata( $activity_comments->user_id );
984
+                $user = get_userdata($activity_comments->user_id);
985 985
                 $course_learner_ids[] = $user->ID;
986 986
 
987 987
             }
988 988
 
989 989
             // add learners on this course to the all courses learner list
990
-            $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids );
990
+            $learner_ids_for_teacher_courses = array_merge($learner_ids_for_teacher_courses, $course_learner_ids);
991 991
 
992 992
         }
993 993
 
994 994
         // if there are no students taking the courses by this teacher don't show them any of the other users
995
-        if( empty( $learner_ids_for_teacher_courses ) ){
995
+        if (empty($learner_ids_for_teacher_courses)) {
996 996
 
997
-            $args[ 'include'] = array( 0 );
997
+            $args['include'] = array(0);
998 998
 
999
-        }else{
999
+        } else {
1000 1000
 
1001
-            $args[ 'include'] = $learner_ids_for_teacher_courses;
1001
+            $args['include'] = $learner_ids_for_teacher_courses;
1002 1002
 
1003 1003
         }
1004 1004
 
@@ -1015,35 +1015,35 @@  discard block
 block discarded – undo
1015 1015
      * @param $questions
1016 1016
      * @return mixed
1017 1017
      */
1018
-    public function allow_teacher_access_to_questions( $questions, $quiz_id ){
1018
+    public function allow_teacher_access_to_questions($questions, $quiz_id) {
1019 1019
 
1020
-        if( ! $this->is_admin_teacher() ){
1020
+        if ( ! $this->is_admin_teacher()) {
1021 1021
             return $questions;
1022 1022
         }
1023 1023
 
1024 1024
         $screen = get_current_screen();
1025 1025
 
1026 1026
         // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions
1027
-        remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 );
1027
+        remove_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20);
1028 1028
 
1029
-        if( ! empty( $screen ) && 'lesson'== $screen->post_type ){
1029
+        if ( ! empty($screen) && 'lesson' == $screen->post_type) {
1030 1030
 
1031 1031
             $admin_user = get_user_by('email', get_bloginfo('admin_email'));
1032
-            if( ! empty($admin_user) ){
1032
+            if ( ! empty($admin_user)) {
1033 1033
 
1034 1034
                 $current_teacher_id = get_current_user_id();
1035 1035
 
1036 1036
                 // set current user to admin so teacher can view all questions
1037
-                wp_set_current_user( $admin_user->ID  );
1038
-                $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id  );
1037
+                wp_set_current_user($admin_user->ID);
1038
+                $questions = Sensei()->lesson->lesson_quiz_questions($quiz_id);
1039 1039
 
1040 1040
                 // set the teacher as the current use again
1041
-                wp_set_current_user( $current_teacher_id );
1041
+                wp_set_current_user($current_teacher_id);
1042 1042
             }
1043 1043
 
1044 1044
         }
1045 1045
         // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions
1046
-        add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 );
1046
+        add_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20, 2);
1047 1047
 
1048 1048
         return $questions;
1049 1049
     }
@@ -1055,30 +1055,30 @@  discard block
 block discarded – undo
1055 1055
      * @param $wp_query
1056 1056
      * @return mixed
1057 1057
      */
1058
-    public function give_access_to_all_questions( $wp_query ){
1058
+    public function give_access_to_all_questions($wp_query) {
1059 1059
 
1060
-        if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){
1060
+        if ( ! $this->is_admin_teacher() || ! function_exists('get_current_screen') || 'question' != $wp_query->get('post_type')) {
1061 1061
 
1062 1062
             return $wp_query;
1063 1063
         }
1064 1064
 
1065 1065
         $screen = get_current_screen();
1066
-        if( ( isset($screen->id) && 'lesson' == $screen->id )
1067
-            || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){
1066
+        if ((isset($screen->id) && 'lesson' == $screen->id)
1067
+            || (defined('DOING_AJAX') && DOING_AJAX)) {
1068 1068
 
1069 1069
             $admin_user = get_user_by('email', get_bloginfo('admin_email'));
1070
-            if( ! empty($admin_user) ){
1070
+            if ( ! empty($admin_user)) {
1071 1071
 
1072 1072
                 $current_teacher_id = get_current_user_id();
1073 1073
 
1074 1074
                 // set current user to admin so teacher can view all questions
1075
-                wp_set_current_user( $admin_user->ID  );
1075
+                wp_set_current_user($admin_user->ID);
1076 1076
 
1077 1077
                 //run new query as admin
1078
-                $wp_query = new WP_Query( $wp_query->query );
1078
+                $wp_query = new WP_Query($wp_query->query);
1079 1079
 
1080 1080
                 //set the teache as current use again
1081
-                wp_set_current_user( $current_teacher_id );
1081
+                wp_set_current_user($current_teacher_id);
1082 1082
 
1083 1083
             }
1084 1084
         }
@@ -1095,7 +1095,7 @@  discard block
 block discarded – undo
1095 1095
      */
1096 1096
     public function course_column_heading($columns) {
1097 1097
 
1098
-        if( $this->is_admin_teacher() ){
1098
+        if ($this->is_admin_teacher()) {
1099 1099
             return $columns;
1100 1100
         }
1101 1101
         $new_columns = array(
@@ -1112,20 +1112,20 @@  discard block
 block discarded – undo
1112 1112
      * @param $column
1113 1113
      * @param $course_id
1114 1114
      */
1115
-    public function course_column_data( $column, $course_id  ){
1115
+    public function course_column_data($column, $course_id) {
1116 1116
 
1117
-        if( $this->is_admin_teacher() || 'teacher' != $column  ){
1117
+        if ($this->is_admin_teacher() || 'teacher' != $column) {
1118 1118
             return;
1119 1119
         }
1120 1120
 
1121
-        $course = get_post( $course_id );
1122
-        $teacher = get_userdata( $course->post_author );
1121
+        $course = get_post($course_id);
1122
+        $teacher = get_userdata($course->post_author);
1123 1123
 
1124
-        if( !$teacher ){
1124
+        if ( ! $teacher) {
1125 1125
             return;
1126 1126
         }
1127 1127
 
1128
-        echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>';
1128
+        echo '<a href="'.get_edit_user_link($teacher->ID).'" >'.$teacher->display_name.'</a>';
1129 1129
 
1130 1130
     }// end course_column_ data
1131 1131
 
@@ -1140,31 +1140,31 @@  discard block
 block discarded – undo
1140 1140
      *
1141 1141
      * @return array $teachers_courses
1142 1142
      */
1143
-    public function get_teacher_courses( $teacher_id, $return_ids_only= false){
1143
+    public function get_teacher_courses($teacher_id, $return_ids_only = false) {
1144 1144
 
1145 1145
         $teachers_courses = array();
1146 1146
 
1147
-        if( empty( $teacher_id  ) ){
1147
+        if (empty($teacher_id)) {
1148 1148
             $teacher_id = get_current_user_id();
1149 1149
         }
1150 1150
 
1151 1151
         $all_courses = Sensei()->course->get_all_courses();
1152 1152
 
1153
-        if( empty( $all_courses ) ){
1153
+        if (empty($all_courses)) {
1154 1154
             return $all_courses;
1155 1155
         }
1156 1156
 
1157
-        foreach( $all_courses as $course ){
1157
+        foreach ($all_courses as $course) {
1158 1158
 
1159
-            if( $course->post_author != $teacher_id  ){
1159
+            if ($course->post_author != $teacher_id) {
1160 1160
                 continue;
1161 1161
             }
1162 1162
 
1163
-            if( $return_ids_only ){
1163
+            if ($return_ids_only) {
1164 1164
 
1165 1165
                 $teachers_courses[] = $course->ID;
1166 1166
 
1167
-            }else{
1167
+            } else {
1168 1168
 
1169 1169
                 $teachers_courses[] = $course;
1170 1170
 
@@ -1184,21 +1184,21 @@  discard block
 block discarded – undo
1184 1184
      * @param $query
1185 1185
      * @return mixed
1186 1186
      */
1187
-    public function limit_edit_messages_query( $query ){
1188
-        if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){
1187
+    public function limit_edit_messages_query($query) {
1188
+        if ( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type')) {
1189 1189
             return $query;
1190 1190
         }
1191 1191
 
1192 1192
         $teacher = wp_get_current_user();
1193 1193
 
1194
-        $query->set( 'meta_key', '_receiver' );
1194
+        $query->set('meta_key', '_receiver');
1195 1195
         $meta_query_args = array(
1196 1196
             'key'     => '_receiver',
1197
-            'value'   => $teacher->get('user_login') ,
1197
+            'value'   => $teacher->get('user_login'),
1198 1198
             'compare' => '='
1199 1199
         );
1200 1200
 
1201
-        $query->set('meta_query', $meta_query_args  );
1201
+        $query->set('meta_query', $meta_query_args);
1202 1202
 
1203 1203
         return $query;
1204 1204
     }
@@ -1214,7 +1214,7 @@  discard block
 block discarded – undo
1214 1214
     public function course_teacher_filter_options() {
1215 1215
         global $typenow;
1216 1216
 
1217
-        if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) {
1217
+        if ( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei')) {
1218 1218
             return;
1219 1219
         }
1220 1220
 
@@ -1224,31 +1224,31 @@  discard block
 block discarded – undo
1224 1224
         // get roles with the course edit capability
1225 1225
         // and then get the users with those roles
1226 1226
         $users_who_can_edit_courses = array();
1227
-        foreach( $roles as $role_item ){
1227
+        foreach ($roles as $role_item) {
1228 1228
 
1229
-            $role = get_role( strtolower( $role_item['name'] ) );
1229
+            $role = get_role(strtolower($role_item['name']));
1230 1230
 
1231
-            if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){
1231
+            if (is_a($role, 'WP_Role') && $role->has_cap('edit_courses')) {
1232 1232
 
1233
-                $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) );
1234
-                $role_users_who_can_edit_courses = get_users( $user_query_args );
1233
+                $user_query_args = array('role' => $role->name, 'fields' => array('ID', 'display_name'));
1234
+                $role_users_who_can_edit_courses = get_users($user_query_args);
1235 1235
 
1236 1236
                 // add user from the current $user_role to all users
1237
-                $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses );
1237
+                $users_who_can_edit_courses = array_merge($users_who_can_edit_courses, $role_users_who_can_edit_courses);
1238 1238
 
1239 1239
             }
1240 1240
 
1241 1241
         }
1242 1242
 
1243 1243
         // Create the select element with the given users who can edit course
1244
-        $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1244
+        $selected = isset($_GET['course_teacher']) ? $_GET['course_teacher'] : '';
1245 1245
         $course_options = '';
1246
-        foreach( $users_who_can_edit_courses as $user ) {
1247
-            $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' .  $user->display_name . '</option>';
1246
+        foreach ($users_who_can_edit_courses as $user) {
1247
+            $course_options .= '<option value="'.esc_attr($user->ID).'" '.selected($selected, $user->ID, false).'>'.$user->display_name.'</option>';
1248 1248
         }
1249 1249
 
1250 1250
         $output = '<select name="course_teacher" id="dropdown_course_teachers">';
1251
-        $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>';
1251
+        $output .= '<option value="">'.__('Show all teachers', 'woothemes-sensei').'</option>';
1252 1252
         $output .= $course_options;
1253 1253
         $output .= '</select>';
1254 1254
 
@@ -1263,15 +1263,15 @@  discard block
 block discarded – undo
1263 1263
      * @param $query
1264 1264
      * @return $query
1265 1265
      */
1266
-    public function teacher_filter_query_modify( $query ){
1266
+    public function teacher_filter_query_modify($query) {
1267 1267
         global $typenow;
1268 1268
 
1269
-        if( ! is_admin() && 'course' != $typenow  || ! current_user_can('manage_sensei')  ) {
1269
+        if ( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei')) {
1270 1270
             return $query;
1271 1271
         }
1272
-        $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1272
+        $course_teacher = isset($_GET['course_teacher']) ? $_GET['course_teacher'] : '';
1273 1273
 
1274
-        if( empty( $course_teacher ) ) {
1274
+        if (empty($course_teacher)) {
1275 1275
             return $query;
1276 1276
         }
1277 1277
 
@@ -1284,23 +1284,23 @@  discard block
 block discarded – undo
1284 1284
      * @param  array $request Default request arguments
1285 1285
      * @return array          Modified request arguments
1286 1286
      */
1287
-    public function restrict_media_library( $request = array() ) {
1287
+    public function restrict_media_library($request = array()) {
1288 1288
 
1289
-        if( ! is_admin() ) {
1289
+        if ( ! is_admin()) {
1290 1290
             return $request;
1291 1291
         }
1292 1292
 
1293
-        if( ! $this->is_admin_teacher() ) {
1293
+        if ( ! $this->is_admin_teacher()) {
1294 1294
             return $request;
1295 1295
         }
1296 1296
 
1297 1297
         $screen = get_current_screen();
1298 1298
 
1299
-        if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) {
1300
-            $teacher = intval( get_current_user_id() );
1299
+        if (in_array($screen->id, array('upload', 'course', 'lesson', 'question'))) {
1300
+            $teacher = intval(get_current_user_id());
1301 1301
 
1302
-            if( $teacher ) {
1303
-                $request['author__in'] = array( $teacher );
1302
+            if ($teacher) {
1303
+                $request['author__in'] = array($teacher);
1304 1304
             }
1305 1305
         }
1306 1306
 
@@ -1312,20 +1312,20 @@  discard block
 block discarded – undo
1312 1312
      * @param  array $query Default query arguments
1313 1313
      * @return array        Modified query arguments
1314 1314
      */
1315
-    public function restrict_media_library_modal( $query = array() ) {
1315
+    public function restrict_media_library_modal($query = array()) {
1316 1316
 
1317
-        if( ! is_admin() ) {
1317
+        if ( ! is_admin()) {
1318 1318
             return $query;
1319 1319
         }
1320 1320
 
1321
-        if( ! $this->is_admin_teacher() ) {
1321
+        if ( ! $this->is_admin_teacher()) {
1322 1322
             return $query;
1323 1323
         }
1324 1324
 
1325
-        $teacher = intval( get_current_user_id() );
1325
+        $teacher = intval(get_current_user_id());
1326 1326
 
1327
-        if( $teacher ) {
1328
-            $query['author__in'] = array( $teacher );
1327
+        if ($teacher) {
1328
+            $query['author__in'] = array($teacher);
1329 1329
         }
1330 1330
 
1331 1331
         return $query;
@@ -1338,28 +1338,28 @@  discard block
 block discarded – undo
1338 1338
      *
1339 1339
      * @param int $lesson_id
1340 1340
      */
1341
-    public function update_lesson_teacher( $lesson_id ){
1341
+    public function update_lesson_teacher($lesson_id) {
1342 1342
 
1343
-        if( 'lesson'!= get_post_type() ){
1343
+        if ('lesson' != get_post_type()) {
1344 1344
             return;
1345 1345
         }
1346 1346
 
1347 1347
         // this should only run once per request cycle
1348
-        remove_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
1348
+        remove_action('save_post', array($this, 'update_lesson_teacher'));
1349 1349
 
1350
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
1350
+        $course_id = Sensei()->lesson->get_course_id($lesson_id);
1351 1351
 
1352
-        if(  empty( $course_id ) || ! $course_id ){
1352
+        if (empty($course_id) || ! $course_id) {
1353 1353
             return;
1354 1354
         }
1355 1355
 
1356
-        $course = get_post( $course_id );
1356
+        $course = get_post($course_id);
1357 1357
 
1358
-        $lesson_update_args= array(
1359
-            'ID' => $lesson_id ,
1358
+        $lesson_update_args = array(
1359
+            'ID' => $lesson_id,
1360 1360
             'post_author' => $course->post_author
1361 1361
         );
1362
-        wp_update_post( $lesson_update_args );
1362
+        wp_update_post($lesson_update_args);
1363 1363
 
1364 1364
     } // end update_lesson_teacher
1365 1365
 
@@ -1373,21 +1373,21 @@  discard block
 block discarded – undo
1373 1373
      * @parameters array $wp_query
1374 1374
      * @return WP_Query $wp_query
1375 1375
      */
1376
-    public function limit_teacher_edit_screen_post_types( $wp_query ) {
1376
+    public function limit_teacher_edit_screen_post_types($wp_query) {
1377 1377
         global $current_user;
1378 1378
 
1379 1379
         //exit early
1380
-        if( ! $this->is_admin_teacher() ){
1380
+        if ( ! $this->is_admin_teacher()) {
1381 1381
             return $wp_query;
1382 1382
         }
1383 1383
 
1384
-        if ( ! function_exists( 'get_current_screen' ) ) {
1384
+        if ( ! function_exists('get_current_screen')) {
1385 1385
             return $wp_query;
1386 1386
         }
1387 1387
 
1388 1388
         $screen = get_current_screen();
1389 1389
 
1390
-        if( empty( $screen ) ){
1390
+        if (empty($screen)) {
1391 1391
             return $wp_query;
1392 1392
         }
1393 1393
 
@@ -1400,10 +1400,10 @@  discard block
 block discarded – undo
1400 1400
             'lesson_page_lesson-order',
1401 1401
         );
1402 1402
 
1403
-        if(  in_array($screen->id  , $limit_screens ) ) {
1403
+        if (in_array($screen->id, $limit_screens)) {
1404 1404
 
1405 1405
             // set the query author to the current user to only show those those posts
1406
-            $wp_query->set( 'author', $current_user->ID );
1406
+            $wp_query->set('author', $current_user->ID);
1407 1407
         }
1408 1408
 
1409 1409
         return $wp_query;
@@ -1423,7 +1423,7 @@  discard block
 block discarded – undo
1423 1423
      * @return void
1424 1424
      */
1425 1425
 
1426
-    public function teacher_login_redirect( $user_login, $user  ) {
1426
+    public function teacher_login_redirect($user_login, $user) {
1427 1427
 
1428 1428
         if (user_can($user, 'edit_courses')) {
1429 1429
 
@@ -1473,9 +1473,9 @@  discard block
 block discarded – undo
1473 1473
          * @param bool $restrict default true
1474 1474
          */
1475 1475
 
1476
-        $restrict = apply_filters('sensei_restrict_posts_menu_page', true );
1476
+        $restrict = apply_filters('sensei_restrict_posts_menu_page', true);
1477 1477
 
1478
-        if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) {
1478
+        if (in_array('teacher', (array) $user->roles) && ! current_user_can('delete_posts') && $restrict) {
1479 1479
 
1480 1480
             remove_menu_page('edit.php');
1481 1481
 
@@ -1509,7 +1509,7 @@  discard block
 block discarded – undo
1509 1509
 
1510 1510
         global $pagenow;
1511 1511
 
1512
-        if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") {
1512
+        if (self::is_a_teacher(get_current_user_id()) && $pagenow == "edit-comments.php") {
1513 1513
 
1514 1514
             $clauses->query_vars['post_author'] = get_current_user_id();
1515 1515
 
@@ -1526,15 +1526,15 @@  discard block
 block discarded – undo
1526 1526
      *
1527 1527
      * @return bool
1528 1528
      */
1529
-    public static function is_a_teacher( $user_id ){
1529
+    public static function is_a_teacher($user_id) {
1530 1530
 
1531 1531
         $user = get_user_by('id', $user_id);
1532 1532
 
1533
-        if( isset( $user->roles ) && in_array(  'teacher',  $user->roles )   ){
1533
+        if (isset($user->roles) && in_array('teacher', $user->roles)) {
1534 1534
 
1535 1535
             return true;
1536 1536
 
1537
-        }else{
1537
+        } else {
1538 1538
 
1539 1539
             return false;
1540 1540
 
@@ -1547,14 +1547,14 @@  discard block
 block discarded – undo
1547 1547
      *
1548 1548
      * @since 1.9.0
1549 1549
      */
1550
-    public static function archive_title(){
1550
+    public static function archive_title() {
1551 1551
 
1552
-        $author = get_user_by( 'id', get_query_var( 'author' ) );
1552
+        $author = get_user_by('id', get_query_var('author'));
1553 1553
         $author_name = $author->display_name;
1554 1554
         ?>
1555 1555
             <h2 class="teacher-archive-title">
1556 1556
 
1557
-                <?php echo sprintf( __( 'All courses by %s', 'woothemes-sensei') , $author_name ); ?>
1557
+                <?php echo sprintf(__('All courses by %s', 'woothemes-sensei'), $author_name); ?>
1558 1558
 
1559 1559
             </h2>
1560 1560
         <?php
@@ -1566,9 +1566,9 @@  discard block
 block discarded – undo
1566 1566
      *
1567 1567
      * @since 1.9.0
1568 1568
      */
1569
-    public static function remove_course_meta_on_teacher_archive(){
1569
+    public static function remove_course_meta_on_teacher_archive() {
1570 1570
 
1571
-        remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) );
1571
+        remove_action('sensei_course_content_inside_before', array(Sensei()->course, 'the_course_meta'));
1572 1572
 
1573 1573
     }
1574 1574
 
Please login to merge, or discard this patch.
Braces   +11 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Teacher class
@@ -414,7 +417,7 @@  discard block
 block discarded – undo
414 417
                     $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module');
415 418
                     $term_id = $existing_term->term_id;
416 419
 
417
-                }else{
420
+                } else{
418 421
 
419 422
                     // for a new term simply get the term from the returned value
420 423
                     $term_id = $new_term['term_id'];
@@ -495,7 +498,7 @@  discard block
 block discarded – undo
495 498
                         'post_author' =>  $new_author
496 499
                     ) );
497 500
                 }
498
-            }else{
501
+            } else{
499 502
                 wp_update_post( array(
500 503
                     'ID'           => $lesson_quizzes,
501 504
                     'post_author' =>  $new_author
@@ -789,7 +792,7 @@  discard block
 block discarded – undo
789 792
             // merge the post types instead of overwriting it
790 793
             $new_post_types = array_merge( $current_post_types, array( 'course' ) );
791 794
 
792
-        }else{
795
+        } else{
793 796
 
794 797
             // in this instance it is probably just one post type in string format
795 798
             $new_post_types =  array( $current_post_types , 'course');
@@ -979,7 +982,7 @@  discard block
 block discarded – undo
979 982
                     $course_learner_ids[] = $user->ID;
980 983
                 }
981 984
 
982
-            }else{
985
+            } else{
983 986
 
984 987
                 $user = get_userdata( $activity_comments->user_id );
985 988
                 $course_learner_ids[] = $user->ID;
@@ -996,7 +999,7 @@  discard block
 block discarded – undo
996 999
 
997 1000
             $args[ 'include'] = array( 0 );
998 1001
 
999
-        }else{
1002
+        } else{
1000 1003
 
1001 1004
             $args[ 'include'] = $learner_ids_for_teacher_courses;
1002 1005
 
@@ -1164,7 +1167,7 @@  discard block
 block discarded – undo
1164 1167
 
1165 1168
                 $teachers_courses[] = $course->ID;
1166 1169
 
1167
-            }else{
1170
+            } else{
1168 1171
 
1169 1172
                 $teachers_courses[] = $course;
1170 1173
 
@@ -1534,7 +1537,7 @@  discard block
 block discarded – undo
1534 1537
 
1535 1538
             return true;
1536 1539
 
1537
-        }else{
1540
+        } else{
1538 1541
 
1539 1542
             return false;
1540 1543
 
Please login to merge, or discard this patch.
includes/class-sensei-updates.php 4 patches
Doc Comments   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
 	 *
456 456
 	 * @since  1.1.0
457 457
 	 * @access public
458
-	 * @return void
458
+	 * @return boolean
459 459
 	 */
460 460
 	public function assign_role_caps() {
461 461
 		foreach ( $this->parent->post_types->role_caps as $role_cap_set  ) {
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 	 *
481 481
 	 * @since 1.3.0
482 482
 	 * @access public
483
-	 * @return void
483
+	 * @return boolean
484 484
 	 */
485 485
 	public function set_default_quiz_grade_type() {
486 486
 		$args = array(	'post_type' 		=> 'quiz',
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 	 *
503 503
 	 * @since 1.3.0
504 504
 	 * @access public
505
-	 * @return void
505
+	 * @return boolean
506 506
 	 */
507 507
 	public function set_default_question_type() {
508 508
 		$args = array(	'post_type' 		=> 'question',
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
 	 *
533 533
 	 * @since 1.3.0
534 534
 	 * @access public
535
-	 * @return void
535
+	 * @return boolean
536 536
 	 */
537 537
 	public function update_question_answer_data( $n = 50, $offset = 0 ) {
538 538
 
@@ -1429,8 +1429,8 @@  discard block
 block discarded – undo
1429 1429
 	 *
1430 1430
 	 * @global type $woothemes_sensei
1431 1431
 	 * @global type $wpdb
1432
-	 * @param type $n
1433
-	 * @param type $offset
1432
+	 * @param integer $n
1433
+	 * @param integer $offset
1434 1434
 	 * @return boolean
1435 1435
 	 */
1436 1436
 	function status_changes_repair_course_statuses( $n = 50, $offset = 0 ) {
@@ -1674,8 +1674,8 @@  discard block
 block discarded – undo
1674 1674
 	 * Update the comment counts for all Courses and Lessons now that sensei comments will no longer be counted.
1675 1675
 	 *
1676 1676
 	 * @global type $wpdb
1677
-	 * @param type $n
1678
-	 * @param type $offset
1677
+	 * @param integer $n
1678
+	 * @param integer $offset
1679 1679
 	 * @return boolean
1680 1680
 	 */
1681 1681
 	public function update_comment_course_lesson_comment_counts( $n = 50, $offset = 0 ) {
Please login to merge, or discard this patch.
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -70,9 +70,9 @@  discard block
 block discarded – undo
70 70
 								'1.7.2' => array( 	'auto' 		=> array( 'index_comment_status_field' => array( 'title' => __( 'Add database index to comment statuses', 'woothemes-sensei' ), 'desc' => __( 'This indexes the comment statuses in the database, which will speed up all Sensei activity queries.', 'woothemes-sensei' ) ), ),
71 71
 													/*'manual' 		=> array( 'remove_legacy_comments' => array( 'title' => __( 'Remove legacy Sensei activity types', 'woothemes-sensei' ), 'desc' => __( 'This removes all legacy (pre-1.7) Sensei activity types - only run this update once the update to v1.7 is complete and everything is stable.', 'woothemes-sensei' ) ) )*/
72 72
 												),
73
-                                '1.8.0' => array(   'auto' => array( 'enhance_teacher_role' => array( 'title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.' ), ),
74
-                            						'manual' 	=> array()
75
-                    							),
73
+								'1.8.0' => array(   'auto' => array( 'enhance_teacher_role' => array( 'title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.' ), ),
74
+													'manual' 	=> array()
75
+												),
76 76
 							);
77 77
 
78 78
 		$this->updates = apply_filters( 'sensei_upgrade_functions', $this->updates, $this->updates );
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 				} // End For Loop
330 330
 			} // End For Loop
331 331
 
332
-            $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update
332
+			$this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update
333 333
 			update_option( $this->token . '-upgrades', $this->updates_run );
334 334
 			return true;
335 335
 
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 	 */
447 447
 	private function set_update_run( $update ) {
448 448
 		array_push( $this->updates_run, $update );
449
-        $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update
449
+		$this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update
450 450
 		update_option( $this->token . '-upgrades', $this->updates_run );
451 451
 	}
452 452
 
@@ -918,11 +918,11 @@  discard block
 block discarded – undo
918 918
 				update_post_meta( $lesson->ID, '_order_' . $course_id, 0 );
919 919
 			}
920 920
 
921
-            $module = Sensei()->modules->get_lesson_module( $lesson->ID );
921
+			$module = Sensei()->modules->get_lesson_module( $lesson->ID );
922 922
 
923
-            if( $module ) {
924
-                update_post_meta( $lesson->ID, '_order_module_' . $module->term_id, 0 );
925
-            }
923
+			if( $module ) {
924
+				update_post_meta( $lesson->ID, '_order_module_' . $module->term_id, 0 );
925
+			}
926 926
 
927 927
 		}
928 928
 
@@ -1732,22 +1732,22 @@  discard block
 block discarded – undo
1732 1732
 
1733 1733
 	}
1734 1734
 
1735
-     /**
1736
-     * WooThemes_Sensei_Updates::enhance_teacher_role
1737
-     *
1738
-     * This runs the update to create the teacher role
1739
-     * @access public
1740
-     * @since 1.8.0
1741
-     * @return bool;
1742
-     */
1743
-    public  function enhance_teacher_role ( ) {
1744
-
1745
-        require_once('class-sensei-teacher.php');
1746
-        $teacher = new Sensei_Teacher();
1747
-        $teacher->create_role();
1748
-        return true;
1749
-
1750
-    }// end enhance_teacher_role
1735
+	 /**
1736
+	  * WooThemes_Sensei_Updates::enhance_teacher_role
1737
+	  *
1738
+	  * This runs the update to create the teacher role
1739
+	  * @access public
1740
+	  * @since 1.8.0
1741
+	  * @return bool;
1742
+	  */
1743
+	public  function enhance_teacher_role ( ) {
1744
+
1745
+		require_once('class-sensei-teacher.php');
1746
+		$teacher = new Sensei_Teacher();
1747
+		$teacher->create_role();
1748
+		return true;
1749
+
1750
+	}// end enhance_teacher_role
1751 1751
 
1752 1752
 } // End Class
1753 1753
 
Please login to merge, or discard this patch.
Spacing   +481 added lines, -481 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Updates Class
@@ -27,59 +27,59 @@  discard block
 block discarded – undo
27 27
 	 * @param   string $parent The main Sensei object by Ref.
28 28
 	 * @return  void
29 29
 	 */
30
-	public function __construct ( $parent ) {
30
+	public function __construct($parent) {
31 31
 
32 32
 		// Setup object data
33 33
 		$this->parent = $parent;
34
-		$this->updates_run = get_option( $this->token . '-upgrades', array() );
34
+		$this->updates_run = get_option($this->token.'-upgrades', array());
35 35
 
36 36
 		// The list of upgrades to run
37
-		$this->updates = array( '1.1.0' => array( 	'auto' 		=> array( 'assign_role_caps' => array( 'title' => __( 'Assign role capabilities', 'woothemes-sensei' ), 'desc' => __( 'Assigns Sensei capabilites to the relevant user roles.', 'woothemes-sensei' ), 'product' => 'Sensei' ) ),
37
+		$this->updates = array('1.1.0' => array('auto' 		=> array('assign_role_caps' => array('title' => __('Assign role capabilities', 'woothemes-sensei'), 'desc' => __('Assigns Sensei capabilites to the relevant user roles.', 'woothemes-sensei'), 'product' => 'Sensei')),
38 38
 													'manual' 	=> array()
39 39
 												),
40
-								'1.3.0' => array( 	'auto' 		=> array( 'set_default_quiz_grade_type' => array( 'title' => __( 'Set default quiz grade type', 'woothemes-sensei' ), 'desc' => __( 'Sets all quizzes to the default \'auto\' grade type.', 'woothemes-sensei' ) ),
41
-																		  'set_default_question_type' => array( 'title' => __( 'Set default question type', 'woothemes-sensei' ), 'desc' => __( 'Sets all questions to the default \'multiple choice\' type.', 'woothemes-sensei' ) )
40
+								'1.3.0' => array('auto' 		=> array('set_default_quiz_grade_type' => array('title' => __('Set default quiz grade type', 'woothemes-sensei'), 'desc' => __('Sets all quizzes to the default \'auto\' grade type.', 'woothemes-sensei')),
41
+																		  'set_default_question_type' => array('title' => __('Set default question type', 'woothemes-sensei'), 'desc' => __('Sets all questions to the default \'multiple choice\' type.', 'woothemes-sensei'))
42 42
 													),
43
-													'manual' 	=> array( 'update_question_answer_data' => array( 'title' => __( 'Update question answer data', 'woothemes-sensei' ), 'desc' => __( 'Updates questions to use the new question types structure.', 'woothemes-sensei' ) ) )
43
+													'manual' 	=> array('update_question_answer_data' => array('title' => __('Update question answer data', 'woothemes-sensei'), 'desc' => __('Updates questions to use the new question types structure.', 'woothemes-sensei')))
44 44
 												),
45
-								'1.4.0' => array( 	'auto' 		=> array( 'update_question_grade_points' => array( 'title' => __( 'Update question grade points', 'woothemes-sensei' ), 'desc' => __( 'Sets all question grade points to the default value of \'1\'.', 'woothemes-sensei' ) ) ),
45
+								'1.4.0' => array('auto' 		=> array('update_question_grade_points' => array('title' => __('Update question grade points', 'woothemes-sensei'), 'desc' => __('Sets all question grade points to the default value of \'1\'.', 'woothemes-sensei'))),
46 46
 													'manual' 	=> array()
47 47
 												),
48
-								'1.5.0' => array( 	'auto' 		=> array( 'convert_essay_paste_questions' => array( 'title' => __( 'Convert essay paste questions into multi-line questions', 'woothemes-sensei' ), 'desc' => __( 'Converts all essay paste questions into multi-line questions as the essay paste question type was removed in v1.5.0.', 'woothemes-sensei' ) ) ),
49
-													'manual' 	=> array( 'set_random_question_order' => array( 'title' => __( 'Set all quizzes to have a random question order', 'woothemes-sensei' ), 'desc' => __( 'Sets the order all of questions in all quizzes to a random order, which can be switched off per quiz.', 'woothemes-sensei' ) ),
50
-																		  'set_default_show_question_count' => array( 'title' => __( 'Set all quizzes to show all questions', 'woothemes-sensei' ), 'desc' => __( 'Sets all quizzes to show all questions - this can be changed per quiz.', 'woothemes-sensei' ) ),
51
-																		  'remove_deleted_user_activity' => array( 'title' => __( 'Remove Sensei activity for deleted users', 'woothemes-sensei' ), 'desc' => __( 'Removes all course, lesson &amp; quiz activity for users that have already been deleted from the database. This will fix incorrect learner counts in the Analysis section.', 'woothemes-sensei' ) ) )
48
+								'1.5.0' => array('auto' 		=> array('convert_essay_paste_questions' => array('title' => __('Convert essay paste questions into multi-line questions', 'woothemes-sensei'), 'desc' => __('Converts all essay paste questions into multi-line questions as the essay paste question type was removed in v1.5.0.', 'woothemes-sensei'))),
49
+													'manual' 	=> array('set_random_question_order' => array('title' => __('Set all quizzes to have a random question order', 'woothemes-sensei'), 'desc' => __('Sets the order all of questions in all quizzes to a random order, which can be switched off per quiz.', 'woothemes-sensei')),
50
+																		  'set_default_show_question_count' => array('title' => __('Set all quizzes to show all questions', 'woothemes-sensei'), 'desc' => __('Sets all quizzes to show all questions - this can be changed per quiz.', 'woothemes-sensei')),
51
+																		  'remove_deleted_user_activity' => array('title' => __('Remove Sensei activity for deleted users', 'woothemes-sensei'), 'desc' => __('Removes all course, lesson &amp; quiz activity for users that have already been deleted from the database. This will fix incorrect learner counts in the Analysis section.', 'woothemes-sensei')))
52 52
 												),
53
-								'1.6.0' => array( 	'auto' 		=> array( 'add_teacher_role' => array( 'title' => __( 'Add \'Teacher\' role', 'woothemes-sensei' ), 'desc' => __( 'Adds a \'Teacher\' role to your WordPress site that will allow users to mange the Grading and Analysis pages.', 'woothemes-sensei' ) ),
54
-																		  'add_sensei_caps' => array( 'title' => __( 'Add administrator capabilities', 'woothemes-sensei' ), 'desc' => __( 'Adds the \'manage_sensei\' and \'manage_sensei_grades\' capabilities to the Administrator role.', 'woothemes-sensei' ) ),
55
-																		  'restructure_question_meta' => array( 'title' => __( 'Restructure question meta data', 'woothemes-sensei' ), 'desc' => __( 'Restructures the question meta data as it relates to quizzes - this accounts for changes in the data structure in v1.6+.', 'woothemes-sensei' ) ),
56
-																		  'update_quiz_settings' => array( 'title' => __( 'Add new quiz settings', 'woothemes-sensei' ), 'desc' => __( 'Adds new settings to quizzes that were previously registered as global settings.', 'woothemes-sensei' ) ),
57
-																		  'reset_lesson_order_meta' => array( 'title' => __( 'Set default order of lessons', 'woothemes-sensei' ), 'desc' => __( 'Adds data to lessons to ensure that they show up on the \'Order Lessons\' screen - if this update has been run once before then it will reset all lessons to the default order.', 'woothemes-sensei' ) ), ),
53
+								'1.6.0' => array('auto' 		=> array('add_teacher_role' => array('title' => __('Add \'Teacher\' role', 'woothemes-sensei'), 'desc' => __('Adds a \'Teacher\' role to your WordPress site that will allow users to mange the Grading and Analysis pages.', 'woothemes-sensei')),
54
+																		  'add_sensei_caps' => array('title' => __('Add administrator capabilities', 'woothemes-sensei'), 'desc' => __('Adds the \'manage_sensei\' and \'manage_sensei_grades\' capabilities to the Administrator role.', 'woothemes-sensei')),
55
+																		  'restructure_question_meta' => array('title' => __('Restructure question meta data', 'woothemes-sensei'), 'desc' => __('Restructures the question meta data as it relates to quizzes - this accounts for changes in the data structure in v1.6+.', 'woothemes-sensei')),
56
+																		  'update_quiz_settings' => array('title' => __('Add new quiz settings', 'woothemes-sensei'), 'desc' => __('Adds new settings to quizzes that were previously registered as global settings.', 'woothemes-sensei')),
57
+																		  'reset_lesson_order_meta' => array('title' => __('Set default order of lessons', 'woothemes-sensei'), 'desc' => __('Adds data to lessons to ensure that they show up on the \'Order Lessons\' screen - if this update has been run once before then it will reset all lessons to the default order.', 'woothemes-sensei')),),
58 58
 													'manual' 	=> array()
59 59
 												),
60
-								'1.7.0' => array( 	'auto' 		=> array( 'add_editor_caps' => array( 'title' => __( 'Add Editor capabilities', 'woothemes-sensei' ), 'desc' => __( 'Adds the \'manage_sensei_grades\' capability to the Editor role.', 'woothemes-sensei' ) ), ),
61
-													'forced' 	=> array(  'update_question_gap_fill_separators' => array( 'title' => __( 'Update Gap Fill questions', 'woothemes-sensei' ), 'desc' => __( 'Updates the format of gap fill questions to allow auto grading and greater flexibility in matching.', 'woothemes-sensei' ) ),
62
-																		  'update_quiz_lesson_relationship' => array( 'title' => __( 'Restructure quiz lesson relationship', 'woothemes-sensei' ), 'desc' => __( 'Adds data to quizzes and lessons to ensure that they maintain their 1 to 1 relationship.', 'woothemes-sensei' ) ),
63
-																		  'status_changes_fix_lessons' => array( 'title' => __( 'Update lesson statuses', 'woothemes-sensei' ), 'desc' => __( 'Update existing lesson statuses.', 'woothemes-sensei' ) ),
64
-																		  'status_changes_convert_lessons' => array( 'title' => __( 'Convert lesson statuses', 'woothemes-sensei' ), 'desc' => __( 'Convert to new lesson statuses.', 'woothemes-sensei' ) ),
65
-																		  'status_changes_convert_courses' => array( 'title' => __( 'Convert course statuses', 'woothemes-sensei' ), 'desc' => __( 'Convert to new course statuses.', 'woothemes-sensei' ) ),
66
-																		  'status_changes_convert_questions' => array( 'title' => __( 'Convert question statuses', 'woothemes-sensei' ), 'desc' => __( 'Convert to new question statuses.', 'woothemes-sensei' ) ),
67
-																		  'update_legacy_sensei_comments_status' => array( 'title' => __( 'Convert legacy Sensei activity types', 'woothemes-sensei' ), 'desc' => __( 'Convert all legacy Sensei activity types such as \'sensei_lesson_start\' and \'sensei_user_answer\' to new status format.', 'woothemes-sensei' ) ),
68
-																		  'update_comment_course_lesson_comment_counts' => array( 'title' => __( 'Update comment counts', 'woothemes-sensei' ), 'desc' => __( 'Update comment counts on Courses and Lessons due to status changes.', 'woothemes-sensei' ) ), ),
60
+								'1.7.0' => array('auto' 		=> array('add_editor_caps' => array('title' => __('Add Editor capabilities', 'woothemes-sensei'), 'desc' => __('Adds the \'manage_sensei_grades\' capability to the Editor role.', 'woothemes-sensei')),),
61
+													'forced' 	=> array('update_question_gap_fill_separators' => array('title' => __('Update Gap Fill questions', 'woothemes-sensei'), 'desc' => __('Updates the format of gap fill questions to allow auto grading and greater flexibility in matching.', 'woothemes-sensei')),
62
+																		  'update_quiz_lesson_relationship' => array('title' => __('Restructure quiz lesson relationship', 'woothemes-sensei'), 'desc' => __('Adds data to quizzes and lessons to ensure that they maintain their 1 to 1 relationship.', 'woothemes-sensei')),
63
+																		  'status_changes_fix_lessons' => array('title' => __('Update lesson statuses', 'woothemes-sensei'), 'desc' => __('Update existing lesson statuses.', 'woothemes-sensei')),
64
+																		  'status_changes_convert_lessons' => array('title' => __('Convert lesson statuses', 'woothemes-sensei'), 'desc' => __('Convert to new lesson statuses.', 'woothemes-sensei')),
65
+																		  'status_changes_convert_courses' => array('title' => __('Convert course statuses', 'woothemes-sensei'), 'desc' => __('Convert to new course statuses.', 'woothemes-sensei')),
66
+																		  'status_changes_convert_questions' => array('title' => __('Convert question statuses', 'woothemes-sensei'), 'desc' => __('Convert to new question statuses.', 'woothemes-sensei')),
67
+																		  'update_legacy_sensei_comments_status' => array('title' => __('Convert legacy Sensei activity types', 'woothemes-sensei'), 'desc' => __('Convert all legacy Sensei activity types such as \'sensei_lesson_start\' and \'sensei_user_answer\' to new status format.', 'woothemes-sensei')),
68
+																		  'update_comment_course_lesson_comment_counts' => array('title' => __('Update comment counts', 'woothemes-sensei'), 'desc' => __('Update comment counts on Courses and Lessons due to status changes.', 'woothemes-sensei')),),
69 69
 												),
70
-								'1.7.2' => array( 	'auto' 		=> array( 'index_comment_status_field' => array( 'title' => __( 'Add database index to comment statuses', 'woothemes-sensei' ), 'desc' => __( 'This indexes the comment statuses in the database, which will speed up all Sensei activity queries.', 'woothemes-sensei' ) ), ),
70
+								'1.7.2' => array('auto' 		=> array('index_comment_status_field' => array('title' => __('Add database index to comment statuses', 'woothemes-sensei'), 'desc' => __('This indexes the comment statuses in the database, which will speed up all Sensei activity queries.', 'woothemes-sensei')),),
71 71
 													/*'manual' 		=> array( 'remove_legacy_comments' => array( 'title' => __( 'Remove legacy Sensei activity types', 'woothemes-sensei' ), 'desc' => __( 'This removes all legacy (pre-1.7) Sensei activity types - only run this update once the update to v1.7 is complete and everything is stable.', 'woothemes-sensei' ) ) )*/
72 72
 												),
73
-                                '1.8.0' => array(   'auto' => array( 'enhance_teacher_role' => array( 'title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.' ), ),
73
+                                '1.8.0' => array('auto' => array('enhance_teacher_role' => array('title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.'),),
74 74
                             						'manual' 	=> array()
75 75
                     							),
76 76
 							);
77 77
 
78
-		$this->updates = apply_filters( 'sensei_upgrade_functions', $this->updates, $this->updates );
79
-		$this->version = get_option( $this->token . '-version' );
78
+		$this->updates = apply_filters('sensei_upgrade_functions', $this->updates, $this->updates);
79
+		$this->version = get_option($this->token.'-version');
80 80
 
81 81
 		// Manual Update Screen
82
-		add_action('admin_menu', array( $this, 'add_update_admin_screen' ), 50 );
82
+		add_action('admin_menu', array($this, 'add_update_admin_screen'), 50);
83 83
 
84 84
 	} // End __construct()
85 85
 
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
 	 * @return void
92 92
 	 */
93 93
 	public function add_update_admin_screen() {
94
-		if ( current_user_can( 'manage_options' ) ) {
95
-			add_submenu_page( 'sensei', __( 'Sensei Updates', 'woothemes-sensei' ), __( 'Data Updates', 'woothemes-sensei' ), 'manage_options', 'sensei_updates', array( $this, 'sensei_updates_page' ) );
94
+		if (current_user_can('manage_options')) {
95
+			add_submenu_page('sensei', __('Sensei Updates', 'woothemes-sensei'), __('Data Updates', 'woothemes-sensei'), 'manage_options', 'sensei_updates', array($this, 'sensei_updates_page'));
96 96
 		}
97 97
 	} // End add_update_admin_screen()
98 98
 
@@ -106,80 +106,80 @@  discard block
 block discarded – undo
106 106
 	public function sensei_updates_page() {
107 107
 
108 108
 		// Only allow admins to load this page and run the update functions
109
-		if( current_user_can( 'manage_options' ) ) {
109
+		if (current_user_can('manage_options')) {
110 110
 			?>
111 111
 			<div class="wrap">
112 112
 
113 113
 				<div id="icon-woothemes-sensei" class="icon32"><br></div>
114
-				<h2><?php _e( 'Sensei Updates', 'woothemes-sensei' ); ?></h2>
114
+				<h2><?php _e('Sensei Updates', 'woothemes-sensei'); ?></h2>
115 115
 
116 116
 				<?php
117
-				if ( isset( $_GET['action'] ) && $_GET['action'] == 'update' && isset( $_GET['n'] ) && intval( $_GET['n'] ) >= 0 && ( ( isset( $_POST['checked'][0] ) && '' != $_POST['checked'][0] ) || ( isset( $_GET['functions'] ) && '' != $_GET['functions'] ) ) ) {
117
+				if (isset($_GET['action']) && $_GET['action'] == 'update' && isset($_GET['n']) && intval($_GET['n']) >= 0 && ((isset($_POST['checked'][0]) && '' != $_POST['checked'][0]) || (isset($_GET['functions']) && '' != $_GET['functions']))) {
118 118
 
119 119
 					// Setup the data variables
120
-					$n = intval( $_GET['n'] );
120
+					$n = intval($_GET['n']);
121 121
 					$functions_list = '';
122 122
 					$done_processing = false;
123 123
 
124 124
 					// Check for updates to run
125
-					if ( isset( $_POST['checked'][0] ) && '' != $_POST['checked'][0] ) {
125
+					if (isset($_POST['checked'][0]) && '' != $_POST['checked'][0]) {
126 126
 
127
-						foreach ( $_POST['checked'] as $key => $value ) {
127
+						foreach ($_POST['checked'] as $key => $value) {
128 128
 
129 129
 							// Dynamic function call
130
-							if ( method_exists( $this, $value) ) {
131
-								$done_processing = call_user_func_array( array( $this, $value ), array( 50, $n ) );
130
+							if (method_exists($this, $value)) {
131
+								$done_processing = call_user_func_array(array($this, $value), array(50, $n));
132 132
 							} else {
133
-								$done_processing = call_user_func_array( $value, array( 50, $n ) );
133
+								$done_processing = call_user_func_array($value, array(50, $n));
134 134
 							} // End If Statement
135 135
 
136 136
 							// Add to functions list get args
137
-							if ( '' == $functions_list ) {
137
+							if ('' == $functions_list) {
138 138
 								$functions_list .= $value;
139 139
 							} else {
140
-								$functions_list .= '+' . $value;
140
+								$functions_list .= '+'.$value;
141 141
 							} // End If Statement
142 142
 
143 143
 							// Mark update has having been run
144
-							$this->set_update_run( $value );
144
+							$this->set_update_run($value);
145 145
 
146 146
 						} // End For Loop
147 147
 
148 148
 					} // End If Statement
149 149
 
150 150
 					// Check for updates to run
151
-					if ( isset( $_GET['functions'] ) && '' != $_GET['functions'] ) {
151
+					if (isset($_GET['functions']) && '' != $_GET['functions']) {
152 152
 
153 153
 						// Existing functions from GET variables instead of POST
154 154
 						$functions_array = $_GET['functions'];
155 155
 
156
-						foreach ( $functions_array as $key => $value ) {
156
+						foreach ($functions_array as $key => $value) {
157 157
 
158 158
 							// Dynamic function call
159
-							if ( method_exists( $this, $value) ) {
160
-								$done_processing = call_user_func_array( array( $this, $value ), array( 50, $n ) );
159
+							if (method_exists($this, $value)) {
160
+								$done_processing = call_user_func_array(array($this, $value), array(50, $n));
161 161
 							} else {
162
-								$done_processing = call_user_func_array( $value, array( 50, $n ) );
162
+								$done_processing = call_user_func_array($value, array(50, $n));
163 163
 							} // End If Statement
164 164
 
165 165
 							// Add to functions list get args
166
-							if ( '' == $functions_list ) {
166
+							if ('' == $functions_list) {
167 167
 								$functions_list .= $value;
168 168
 							} else {
169
-								$functions_list .= '+' . $value;
169
+								$functions_list .= '+'.$value;
170 170
 							} // End If Statement
171 171
 
172
-							$this->set_update_run( $value );
172
+							$this->set_update_run($value);
173 173
 
174 174
 						} // End For Loop
175 175
 
176 176
 					} // End If Statement
177 177
 
178
-					if ( ! $done_processing ) { ?>
178
+					if ( ! $done_processing) { ?>
179 179
 
180
-						<h3><?php _e( 'Processing Updates...', 'woothemes-sensei' ); ?></h3>
180
+						<h3><?php _e('Processing Updates...', 'woothemes-sensei'); ?></h3>
181 181
 
182
-						<p><?php _e( 'If your browser doesn&#8217;t start loading the next page automatically, click this button:', 'woothemes-sensei' ); ?>&nbsp;&nbsp;<a class="button" href="admin.php?page=sensei_updates&action=update&n=<?php echo ($n + 50) ?>&functions[]=<?php echo $functions_list; ?>"><?php _e( 'Next', 'woothemes-sensei' ); ?></a></p>
182
+						<p><?php _e('If your browser doesn&#8217;t start loading the next page automatically, click this button:', 'woothemes-sensei'); ?>&nbsp;&nbsp;<a class="button" href="admin.php?page=sensei_updates&action=update&n=<?php echo ($n + 50) ?>&functions[]=<?php echo $functions_list; ?>"><?php _e('Next', 'woothemes-sensei'); ?></a></p>
183 183
 						<script type='text/javascript'>
184 184
 						<!--
185 185
 						function sensei_nextpage() {
@@ -191,48 +191,48 @@  discard block
 block discarded – undo
191 191
 
192 192
 					} else { ?>
193 193
 
194
-						<p><strong><?php _e( 'Update completed successfully!', 'woothemes-sensei' ); ?></strong></p>
195
-						<p><a href="<?php echo admin_url('edit.php?post_type=lesson'); ?>"><?php _e( 'Create a new lesson', 'woothemes-sensei' ); ?></a> or <a href="<?php echo admin_url('admin.php?page=sensei_updates'); ?>"><?php _e( 'run some more updates', 'woothemes-sensei' ); ?></a>.</p>
194
+						<p><strong><?php _e('Update completed successfully!', 'woothemes-sensei'); ?></strong></p>
195
+						<p><a href="<?php echo admin_url('edit.php?post_type=lesson'); ?>"><?php _e('Create a new lesson', 'woothemes-sensei'); ?></a> or <a href="<?php echo admin_url('admin.php?page=sensei_updates'); ?>"><?php _e('run some more updates', 'woothemes-sensei'); ?></a>.</p>
196 196
 
197 197
 					<?php } // End If Statement
198 198
 
199 199
 				} else { ?>
200 200
 
201
-					<h3><?php _e( 'Updates', 'woothemes-sensei' ); ?></h3>
202
-					<p><?php printf( __( 'These are updates that have been made available as new Sensei versions have been released. Updates of type %1$sAuto%2$s will run as you update Sensei to the relevant version - other updates need to be run manually and you can do that here.', 'woothemes-sensei' ), '<code>', '</code>' ); ?></p>
201
+					<h3><?php _e('Updates', 'woothemes-sensei'); ?></h3>
202
+					<p><?php printf(__('These are updates that have been made available as new Sensei versions have been released. Updates of type %1$sAuto%2$s will run as you update Sensei to the relevant version - other updates need to be run manually and you can do that here.', 'woothemes-sensei'), '<code>', '</code>'); ?></p>
203 203
 
204
-					<div class="updated"><p><strong><?php _e( 'Only run these updates if you have been instructed to do so by WooThemes support staff.', 'woothemes-sensei' ); ?></strong></p></div>
204
+					<div class="updated"><p><strong><?php _e('Only run these updates if you have been instructed to do so by WooThemes support staff.', 'woothemes-sensei'); ?></strong></p></div>
205 205
 
206 206
 					<table class="widefat" cellspacing="0" id="update-plugins-table">
207 207
 
208 208
 						<thead>
209 209
 							<tr>
210
-								<th scope="col" class="manage-column"><?php _e( 'Update', 'woothemes-sensei' ); ?></th>
211
-								<th scope="col" class="manage-column"><?php _e( 'Type', 'woothemes-sensei' ); ?></th>
212
-								<th scope="col" class="manage-column"><?php _e( 'Action', 'woothemes-sensei' ); ?></th>
210
+								<th scope="col" class="manage-column"><?php _e('Update', 'woothemes-sensei'); ?></th>
211
+								<th scope="col" class="manage-column"><?php _e('Type', 'woothemes-sensei'); ?></th>
212
+								<th scope="col" class="manage-column"><?php _e('Action', 'woothemes-sensei'); ?></th>
213 213
 							</tr>
214 214
 						</thead>
215 215
 
216 216
 						<tfoot>
217 217
 							<tr>
218
-								<th scope="col" class="manage-column"><?php _e( 'Update', 'woothemes-sensei' ); ?></th>
219
-								<th scope="col" class="manage-column"><?php _e( 'Type', 'woothemes-sensei' ); ?></th>
220
-								<th scope="col" class="manage-column"><?php _e( 'Action', 'woothemes-sensei' ); ?></th>
218
+								<th scope="col" class="manage-column"><?php _e('Update', 'woothemes-sensei'); ?></th>
219
+								<th scope="col" class="manage-column"><?php _e('Type', 'woothemes-sensei'); ?></th>
220
+								<th scope="col" class="manage-column"><?php _e('Action', 'woothemes-sensei'); ?></th>
221 221
 							</tr>
222 222
 						</tfoot>
223 223
 
224 224
 						<tbody class="updates">
225 225
 							<?php
226 226
 							// Sort updates with the latest at the top
227
-							uksort( $this->updates, array( $this, 'sort_updates' ) );
228
-							$this->updates = array_reverse( $this->updates, true );
227
+							uksort($this->updates, array($this, 'sort_updates'));
228
+							$this->updates = array_reverse($this->updates, true);
229 229
 							$class = 'alternate';
230
-							foreach( $this->updates as $version => $version_updates ) {
231
-								foreach( $version_updates as $type => $updates ) {
232
-									foreach( $updates as $update => $data ) {
233
-										$update_run = $this->has_update_run( $update );
230
+							foreach ($this->updates as $version => $version_updates) {
231
+								foreach ($version_updates as $type => $updates) {
232
+									foreach ($updates as $update => $data) {
233
+										$update_run = $this->has_update_run($update);
234 234
 										$product = 'Sensei';
235
-										if ( isset( $data['product'] ) && '' != $data['product'] ) {
235
+										if (isset($data['product']) && '' != $data['product']) {
236 236
 											$product = $data['product'];
237 237
 										} // End If Statement
238 238
 										?>
@@ -242,21 +242,21 @@  discard block
 block discarded – undo
242 242
 													<p>
243 243
 														<input type="hidden" name="checked[]" value="<?php echo $update; ?>">
244 244
 														<strong><?php echo $data['title']; ?></strong><br><?php echo $data['desc']; ?><br>
245
-														<em><?php printf( __( 'Originally included in %s v%s', 'woothemes-sensei' ), $product, $version ); ?></em>
245
+														<em><?php printf(__('Originally included in %s v%s', 'woothemes-sensei'), $product, $version); ?></em>
246 246
 													</p>
247 247
 												</td>
248 248
 												<?php
249
-												$type_label = __( 'Auto', 'woothemes-sensei' );
250
-												if( $type != 'auto' ) {
251
-													$type_label = __( 'Manual', 'woothemes-sensei' );
249
+												$type_label = __('Auto', 'woothemes-sensei');
250
+												if ($type != 'auto') {
251
+													$type_label = __('Manual', 'woothemes-sensei');
252 252
 												}
253 253
 												?>
254 254
 												<td><p><?php echo $type_label; ?></p></td>
255
-												<td><p><input onclick="javascript:return confirm('<?php echo addslashes( sprintf( __( 'Are you sure you want to run the \'%s\' update?', 'woothemes-sensei' ), $data['title'] ) ); ?>');" id="update-sensei" class="button<?php if( ! $update_run ) { echo ' button-primary'; } ?>" type="submit" value="<?php if( $update_run ) { _e( 'Re-run Update', 'woothemes-sensei' ); } else { _e( 'Run Update', 'woothemes-sensei' ); } ?>" name="update"></p></td>
255
+												<td><p><input onclick="javascript:return confirm('<?php echo addslashes(sprintf(__('Are you sure you want to run the \'%s\' update?', 'woothemes-sensei'), $data['title'])); ?>');" id="update-sensei" class="button<?php if ( ! $update_run) { echo ' button-primary'; } ?>" type="submit" value="<?php if ($update_run) { _e('Re-run Update', 'woothemes-sensei'); } else { _e('Run Update', 'woothemes-sensei'); } ?>" name="update"></p></td>
256 256
 											</tr>
257 257
 										</form>
258 258
 										<?php
259
-										if( 'alternate' == $class ) {
259
+										if ('alternate' == $class) {
260 260
 											$class = '';
261 261
 										} else {
262 262
 											$class = 'alternate';
@@ -283,8 +283,8 @@  discard block
 block discarded – undo
283 283
 	 * @param  string $b Second key
284 284
 	 * @return integer
285 285
 	 */
286
-	private function sort_updates( $a, $b ) {
287
-		return strcmp( $a, $b );
286
+	private function sort_updates($a, $b) {
287
+		return strcmp($a, $b);
288 288
 	}
289 289
 
290 290
 	/**
@@ -295,32 +295,32 @@  discard block
 block discarded – undo
295 295
 	 * @access public
296 296
 	 * @return boolean
297 297
 	 */
298
-	public function update ( $type = 'auto' ) {
298
+	public function update($type = 'auto') {
299 299
 
300 300
 		// Only allow admins to run update functions
301
-		if( current_user_can( 'manage_options' ) ) {
301
+		if (current_user_can('manage_options')) {
302 302
 
303 303
 			$this->force_updates();
304 304
 
305 305
 			// Run through all functions
306
-			foreach ( $this->updates as $version => $value ) {
307
-				foreach ( $this->updates[$version] as $upgrade_type => $function_to_run ) {
308
-					if ( $upgrade_type == $type ) {
306
+			foreach ($this->updates as $version => $value) {
307
+				foreach ($this->updates[$version] as $upgrade_type => $function_to_run) {
308
+					if ($upgrade_type == $type) {
309 309
 						$updated = false;
310 310
 						// Run the update function
311
-						foreach ( $function_to_run as $function_name => $update_data ) {
312
-							if ( isset( $function_name ) && '' != $function_name ) {
313
-								if ( ! in_array( $function_name, $this->updates_run ) ) {
311
+						foreach ($function_to_run as $function_name => $update_data) {
312
+							if (isset($function_name) && '' != $function_name) {
313
+								if ( ! in_array($function_name, $this->updates_run)) {
314 314
 									$updated = false;
315
-									if ( method_exists( $this, $function_name ) ) {
316
-										$updated = call_user_func( array( $this, $function_name ) );
317
-									} elseif( function_exists( $function_name ) ) {
318
-										$updated = call_user_func( $function_name );
315
+									if (method_exists($this, $function_name)) {
316
+										$updated = call_user_func(array($this, $function_name));
317
+									} elseif (function_exists($function_name)) {
318
+										$updated = call_user_func($function_name);
319 319
 									} else {
320 320
 										// Nothing to see here...
321 321
 									} // End If Statement
322
-									if ( $updated ) {
323
-										array_push( $this->updates_run, $function_name );
322
+									if ($updated) {
323
+										array_push($this->updates_run, $function_name);
324 324
 									} // End If Statement
325 325
 								}
326 326
 							} // End If Statement
@@ -329,8 +329,8 @@  discard block
 block discarded – undo
329 329
 				} // End For Loop
330 330
 			} // End For Loop
331 331
 
332
-            $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update
333
-			update_option( $this->token . '-upgrades', $this->updates_run );
332
+            $this->updates_run = array_unique($this->updates_run); // we only need one reference per update
333
+			update_option($this->token.'-upgrades', $this->updates_run);
334 334
 			return true;
335 335
 
336 336
 		}
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
 
340 340
 	private function force_updates() {
341 341
 
342
-		if( ! isset( $_GET['page'] ) || 'sensei_updates' != $_GET['page'] ) {
342
+		if ( ! isset($_GET['page']) || 'sensei_updates' != $_GET['page']) {
343 343
 
344 344
 			// $skip_forced_updates = false;
345 345
 			// if( ! get_option( 'woothemes-sensei-force-updates', false ) ) {
@@ -348,8 +348,8 @@  discard block
 block discarded – undo
348 348
 
349 349
 			// Force critical updates if only if lessons already exist
350 350
 			$skip_forced_updates = false;
351
-			$lesson_posts = wp_count_posts( 'lesson' );
352
-			if( ! isset( $lesson_posts->publish ) || ! $lesson_posts->publish ) {
351
+			$lesson_posts = wp_count_posts('lesson');
352
+			if ( ! isset($lesson_posts->publish) || ! $lesson_posts->publish) {
353 353
 				$skip_forced_updates = true;
354 354
 			}
355 355
 
@@ -357,69 +357,69 @@  discard block
 block discarded – undo
357 357
 
358 358
 			$updates_to_run = array();
359 359
 
360
-			foreach ( $this->updates as $version => $value ) {
361
-				foreach ( $this->updates[$version] as $upgrade_type => $function_to_run ) {
362
-					if ( $upgrade_type == 'forced' ) {
363
-						foreach ( $function_to_run as $function_name => $update_data ) {
360
+			foreach ($this->updates as $version => $value) {
361
+				foreach ($this->updates[$version] as $upgrade_type => $function_to_run) {
362
+					if ($upgrade_type == 'forced') {
363
+						foreach ($function_to_run as $function_name => $update_data) {
364 364
 
365
-							if( $skip_forced_updates ) {
366
-								$this->set_update_run( $function_name );
365
+							if ($skip_forced_updates) {
366
+								$this->set_update_run($function_name);
367 367
 								continue;
368 368
 							}
369 369
 
370
-							$update_run = $this->has_update_run( $function_name );
370
+							$update_run = $this->has_update_run($function_name);
371 371
 
372
-							if( ! $update_run ) {
372
+							if ( ! $update_run) {
373 373
 								$use_the_force = true;
374
-								$updates_to_run[ $function_name ] = $update_data;
374
+								$updates_to_run[$function_name] = $update_data;
375 375
 							}
376 376
 						}
377 377
 					}
378 378
 				}
379 379
 			}
380 380
 
381
-			if( $skip_forced_updates ) {
381
+			if ($skip_forced_updates) {
382 382
 				return;
383 383
 			}
384 384
 
385
-			if( $use_the_force && 0 < count( $updates_to_run ) ) {
385
+			if ($use_the_force && 0 < count($updates_to_run)) {
386 386
 
387
-				$update_title = __( 'Important Sensei updates required', 'woothemes-sensei' );
387
+				$update_title = __('Important Sensei updates required', 'woothemes-sensei');
388 388
 
389
-				$update_message = '<h1>' . __( 'Important Sensei upgrades required!', 'woothemes-sensei' ) . '</h1>' . "\n";
389
+				$update_message = '<h1>'.__('Important Sensei upgrades required!', 'woothemes-sensei').'</h1>'."\n";
390 390
 
391 391
 				// $update_message .= '<h4>' . sprintf( __( 'These updates are only required if you are updating from a previous version of Sensei. If you are installing Sensei for the first time, %1$syou can dismiss this page by clicking here%2$s.', 'woothemes-sensei' ), '<a href="' . add_query_arg( array( 'sensei_skip_forced_updates' => 'true' ) ) . '">', '</a>' ) . '</h4>' ."\n";
392 392
 
393
-				$update_message .= '<p>' . __( 'The latest version of Sensei requires some important database upgrades. In order to run these upgrades you will need to follow the step by step guide below. Your site will not function correctly unless you run these critical updates.', 'woothemes-sensei' ) . '</p>' . "\n";
393
+				$update_message .= '<p>'.__('The latest version of Sensei requires some important database upgrades. In order to run these upgrades you will need to follow the step by step guide below. Your site will not function correctly unless you run these critical updates.', 'woothemes-sensei').'</p>'."\n";
394 394
 
395
-				$update_message .= '<p><b>' . __( 'To run the upgrades click on each of the links below in the order that they appear.', 'woothemes-sensei' ) . '</b></p>' . "\n";
395
+				$update_message .= '<p><b>'.__('To run the upgrades click on each of the links below in the order that they appear.', 'woothemes-sensei').'</b></p>'."\n";
396 396
 
397
-				$update_message .= '<p>' . __( 'Clicking each link will open up a new window/tab - do not close that window/tab until you see the message \'Update completed successfully\'. Once you see that message you can close the window/tab and start the next upgrade by clicking on the next link in the list.', 'woothemes-sensei' ) . '</p>' . "\n";
397
+				$update_message .= '<p>'.__('Clicking each link will open up a new window/tab - do not close that window/tab until you see the message \'Update completed successfully\'. Once you see that message you can close the window/tab and start the next upgrade by clicking on the next link in the list.', 'woothemes-sensei').'</p>'."\n";
398 398
 
399
-				$update_message .= '<p><b>' . __( 'Once all the upgrades have been completed you will be able to use your WordPress site again.', 'woothemes-sensei' ) . '</b></p>' . "\n";
399
+				$update_message .= '<p><b>'.__('Once all the upgrades have been completed you will be able to use your WordPress site again.', 'woothemes-sensei').'</b></p>'."\n";
400 400
 
401
-				$update_message .= '<ol>' . "\n";
401
+				$update_message .= '<ol>'."\n";
402 402
 
403
-					foreach( $updates_to_run as $function => $data ) {
403
+					foreach ($updates_to_run as $function => $data) {
404 404
 
405
-						if( ! isset( $data['title'] ) ) {
405
+						if ( ! isset($data['title'])) {
406 406
 							break;
407 407
 						}
408 408
 
409
-						$update_message .= '<li style="margin:5px 0;"><a href="' . admin_url( 'admin.php?page=sensei_updates&action=update&n=0&functions[]=' . $function ) . '" target="_blank">' . $data['title'] . '</a></li>';
409
+						$update_message .= '<li style="margin:5px 0;"><a href="'.admin_url('admin.php?page=sensei_updates&action=update&n=0&functions[]='.$function).'" target="_blank">'.$data['title'].'</a></li>';
410 410
 					}
411 411
 
412
-				$update_message .= '</ol>' . "\n";
412
+				$update_message .= '</ol>'."\n";
413 413
 
414
-				switch( $version ) {
414
+				switch ($version) {
415 415
 
416 416
 					case '1.7.0':
417
-						$update_message .= '<p><em>' . sprintf( __( 'Want to know what these upgrades are all about? %1$sFind out more here%2$s.', 'woothemes-sensei' ), '<a href="http://develop.woothemes.com/sensei/2014/12/03/important-information-about-sensei-1-7" target="_blank">', '</a>' ) . '</em></p>' . "\n";
417
+						$update_message .= '<p><em>'.sprintf(__('Want to know what these upgrades are all about? %1$sFind out more here%2$s.', 'woothemes-sensei'), '<a href="http://develop.woothemes.com/sensei/2014/12/03/important-information-about-sensei-1-7" target="_blank">', '</a>').'</em></p>'."\n";
418 418
 					break;
419 419
 
420 420
 				}
421 421
 
422
-				wp_die( $update_message, $update_title );
422
+				wp_die($update_message, $update_title);
423 423
 			}
424 424
 		}
425 425
 	}
@@ -431,8 +431,8 @@  discard block
 block discarded – undo
431 431
 	 * @since  1.4.0
432 432
 	 * @return boolean
433 433
 	 */
434
-	private function has_update_run( $update ) {
435
-		if ( in_array( $update, $this->updates_run ) ) {
434
+	private function has_update_run($update) {
435
+		if (in_array($update, $this->updates_run)) {
436 436
 			return true;
437 437
 		}
438 438
 		return false;
@@ -444,10 +444,10 @@  discard block
 block discarded – undo
444 444
 	 * @param string $update Update to process
445 445
 	 * @since  1.4.0
446 446
 	 */
447
-	private function set_update_run( $update ) {
448
-		array_push( $this->updates_run, $update );
449
-        $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update
450
-		update_option( $this->token . '-upgrades', $this->updates_run );
447
+	private function set_update_run($update) {
448
+		array_push($this->updates_run, $update);
449
+        $this->updates_run = array_unique($this->updates_run); // we only need one reference per update
450
+		update_option($this->token.'-upgrades', $this->updates_run);
451 451
 	}
452 452
 
453 453
 	/**
@@ -458,15 +458,15 @@  discard block
 block discarded – undo
458 458
 	 * @return void
459 459
 	 */
460 460
 	public function assign_role_caps() {
461
-		foreach ( $this->parent->post_types->role_caps as $role_cap_set  ) {
462
-			foreach ( $role_cap_set as $role_key => $capabilities_array ) {
461
+		foreach ($this->parent->post_types->role_caps as $role_cap_set) {
462
+			foreach ($role_cap_set as $role_key => $capabilities_array) {
463 463
 				/* Get the role. */
464
-				$role = get_role( $role_key );
465
-				foreach ( $capabilities_array as $cap_name  ) {
464
+				$role = get_role($role_key);
465
+				foreach ($capabilities_array as $cap_name) {
466 466
 					/* If the role exists, add required capabilities for the plugin. */
467
-					if ( !empty( $role ) ) {
468
-						if ( !$role->has_cap( $cap_name ) ) {
469
-							$role->add_cap( $cap_name );
467
+					if ( ! empty($role)) {
468
+						if ( ! $role->has_cap($cap_name)) {
469
+							$role->add_cap($cap_name);
470 470
 						} // End If Statement
471 471
 					} // End If Statement
472 472
 				} // End For Loop
@@ -483,16 +483,16 @@  discard block
 block discarded – undo
483 483
 	 * @return void
484 484
 	 */
485 485
 	public function set_default_quiz_grade_type() {
486
-		$args = array(	'post_type' 		=> 'quiz',
486
+		$args = array('post_type' 		=> 'quiz',
487 487
 						'posts_per_page' 		=> -1,
488 488
 						'post_status'		=> 'publish',
489 489
 						'suppress_filters' 	=> 0
490 490
 						);
491
-		$quizzes = get_posts( $args );
491
+		$quizzes = get_posts($args);
492 492
 
493
-		foreach( $quizzes as $quiz ) {
494
-			update_post_meta( $quiz->ID, '_quiz_grade_type', 'auto' );
495
-			update_post_meta( $quiz->ID, '_quiz_grade_type_disabled', '' );
493
+		foreach ($quizzes as $quiz) {
494
+			update_post_meta($quiz->ID, '_quiz_grade_type', 'auto');
495
+			update_post_meta($quiz->ID, '_quiz_grade_type_disabled', '');
496 496
 		}
497 497
 		return true;
498 498
 	} // End set_default_quiz_grade_type
@@ -505,23 +505,23 @@  discard block
 block discarded – undo
505 505
 	 * @return void
506 506
 	 */
507 507
 	public function set_default_question_type() {
508
-		$args = array(	'post_type' 		=> 'question',
508
+		$args = array('post_type' 		=> 'question',
509 509
 						'posts_per_page' 		=> -1,
510 510
 						'post_status'		=> 'publish',
511 511
 						'suppress_filters' 	=> 0
512 512
 						);
513
-		$questions = get_posts( $args );
513
+		$questions = get_posts($args);
514 514
 
515 515
 		$already_run = true;
516
-		foreach( $questions as $question ) {
517
-			if( $already_run ) {
518
-				$terms = wp_get_post_terms( $question->ID, 'question-type' );
519
-				if( is_array( $terms ) && count( $terms ) > 0 ) {
516
+		foreach ($questions as $question) {
517
+			if ($already_run) {
518
+				$terms = wp_get_post_terms($question->ID, 'question-type');
519
+				if (is_array($terms) && count($terms) > 0) {
520 520
 					break;
521 521
 				}
522 522
 			}
523 523
 			$already_run = false;
524
-			wp_set_post_terms( $question->ID, array( 'multiple-choice' ), 'question-type' );
524
+			wp_set_post_terms($question->ID, array('multiple-choice'), 'question-type');
525 525
 		}
526 526
 
527 527
 		return true;
@@ -534,90 +534,90 @@  discard block
 block discarded – undo
534 534
 	 * @access public
535 535
 	 * @return void
536 536
 	 */
537
-	public function update_question_answer_data( $n = 50, $offset = 0 ) {
537
+	public function update_question_answer_data($n = 50, $offset = 0) {
538 538
 
539 539
 		// Get Total Number of Updates to run
540
-		$quiz_count_object = wp_count_posts( 'quiz' );
540
+		$quiz_count_object = wp_count_posts('quiz');
541 541
 		$quiz_count_published = $quiz_count_object->publish;
542 542
 
543 543
 		// Calculate if this is the last page
544
-		if ( 0 == $offset ) {
544
+		if (0 == $offset) {
545 545
 			$current_page = 1;
546 546
 		} else {
547
-			$current_page = intval( $offset / $n );
547
+			$current_page = intval($offset / $n);
548 548
 		} // End If Statement
549
-		$total_pages = intval( $quiz_count_published / $n );
549
+		$total_pages = intval($quiz_count_published / $n);
550 550
 
551 551
 
552
-		$args = array(	'post_type' 		=> 'quiz',
552
+		$args = array('post_type' 		=> 'quiz',
553 553
 						'posts_per_page' 		=> $n,
554 554
 						'offset'			=> $offset,
555 555
 						'post_status'		=> 'publish',
556 556
 						'suppress_filters' 	=> 0
557 557
 						);
558
-		$quizzes = get_posts( $args );
558
+		$quizzes = get_posts($args);
559 559
 
560 560
 		$old_answers = array();
561 561
 		$right_answers = array();
562 562
 		$old_user_answers = array();
563 563
 
564
-		if( is_array( $quizzes ) ) {
565
-			foreach( $quizzes as $quiz ) {
564
+		if (is_array($quizzes)) {
565
+			foreach ($quizzes as $quiz) {
566 566
 				$quiz_id = $quiz->ID;
567 567
 
568 568
 				// Get current user answers
569
-				$comments = WooThemes_Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $quiz_id, 'type' => 'sensei_quiz_answers' ), true  );
569
+				$comments = WooThemes_Sensei_Utils::sensei_check_for_activity(array('post_id' => $quiz_id, 'type' => 'sensei_quiz_answers'), true);
570 570
 				// Need to always return an array, even with only 1 item
571
-				if ( !is_array($comments) ) {
572
-					$comments = array( $comments );
571
+				if ( ! is_array($comments)) {
572
+					$comments = array($comments);
573 573
 				}
574
-				foreach ( $comments as $comment ) {
574
+				foreach ($comments as $comment) {
575 575
 					$user_id = $comment->user_id;
576
-					$content = maybe_unserialize( base64_decode( $comment->comment_content ) );
577
-					$old_user_answers[ $quiz_id ][ $user_id ] = $content;
576
+					$content = maybe_unserialize(base64_decode($comment->comment_content));
577
+					$old_user_answers[$quiz_id][$user_id] = $content;
578 578
 				}
579 579
 
580 580
 				// Get correct answers
581
-				$questions = WooThemes_Sensei_Utils::sensei_get_quiz_questions( $quiz_id );
582
-				if( is_array( $questions ) ) {
583
-					foreach( $questions as $question ) {
584
-						$right_answer = get_post_meta( $question->ID, '_question_right_answer', true );
585
-						$right_answers[ $quiz_id ][ $question->ID ] = $right_answer;
581
+				$questions = WooThemes_Sensei_Utils::sensei_get_quiz_questions($quiz_id);
582
+				if (is_array($questions)) {
583
+					foreach ($questions as $question) {
584
+						$right_answer = get_post_meta($question->ID, '_question_right_answer', true);
585
+						$right_answers[$quiz_id][$question->ID] = $right_answer;
586 586
 					}
587 587
 				}
588 588
 			}
589 589
 		}
590 590
 
591
-		if( is_array( $right_answers ) ) {
592
-			foreach( $right_answers as $quiz_id => $question ) {
591
+		if (is_array($right_answers)) {
592
+			foreach ($right_answers as $quiz_id => $question) {
593 593
 				$count = 0;
594
-				if( is_array( $question ) ) {
595
-					foreach( $question as $question_id => $answer ) {
594
+				if (is_array($question)) {
595
+					foreach ($question as $question_id => $answer) {
596 596
 						++$count;
597
-						if( isset( $old_user_answers[ $quiz_id ] ) ) {
598
-							$answers_linkup[ $quiz_id ][ $count ] = $question_id;
597
+						if (isset($old_user_answers[$quiz_id])) {
598
+							$answers_linkup[$quiz_id][$count] = $question_id;
599 599
 						}
600 600
 					}
601 601
 				}
602 602
 			}
603 603
 		}
604 604
 
605
-		if( is_array( $old_user_answers ) ) {
606
-			foreach( $old_user_answers as $quiz_id => $user_answers ) {
607
-				foreach( $user_answers as $user_id => $answers ) {
608
-					foreach( $answers as $answer_id => $user_answer ) {
609
-						$question_id = $answers_linkup[ $quiz_id ][ $answer_id ];
610
-						$new_user_answers[ $question_id ] = $user_answer;
611
-						WooThemes_Sensei_Utils::sensei_grade_question_auto( $question_id, '', $user_answer, $user_id );
605
+		if (is_array($old_user_answers)) {
606
+			foreach ($old_user_answers as $quiz_id => $user_answers) {
607
+				foreach ($user_answers as $user_id => $answers) {
608
+					foreach ($answers as $answer_id => $user_answer) {
609
+						$question_id = $answers_linkup[$quiz_id][$answer_id];
610
+						$new_user_answers[$question_id] = $user_answer;
611
+						WooThemes_Sensei_Utils::sensei_grade_question_auto($question_id, '', $user_answer, $user_id);
612 612
 					}
613
-					$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
614
-					WooThemes_Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
615
-					WooThemes_Sensei_Utils::sensei_save_quiz_answers( $new_user_answers, $user_id );
613
+					$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
614
+					WooThemes_Sensei_Utils::sensei_start_lesson($lesson_id, $user_id);
615
+					WooThemes_Sensei_Utils::sensei_save_quiz_answers($new_user_answers, $user_id);
616 616
 				}
617 617
 			}
618 618
 		}
619 619
 
620
-		if ( $current_page == $total_pages ) {
620
+		if ($current_page == $total_pages) {
621 621
 			return true;
622 622
 		} else {
623 623
 			return false;
@@ -632,15 +632,15 @@  discard block
 block discarded – undo
632 632
 	 * @return boolean
633 633
 	 */
634 634
 	public function update_question_grade_points() {
635
-		$args = array(	'post_type' 		=> 'question',
635
+		$args = array('post_type' 		=> 'question',
636 636
 						'posts_per_page' 		=> -1,
637 637
 						'post_status'		=> 'publish',
638 638
 						'suppress_filters' 	=> 0
639 639
 						);
640
-		$questions = get_posts( $args );
640
+		$questions = get_posts($args);
641 641
 
642
-		foreach( $questions as $question ) {
643
-			update_post_meta( $question->ID, '_question_grade', '1' );
642
+		foreach ($questions as $question) {
643
+			update_post_meta($question->ID, '_question_grade', '1');
644 644
 		}
645 645
 		return true;
646 646
 	} // End update_question_grade_points
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
 	 * @return boolean
653 653
 	 */
654 654
 	public function convert_essay_paste_questions() {
655
-		$args = array(	'post_type' 		=> 'question',
655
+		$args = array('post_type' 		=> 'question',
656 656
 						'posts_per_page' 		=> -1,
657 657
 						'post_status'		=> 'publish',
658 658
 						'tax_query'			=> array(
@@ -664,14 +664,14 @@  discard block
 block discarded – undo
664 664
 						),
665 665
 						'suppress_filters' 	=> 0
666 666
 						);
667
-		$questions = get_posts( $args );
667
+		$questions = get_posts($args);
668 668
 
669
-		foreach( $questions as $question ) {
670
-			wp_set_object_terms( $question->ID, 'multi-line', 'question-type', false );
669
+		foreach ($questions as $question) {
670
+			wp_set_object_terms($question->ID, 'multi-line', 'question-type', false);
671 671
 
672
-			$quiz_id = get_post_meta( $question->ID, '_quiz_id', true );
673
-			if( 0 < intval( $quiz_id ) ) {
674
-				add_post_meta( $question->ID, '_quiz_question_order' . $quiz_id, $quiz_id . '0000', true );
672
+			$quiz_id = get_post_meta($question->ID, '_quiz_id', true);
673
+			if (0 < intval($quiz_id)) {
674
+				add_post_meta($question->ID, '_quiz_question_order'.$quiz_id, $quiz_id.'0000', true);
675 675
 			}
676 676
 		}
677 677
 		return true;
@@ -683,33 +683,33 @@  discard block
 block discarded – undo
683 683
 	 * @since  1.5.0
684 684
 	 * @return boolean
685 685
 	 */
686
-	public function set_random_question_order( $n = 50, $offset = 0 ) {
686
+	public function set_random_question_order($n = 50, $offset = 0) {
687 687
 
688 688
 		// Get Total Number of Updates to run
689
-		$quiz_count_object = wp_count_posts( 'quiz' );
689
+		$quiz_count_object = wp_count_posts('quiz');
690 690
 		$quiz_count_published = $quiz_count_object->publish;
691 691
 
692 692
 		// Calculate if this is the last page
693
-		if ( 0 == $offset ) {
693
+		if (0 == $offset) {
694 694
 			$current_page = 1;
695 695
 		} else {
696
-			$current_page = intval( $offset / $n );
696
+			$current_page = intval($offset / $n);
697 697
 		} // End If Statement
698
-		$total_pages = intval( $quiz_count_published / $n );
698
+		$total_pages = intval($quiz_count_published / $n);
699 699
 
700
-		$args = array(	'post_type' 		=> 'quiz',
700
+		$args = array('post_type' 		=> 'quiz',
701 701
 						'post_status'		=> 'any',
702 702
 						'posts_per_page' 		=> $n,
703 703
 						'offset'			=> $offset,
704 704
 						'suppress_filters' 	=> 0
705 705
 						);
706
-		$quizzes = get_posts( $args );
706
+		$quizzes = get_posts($args);
707 707
 
708
-		foreach( $quizzes as $quiz ) {
709
-			update_post_meta( $quiz->ID, '_random_question_order', 'yes' );
708
+		foreach ($quizzes as $quiz) {
709
+			update_post_meta($quiz->ID, '_random_question_order', 'yes');
710 710
 		}
711 711
 
712
-		if ( $current_page == $total_pages ) {
712
+		if ($current_page == $total_pages) {
713 713
 			return true;
714 714
 		} else {
715 715
 			return false;
@@ -723,37 +723,37 @@  discard block
 block discarded – undo
723 723
 	 * @since  1.5.0
724 724
 	 * @return boolean
725 725
 	 */
726
-	public function set_default_show_question_count( $n = 50, $offset = 0 ) {
726
+	public function set_default_show_question_count($n = 50, $offset = 0) {
727 727
 
728
-		$args = array(	'post_type' 		=> 'quiz',
728
+		$args = array('post_type' 		=> 'quiz',
729 729
 						'post_status'		=> 'any',
730 730
 						'posts_per_page' 		=> $n,
731 731
 						'offset'			=> $offset,
732 732
 						'meta_key'			=> '_show_questions',
733 733
 						'suppress_filters' 	=> 0
734 734
 						);
735
-		$quizzes = get_posts( $args );
735
+		$quizzes = get_posts($args);
736 736
 
737
-		$total_quizzes = count( $quizzes );
737
+		$total_quizzes = count($quizzes);
738 738
 
739
-		if( 0 == intval( $total_quizzes ) ) {
739
+		if (0 == intval($total_quizzes)) {
740 740
 			return true;
741 741
 		}
742 742
 
743
-		foreach( $quizzes as $quiz ) {
744
-			delete_post_meta( $quiz->ID, '_show_questions' );
743
+		foreach ($quizzes as $quiz) {
744
+			delete_post_meta($quiz->ID, '_show_questions');
745 745
 		}
746 746
 
747
-		$total_pages = intval( $total_quizzes / $n );
747
+		$total_pages = intval($total_quizzes / $n);
748 748
 
749 749
 		// Calculate if this is the last page
750
-		if ( 0 == $offset ) {
750
+		if (0 == $offset) {
751 751
 			$current_page = 1;
752 752
 		} else {
753
-			$current_page = intval( $offset / $n );
753
+			$current_page = intval($offset / $n);
754 754
 		} // End If Statement
755 755
 
756
-		if ( $current_page == $total_pages ) {
756
+		if ($current_page == $total_pages) {
757 757
 			return true;
758 758
 		} else {
759 759
 			return false;
@@ -761,17 +761,17 @@  discard block
 block discarded – undo
761 761
 
762 762
 	}
763 763
 
764
-	public function remove_deleted_user_activity( $n = 50, $offset = 0 ) {
764
+	public function remove_deleted_user_activity($n = 50, $offset = 0) {
765 765
 
766 766
 
767 767
 //		remove_filter( 'comments_clauses', array( Sensei()->admin, 'comments_admin_filter' ) );
768 768
 
769
-		$all_activity = get_comments( array( 'status' => 'approve' ) );
769
+		$all_activity = get_comments(array('status' => 'approve'));
770 770
 		$activity_count = array();
771
-		foreach( $all_activity as $activity ) {
772
-			if( '' == $activity->comment_type ) continue;
773
-			if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue;
774
-			if( 0 == $activity->user_id ) continue;
771
+		foreach ($all_activity as $activity) {
772
+			if ('' == $activity->comment_type) continue;
773
+			if (strpos('sensei_', $activity->comment_type) != 0) continue;
774
+			if (0 == $activity->user_id) continue;
775 775
 			$activity_count[] = $activity->comment_ID;
776 776
 		}
777 777
 
@@ -781,35 +781,35 @@  discard block
 block discarded – undo
781 781
 			'status' => 'approve'
782 782
 		);
783 783
 
784
-		$activities = get_comments( $args );
784
+		$activities = get_comments($args);
785 785
 
786
-		foreach( $activities as $activity ) {
787
-			if( '' == $activity->comment_type ) continue;
788
-			if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue;
789
-			if( 0 == $activity->user_id ) continue;
786
+		foreach ($activities as $activity) {
787
+			if ('' == $activity->comment_type) continue;
788
+			if (strpos('sensei_', $activity->comment_type) != 0) continue;
789
+			if (0 == $activity->user_id) continue;
790 790
 
791
-			$user_exists = get_userdata( $activity->user_id );
791
+			$user_exists = get_userdata($activity->user_id);
792 792
 
793
-			if( ! $user_exists ) {
794
-				wp_delete_comment( intval( $activity->comment_ID ), true );
793
+			if ( ! $user_exists) {
794
+				wp_delete_comment(intval($activity->comment_ID), true);
795 795
 				wp_cache_flush();
796 796
 			}
797 797
 		}
798 798
 
799
-		$total_activities = count( $activity_count );
799
+		$total_activities = count($activity_count);
800 800
 
801
-		$total_pages = intval( $total_activities / $n );
801
+		$total_pages = intval($total_activities / $n);
802 802
 
803 803
 		// Calculate if this is the last page
804
-		if ( 0 == $offset ) {
804
+		if (0 == $offset) {
805 805
 			$current_page = 1;
806 806
 		} else {
807
-			$current_page = intval( $offset / $n );
807
+			$current_page = intval($offset / $n);
808 808
 		} // End If Statement
809 809
 
810 810
 //		add_filter( 'comments_clauses', array( Sensei()->admin, 'comments_admin_filter' ) );
811 811
 
812
-		if ( $current_page >= $total_pages ) {
812
+		if ($current_page >= $total_pages) {
813 813
 			return true;
814 814
 		} else {
815 815
 			return false;
@@ -818,16 +818,16 @@  discard block
 block discarded – undo
818 818
 	}
819 819
 
820 820
 	public function add_teacher_role() {
821
-		add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ), array( 'read' => true, 'manage_sensei_grades' => true ) );
821
+		add_role('teacher', __('Teacher', 'woothemes-sensei'), array('read' => true, 'manage_sensei_grades' => true));
822 822
 		return true;
823 823
 	}
824 824
 
825 825
 	public function add_sensei_caps() {
826
-		$role = get_role( 'administrator' );
826
+		$role = get_role('administrator');
827 827
 
828
-		if( ! is_null( $role ) ) {
829
-			$role->add_cap( 'manage_sensei' );
830
-			$role->add_cap( 'manage_sensei_grades' );
828
+		if ( ! is_null($role)) {
829
+			$role->add_cap('manage_sensei');
830
+			$role->add_cap('manage_sensei_grades');
831 831
 		}
832 832
 
833 833
 		return true;
@@ -841,16 +841,16 @@  discard block
 block discarded – undo
841 841
 			'suppress_filters' 	=> 0
842 842
 		);
843 843
 
844
-		$questions = get_posts( $args );
844
+		$questions = get_posts($args);
845 845
 
846
-		foreach( $questions as $question ) {
846
+		foreach ($questions as $question) {
847 847
 
848
-			if( ! isset( $question->ID ) ) continue;
848
+			if ( ! isset($question->ID)) continue;
849 849
 
850
-			$quiz_id = get_post_meta( $question->ID, '_quiz_id', true );
850
+			$quiz_id = get_post_meta($question->ID, '_quiz_id', true);
851 851
 
852
-			$question_order = get_post_meta( $question->ID, '_quiz_question_order', true );
853
-			update_post_meta( $question->ID, '_quiz_question_order' . $quiz_id, $question_order );
852
+			$question_order = get_post_meta($question->ID, '_quiz_question_order', true);
853
+			update_post_meta($question->ID, '_quiz_question_order'.$quiz_id, $question_order);
854 854
 
855 855
 		}
856 856
 
@@ -859,15 +859,15 @@  discard block
 block discarded – undo
859 859
 
860 860
 	public function update_quiz_settings() {
861 861
 
862
-		$settings = get_option( 'woothemes-sensei-settings', array() );
862
+		$settings = get_option('woothemes-sensei-settings', array());
863 863
 
864 864
 		$lesson_completion = false;
865
-		if( isset( $settings['lesson_completion'] ) ) {
865
+		if (isset($settings['lesson_completion'])) {
866 866
 			$lesson_completion = $settings['lesson_completion'];
867 867
 		}
868 868
 
869 869
 		$reset_quiz_allowed = false;
870
-		if( isset( $settings['quiz_reset_allowed'] ) ) {
870
+		if (isset($settings['quiz_reset_allowed'])) {
871 871
 			$reset_quiz_allowed = $settings['quiz_reset_allowed'];
872 872
 		}
873 873
 
@@ -878,20 +878,20 @@  discard block
 block discarded – undo
878 878
 			'suppress_filters' 	=> 0
879 879
 		);
880 880
 
881
-		$quizzes = get_posts( $args );
881
+		$quizzes = get_posts($args);
882 882
 
883
-		foreach( $quizzes as $quiz ) {
883
+		foreach ($quizzes as $quiz) {
884 884
 
885
-			if( ! isset( $quiz->ID ) ) continue;
885
+			if ( ! isset($quiz->ID)) continue;
886 886
 
887
-			if( isset( $lesson_completion ) && 'passed' == $lesson_completion ) {
888
-				update_post_meta( $quiz->ID, '_pass_required', 'on' );
887
+			if (isset($lesson_completion) && 'passed' == $lesson_completion) {
888
+				update_post_meta($quiz->ID, '_pass_required', 'on');
889 889
 			} else {
890
-				update_post_meta( $quiz->ID, '_quiz_passmark', 0 );
890
+				update_post_meta($quiz->ID, '_quiz_passmark', 0);
891 891
 			}
892 892
 
893
-			if( isset( $reset_quiz_allowed ) && $reset_quiz_allowed ) {
894
-				update_post_meta( $quiz->ID, '_enable_quiz_reset', 'on' );
893
+			if (isset($reset_quiz_allowed) && $reset_quiz_allowed) {
894
+				update_post_meta($quiz->ID, '_enable_quiz_reset', 'on');
895 895
 			}
896 896
 		}
897 897
 
@@ -906,22 +906,22 @@  discard block
 block discarded – undo
906 906
 			'suppress_filters' 	=> 0
907 907
 		);
908 908
 
909
-		$lessons = get_posts( $args );
909
+		$lessons = get_posts($args);
910 910
 
911
-		foreach( $lessons as $lesson ) {
911
+		foreach ($lessons as $lesson) {
912 912
 
913
-			if( ! isset( $lesson->ID ) ) continue;
913
+			if ( ! isset($lesson->ID)) continue;
914 914
 
915
-			$course_id = get_post_meta( $lesson->ID, '_lesson_course', true);
915
+			$course_id = get_post_meta($lesson->ID, '_lesson_course', true);
916 916
 
917
-			if( $course_id ) {
918
-				update_post_meta( $lesson->ID, '_order_' . $course_id, 0 );
917
+			if ($course_id) {
918
+				update_post_meta($lesson->ID, '_order_'.$course_id, 0);
919 919
 			}
920 920
 
921
-            $module = Sensei()->modules->get_lesson_module( $lesson->ID );
921
+            $module = Sensei()->modules->get_lesson_module($lesson->ID);
922 922
 
923
-            if( $module ) {
924
-                update_post_meta( $lesson->ID, '_order_module_' . $module->term_id, 0 );
923
+            if ($module) {
924
+                update_post_meta($lesson->ID, '_order_module_'.$module->term_id, 0);
925 925
             }
926 926
 
927 927
 		}
@@ -930,10 +930,10 @@  discard block
 block discarded – undo
930 930
 	}
931 931
 
932 932
 	public function add_editor_caps() {
933
-		$role = get_role( 'editor' );
933
+		$role = get_role('editor');
934 934
 
935
-		if( ! is_null( $role ) ) {
936
-			$role->add_cap( 'manage_sensei_grades' );
935
+		if ( ! is_null($role)) {
936
+			$role->add_cap('manage_sensei_grades');
937 937
 		}
938 938
 
939 939
 		return true;
@@ -952,26 +952,26 @@  discard block
 block discarded – undo
952 952
 					WHERE m.meta_key = '_question_right_answer' AND m.meta_value LIKE '%|%' AND m.meta_value NOT LIKE '%||%'
953 953
 						AND m.post_id = tr.object_id AND tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.term_id = t.term_id
954 954
 						AND tt.taxonomy = 'question-type' AND t.slug = 'gap-fill'";
955
-		$wpdb->query( $sql );
955
+		$wpdb->query($sql);
956 956
 
957 957
 		return true;
958 958
 	}
959 959
 
960
-	public function update_quiz_lesson_relationship( $n = 50, $offset = 0 ) {
961
-		$count_object = wp_count_posts( 'quiz' );
960
+	public function update_quiz_lesson_relationship($n = 50, $offset = 0) {
961
+		$count_object = wp_count_posts('quiz');
962 962
 
963 963
 		$count_published = 0;
964
-		foreach ( $count_object AS $status => $count ) {
964
+		foreach ($count_object AS $status => $count) {
965 965
 			$count_published += $count;
966 966
 		}
967 967
 
968 968
 		// Calculate if this is the last page
969
-		if ( 0 == $offset ) {
969
+		if (0 == $offset) {
970 970
 			$current_page = 1;
971 971
 		} else {
972
-			$current_page = intval( $offset / $n );
972
+			$current_page = intval($offset / $n);
973 973
 		}
974
-		$total_pages = ceil( $count_published / $n );
974
+		$total_pages = ceil($count_published / $n);
975 975
 
976 976
 		$args = array(
977 977
 			'post_type' => 'quiz',
@@ -980,52 +980,52 @@  discard block
 block discarded – undo
980 980
 			'post_status' => 'any'
981 981
 		);
982 982
 
983
-		$quizzes = get_posts( $args );
983
+		$quizzes = get_posts($args);
984 984
 
985
-		foreach( $quizzes as $quiz ) {
985
+		foreach ($quizzes as $quiz) {
986 986
 
987
-			if( ! isset( $quiz->ID ) || 0 != $quiz->post_parent ) continue;
987
+			if ( ! isset($quiz->ID) || 0 != $quiz->post_parent) continue;
988 988
 
989
-			$lesson_id = get_post_meta( $quiz->ID, '_quiz_lesson', true );
989
+			$lesson_id = get_post_meta($quiz->ID, '_quiz_lesson', true);
990 990
 
991
-			if( empty( $lesson_id ) ) continue;
991
+			if (empty($lesson_id)) continue;
992 992
 
993 993
 			$data = array(
994 994
 				'ID' => $quiz->ID,
995 995
 				'post_parent' => $lesson_id,
996 996
 			);
997
-			wp_update_post( $data );
997
+			wp_update_post($data);
998 998
 
999
-			update_post_meta( $lesson_id, '_lesson_quiz', $quiz->ID );
999
+			update_post_meta($lesson_id, '_lesson_quiz', $quiz->ID);
1000 1000
 		}
1001 1001
 
1002
-		if ( $current_page == $total_pages || 0 == $total_pages ) {
1002
+		if ($current_page == $total_pages || 0 == $total_pages) {
1003 1003
 			return true;
1004 1004
 		} else {
1005 1005
 			return false;
1006 1006
 		}
1007 1007
 	}
1008 1008
 
1009
-	function status_changes_fix_lessons( $n = 50, $offset = 0 ) {
1009
+	function status_changes_fix_lessons($n = 50, $offset = 0) {
1010 1010
 		global $wpdb;
1011 1011
 
1012
-		$count_object = wp_count_posts( 'lesson' );
1012
+		$count_object = wp_count_posts('lesson');
1013 1013
 		$count_published = 0;
1014
-		foreach ( $count_object AS $status => $count ) {
1014
+		foreach ($count_object AS $status => $count) {
1015 1015
 			$count_published += $count;
1016 1016
 		}
1017 1017
 
1018
-		if ( 0 == $count_published ) {
1018
+		if (0 == $count_published) {
1019 1019
 			return true;
1020 1020
 		}
1021 1021
 
1022 1022
 		// Calculate if this is the last page
1023
-		if ( 0 == $offset ) {
1023
+		if (0 == $offset) {
1024 1024
 			$current_page = 1;
1025 1025
 		} else {
1026
-			$current_page = intval( $offset / $n );
1026
+			$current_page = intval($offset / $n);
1027 1027
 		}
1028
-		$total_pages = ceil( $count_published / $n );
1028
+		$total_pages = ceil($count_published / $n);
1029 1029
 
1030 1030
 		// Get all Lessons with (and without) Quizzes...
1031 1031
 		$args = array(
@@ -1035,26 +1035,26 @@  discard block
 block discarded – undo
1035 1035
 			'offset' => $offset,
1036 1036
 			'fields' => 'ids'
1037 1037
 		);
1038
-		$lesson_ids = get_posts( $args );
1038
+		$lesson_ids = get_posts($args);
1039 1039
 
1040 1040
 		// ...get all Quiz IDs for the above Lessons
1041
-		$id_list = join( ',', $lesson_ids );
1042
-		$meta_list = $wpdb->get_results( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A );
1041
+		$id_list = join(',', $lesson_ids);
1042
+		$meta_list = $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A);
1043 1043
 		$lesson_quiz_ids = array();
1044
-		if ( !empty($meta_list) ) {
1045
-			foreach ( $meta_list as $metarow ) {
1044
+		if ( ! empty($meta_list)) {
1045
+			foreach ($meta_list as $metarow) {
1046 1046
 				$lesson_id = $metarow['meta_value'];
1047 1047
 				$quiz_id = $metarow['post_id'];
1048
-				$lesson_quiz_ids[ $lesson_id ] = $quiz_id;
1048
+				$lesson_quiz_ids[$lesson_id] = $quiz_id;
1049 1049
 			}
1050 1050
 		}
1051 1051
 
1052 1052
 		// ...check all Quiz IDs for questions
1053
-		$id_list = join( ',', array_values($lesson_quiz_ids) );
1054
-		$meta_list = $wpdb->get_results( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_id' AND meta_value IN ($id_list)", ARRAY_A );
1053
+		$id_list = join(',', array_values($lesson_quiz_ids));
1054
+		$meta_list = $wpdb->get_results("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_id' AND meta_value IN ($id_list)", ARRAY_A);
1055 1055
 		$lesson_quiz_ids_with_questions = array();
1056
-		if ( !empty($meta_list) ) {
1057
-			foreach ( $meta_list as $metarow ) {
1056
+		if ( ! empty($meta_list)) {
1057
+			foreach ($meta_list as $metarow) {
1058 1058
 				$quiz_id = $metarow['meta_value'];
1059 1059
 				$lesson_quiz_ids_with_questions[] = $quiz_id;
1060 1060
 			}
@@ -1062,49 +1062,49 @@  discard block
 block discarded – undo
1062 1062
 
1063 1063
 		// For each quiz check there are questions, if not remove the corresponding meta keys from Quizzes and Lessons
1064 1064
 		// if there are questions on the quiz add the corresponding meta keys to Quizzes and Lessons
1065
-		$d_count = $a_count =0;
1066
-		foreach ( $lesson_quiz_ids AS $lesson_id => $quiz_id ) {
1067
-			if ( !in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) {
1065
+		$d_count = $a_count = 0;
1066
+		foreach ($lesson_quiz_ids AS $lesson_id => $quiz_id) {
1067
+			if ( ! in_array($quiz_id, $lesson_quiz_ids_with_questions)) {
1068 1068
 
1069 1069
 				// Quiz has no questions, drop the corresponding data
1070
-				delete_post_meta( $quiz_id, '_pass_required' );
1071
-				delete_post_meta( $quiz_id, '_quiz_passmark' );
1072
-				delete_post_meta( $lesson_id, '_quiz_has_questions' );
1070
+				delete_post_meta($quiz_id, '_pass_required');
1071
+				delete_post_meta($quiz_id, '_quiz_passmark');
1072
+				delete_post_meta($lesson_id, '_quiz_has_questions');
1073 1073
 				$d_count++;
1074 1074
 			}
1075
-			else if ( in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) {
1075
+			else if (in_array($quiz_id, $lesson_quiz_ids_with_questions)) {
1076 1076
 
1077 1077
 				// Quiz has no questions, drop the corresponding data
1078
-				update_post_meta( $lesson_id, '_quiz_has_questions', true );
1078
+				update_post_meta($lesson_id, '_quiz_has_questions', true);
1079 1079
 				$a_count++;
1080 1080
 			}
1081 1081
 		}
1082 1082
 
1083
-		if ( $current_page == $total_pages ) {
1083
+		if ($current_page == $total_pages) {
1084 1084
 			return true;
1085 1085
 		} else {
1086 1086
 			return false;
1087 1087
 		}
1088 1088
 	}
1089 1089
 
1090
-	function status_changes_convert_lessons( $n = 50, $offset = 0 ) {
1090
+	function status_changes_convert_lessons($n = 50, $offset = 0) {
1091 1091
 		global $wpdb;
1092 1092
 
1093
-		wp_defer_comment_counting( true );
1093
+		wp_defer_comment_counting(true);
1094 1094
 
1095
-		$user_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users " );
1095
+		$user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users ");
1096 1096
 
1097
-		if ( 0 == $user_count_result ) {
1097
+		if (0 == $user_count_result) {
1098 1098
 			return true;
1099 1099
 		}
1100 1100
 
1101
-		if ( 0 == $offset ) {
1101
+		if (0 == $offset) {
1102 1102
 			$current_page = 1;
1103 1103
 		} else {
1104
-			$current_page = intval( $offset / $n );
1104
+			$current_page = intval($offset / $n);
1105 1105
 		}
1106 1106
 
1107
-		$total_pages = ceil( $user_count_result / $n );
1107
+		$total_pages = ceil($user_count_result / $n);
1108 1108
 
1109 1109
 		// Get all Lessons with Quizzes...
1110 1110
 		$args = array(
@@ -1119,34 +1119,34 @@  discard block
 block discarded – undo
1119 1119
 			),
1120 1120
 			'fields' => 'ids'
1121 1121
 		);
1122
-		$lesson_ids_with_quizzes = get_posts( $args );
1122
+		$lesson_ids_with_quizzes = get_posts($args);
1123 1123
 		// ...get all Quiz IDs for the above Lessons
1124
-		$id_list = join( ',', $lesson_ids_with_quizzes );
1125
-		$meta_list = $wpdb->get_results( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A );
1124
+		$id_list = join(',', $lesson_ids_with_quizzes);
1125
+		$meta_list = $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A);
1126 1126
 		$lesson_quiz_ids = array();
1127
-		if ( !empty($meta_list) ) {
1128
-			foreach ( $meta_list as $metarow ) {
1127
+		if ( ! empty($meta_list)) {
1128
+			foreach ($meta_list as $metarow) {
1129 1129
 				$lesson_id = $metarow['meta_value'];
1130 1130
 				$quiz_id = $metarow['post_id'];
1131
-				$lesson_quiz_ids[ $lesson_id ] = $quiz_id;
1131
+				$lesson_quiz_ids[$lesson_id] = $quiz_id;
1132 1132
 			}
1133 1133
 		}
1134 1134
 
1135 1135
 		// ...get all Pass Required & Passmarks for the above Lesson/Quizzes
1136
-		$id_list = join( ',', array_values($lesson_quiz_ids) );
1137
-		$meta_list = $wpdb->get_results( "SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE ( meta_key = '_pass_required' OR meta_key = '_quiz_passmark' ) AND post_id IN ($id_list)", ARRAY_A );
1136
+		$id_list = join(',', array_values($lesson_quiz_ids));
1137
+		$meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE ( meta_key = '_pass_required' OR meta_key = '_quiz_passmark' ) AND post_id IN ($id_list)", ARRAY_A);
1138 1138
 		$quizzes_pass_required = $quizzes_passmarks = array();
1139
-		if ( !empty($meta_list) ) {
1140
-			foreach ( $meta_list as $metarow ) {
1141
-				if ( !empty($metarow['meta_value']) ) {
1139
+		if ( ! empty($meta_list)) {
1140
+			foreach ($meta_list as $metarow) {
1141
+				if ( ! empty($metarow['meta_value'])) {
1142 1142
 					$quiz_id = $metarow['post_id'];
1143 1143
 					$key = $metarow['meta_key'];
1144 1144
 					$value = $metarow['meta_value'];
1145
-					if ( '_pass_required' == $key ) {
1146
-						$quizzes_pass_required[ $quiz_id ] = $value;
1145
+					if ('_pass_required' == $key) {
1146
+						$quizzes_pass_required[$quiz_id] = $value;
1147 1147
 					}
1148
-					if ( '_quiz_passmark' == $key ) {
1149
-						$quizzes_passmarks[ $quiz_id ] = $value;
1148
+					if ('_quiz_passmark' == $key) {
1149
+						$quizzes_passmarks[$quiz_id] = $value;
1150 1150
 					}
1151 1151
 				}
1152 1152
 			}
@@ -1160,41 +1160,41 @@  discard block
 block discarded – undo
1160 1160
 		$check_existing_sql = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = 'sensei_lesson_status' ";
1161 1161
 
1162 1162
 		// $per_page users at a time, could be batch run via an admin ajax command, 1 user at a time?
1163
-		$user_ids = $wpdb->get_col( $wpdb->prepare($users_sql, $n, $offset) );
1163
+		$user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset));
1164 1164
 
1165
-		foreach ( $user_ids AS $user_id ) {
1165
+		foreach ($user_ids AS $user_id) {
1166 1166
 
1167 1167
 			$lesson_ends = $lesson_grades = $lesson_answers = array();
1168 1168
 
1169 1169
 			// Pre-process the lesson ends
1170
-			$_lesson_ends = $wpdb->get_results( $wpdb->prepare($end_sql, $user_id), ARRAY_A );
1171
-			foreach ( $_lesson_ends as $lesson_end ) {
1170
+			$_lesson_ends = $wpdb->get_results($wpdb->prepare($end_sql, $user_id), ARRAY_A);
1171
+			foreach ($_lesson_ends as $lesson_end) {
1172 1172
 				// This will overwrite existing entries with the newer ones
1173
-				$lesson_ends[ $lesson_end['comment_post_ID'] ] = $lesson_end['comment_date'];
1173
+				$lesson_ends[$lesson_end['comment_post_ID']] = $lesson_end['comment_date'];
1174 1174
 			}
1175
-			unset( $_lesson_ends );
1175
+			unset($_lesson_ends);
1176 1176
 
1177 1177
 			// Pre-process the lesson grades
1178
-			$_lesson_grades = $wpdb->get_results( $wpdb->prepare($grade_sql, $user_id), ARRAY_A );
1179
-			foreach ( $_lesson_grades as $lesson_grade ) {
1178
+			$_lesson_grades = $wpdb->get_results($wpdb->prepare($grade_sql, $user_id), ARRAY_A);
1179
+			foreach ($_lesson_grades as $lesson_grade) {
1180 1180
 				// This will overwrite existing entries with the newer ones (assuming the grade is higher)
1181
-				if ( empty($lesson_grades[ $lesson_grade['comment_post_ID'] ]) || $lesson_grades[ $lesson_grade['comment_post_ID'] ] < $lesson_grade['comment_content'] ) {
1182
-					$lesson_grades[ $lesson_grade['comment_post_ID'] ] = $lesson_grade['comment_content'];
1181
+				if (empty($lesson_grades[$lesson_grade['comment_post_ID']]) || $lesson_grades[$lesson_grade['comment_post_ID']] < $lesson_grade['comment_content']) {
1182
+					$lesson_grades[$lesson_grade['comment_post_ID']] = $lesson_grade['comment_content'];
1183 1183
 				}
1184 1184
 			}
1185
-			unset( $_lesson_grades );
1185
+			unset($_lesson_grades);
1186 1186
 
1187 1187
 			// Pre-process the lesson answers
1188
-			$_lesson_answers = $wpdb->get_results( $wpdb->prepare($answers_sql, $user_id), ARRAY_A );
1189
-			foreach ( $_lesson_answers as $lesson_answer ) {
1188
+			$_lesson_answers = $wpdb->get_results($wpdb->prepare($answers_sql, $user_id), ARRAY_A);
1189
+			foreach ($_lesson_answers as $lesson_answer) {
1190 1190
 				// This will overwrite existing entries with the newer ones
1191
-				$lesson_answers[ $lesson_answer['comment_post_ID'] ] = $lesson_answer['comment_content'];
1191
+				$lesson_answers[$lesson_answer['comment_post_ID']] = $lesson_answer['comment_content'];
1192 1192
 			}
1193
-			unset( $_lesson_answers );
1193
+			unset($_lesson_answers);
1194 1194
 
1195 1195
 			// Grab all the lesson starts for the user
1196
-			$lesson_starts = $wpdb->get_results( $wpdb->prepare($start_sql, $user_id), ARRAY_A );
1197
-			foreach ( $lesson_starts as $lesson_log ) {
1196
+			$lesson_starts = $wpdb->get_results($wpdb->prepare($start_sql, $user_id), ARRAY_A);
1197
+			foreach ($lesson_starts as $lesson_log) {
1198 1198
 
1199 1199
 				$lesson_id = $lesson_log['comment_post_ID'];
1200 1200
 
@@ -1207,23 +1207,23 @@  discard block
 block discarded – undo
1207 1207
 					'start' => $status_date,
1208 1208
 				);
1209 1209
 				// Check if there is a lesson end
1210
-				if ( !empty($lesson_ends[$lesson_id]) ) {
1210
+				if ( ! empty($lesson_ends[$lesson_id])) {
1211 1211
 					$status_date = $lesson_ends[$lesson_id];
1212 1212
 					// Check lesson has quiz
1213
-					if ( !empty( $lesson_quiz_ids[$lesson_id] ) ) {
1213
+					if ( ! empty($lesson_quiz_ids[$lesson_id])) {
1214 1214
 						// Check for the quiz answers
1215
-						if ( !empty($lesson_answers[$quiz_id]) ) {
1215
+						if ( ! empty($lesson_answers[$quiz_id])) {
1216 1216
 							$meta_data['questions_asked'] = $lesson_answers[$quiz_id];
1217 1217
 						}
1218 1218
 						// Check if there is a quiz grade
1219 1219
 						$quiz_id = $lesson_quiz_ids[$lesson_id];
1220
-						if ( !empty($lesson_grades[$quiz_id]) ) {
1220
+						if ( ! empty($lesson_grades[$quiz_id])) {
1221 1221
 							$meta_data['grade'] = $quiz_grade = $lesson_grades[$quiz_id];
1222 1222
 							// Check if the user has to get the passmark and has or not
1223
-							if ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] <= $quiz_grade ) {
1223
+							if ( ! empty($quizzes_pass_required[$quiz_id]) && $quizzes_passmarks[$quiz_id] <= $quiz_grade) {
1224 1224
 								$status = 'passed';
1225 1225
 							}
1226
-							elseif ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] > $quiz_grade ) {
1226
+							elseif ( ! empty($quizzes_pass_required[$quiz_id]) && $quizzes_passmarks[$quiz_id] > $quiz_grade) {
1227 1227
 								$status = 'failed';
1228 1228
 							}
1229 1229
 							else {
@@ -1251,26 +1251,26 @@  discard block
 block discarded – undo
1251 1251
 						'comment_author' => '',
1252 1252
 					);
1253 1253
 				// Check it doesn't already exist
1254
-				$sql = $wpdb->prepare( $check_existing_sql, $lesson_id, $user_id );
1255
-				$comment_ID = $wpdb->get_var( $sql );
1256
-				if ( !$comment_ID ) {
1254
+				$sql = $wpdb->prepare($check_existing_sql, $lesson_id, $user_id);
1255
+				$comment_ID = $wpdb->get_var($sql);
1256
+				if ( ! $comment_ID) {
1257 1257
 					// Bypassing WP wp_insert_comment( $data ), so no actions/filters are run
1258 1258
 					$wpdb->insert($wpdb->comments, $data);
1259 1259
 					$comment_ID = (int) $wpdb->insert_id;
1260 1260
 
1261
-					if ( $comment_ID && !empty($meta_data) ) {
1262
-						foreach ( $meta_data as $key => $value ) {
1261
+					if ($comment_ID && ! empty($meta_data)) {
1262
+						foreach ($meta_data as $key => $value) {
1263 1263
 							// Bypassing WP add_comment_meta(() so no actions/filters are run
1264
-							if ( $wpdb->get_var( $wpdb->prepare(
1264
+							if ($wpdb->get_var($wpdb->prepare(
1265 1265
 									"SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ",
1266
-									$comment_ID, $key ) ) ) {
1266
+									$comment_ID, $key ))) {
1267 1267
 									continue; // Found the meta data already
1268 1268
 							}
1269
-							$result = $wpdb->insert( $wpdb->commentmeta, array(
1269
+							$result = $wpdb->insert($wpdb->commentmeta, array(
1270 1270
 								'comment_id' => $comment_ID,
1271 1271
 								'meta_key' => $key,
1272 1272
 								'meta_value' => $value
1273
-							) );
1273
+							));
1274 1274
 						}
1275 1275
 					}
1276 1276
 				}
@@ -1278,40 +1278,40 @@  discard block
 block discarded – undo
1278 1278
 		}
1279 1279
 		$wpdb->flush();
1280 1280
 
1281
-		if ( $current_page == $total_pages ) {
1281
+		if ($current_page == $total_pages) {
1282 1282
 			return true;
1283 1283
 		} else {
1284 1284
 			return false;
1285 1285
 		}
1286 1286
 	}
1287 1287
 
1288
-	function status_changes_convert_courses( $n = 50, $offset = 0 ) {
1288
+	function status_changes_convert_courses($n = 50, $offset = 0) {
1289 1289
 		global $wpdb;
1290 1290
 
1291
-		wp_defer_comment_counting( true );
1291
+		wp_defer_comment_counting(true);
1292 1292
 
1293
-		$user_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users " );
1293
+		$user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users ");
1294 1294
 
1295
-		if ( 0 == $user_count_result ) {
1295
+		if (0 == $user_count_result) {
1296 1296
 			return true;
1297 1297
 		}
1298 1298
 
1299
-		if ( 0 == $offset ) {
1299
+		if (0 == $offset) {
1300 1300
 			$current_page = 1;
1301 1301
 		} else {
1302
-			$current_page = intval( $offset / $n );
1302
+			$current_page = intval($offset / $n);
1303 1303
 		}
1304 1304
 
1305
-		$total_pages = ceil( $user_count_result / $n );
1305
+		$total_pages = ceil($user_count_result / $n);
1306 1306
 
1307 1307
 		// Get all Lesson => Course relationships
1308
-		$meta_list = $wpdb->get_results( "SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course'", ARRAY_A );
1308
+		$meta_list = $wpdb->get_results("SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course'", ARRAY_A);
1309 1309
 		$course_lesson_ids = array();
1310
-		if ( !empty($meta_list) ) {
1311
-			foreach ( $meta_list as $metarow ) {
1310
+		if ( ! empty($meta_list)) {
1311
+			foreach ($meta_list as $metarow) {
1312 1312
 				$lesson_id = $metarow['post_id'];
1313 1313
 				$course_id = $metarow['meta_value'];
1314
-				$course_lesson_ids[ $course_id ][] = $lesson_id;
1314
+				$course_lesson_ids[$course_id][] = $lesson_id;
1315 1315
 			}
1316 1316
 		}
1317 1317
 
@@ -1321,13 +1321,13 @@  discard block
 block discarded – undo
1321 1321
 		$check_existing_sql = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = 'sensei_course_status' ";
1322 1322
 
1323 1323
 		// $per_page users at a time, could be batch run via an admin ajax command, 1 user at a time?
1324
-		$user_ids = $wpdb->get_col( $wpdb->prepare($users_sql, $n, $offset) );
1324
+		$user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset));
1325 1325
 
1326
-		foreach ( $user_ids AS $user_id ) {
1326
+		foreach ($user_ids AS $user_id) {
1327 1327
 
1328 1328
 			// Grab all the course starts for the user
1329
-			$course_starts = $wpdb->get_results( $wpdb->prepare($start_sql, $user_id), ARRAY_A );
1330
-			foreach ( $course_starts as $course_log ) {
1329
+			$course_starts = $wpdb->get_results($wpdb->prepare($start_sql, $user_id), ARRAY_A);
1330
+			foreach ($course_starts as $course_log) {
1331 1331
 
1332 1332
 				$course_id = $course_log['comment_post_ID'];
1333 1333
 
@@ -1342,23 +1342,23 @@  discard block
 block discarded – undo
1342 1342
 					'percent' => 0,
1343 1343
 				);
1344 1344
 				// Check if the course has lessons
1345
-				if ( !empty( $course_lesson_ids[$course_id] ) ) {
1345
+				if ( ! empty($course_lesson_ids[$course_id])) {
1346 1346
 
1347 1347
 					$lessons_completed = 0;
1348
-					$total_lessons = count( $course_lesson_ids[ $course_id ] );
1348
+					$total_lessons = count($course_lesson_ids[$course_id]);
1349 1349
 
1350 1350
 					// Don't use prepare as we need to provide the id join
1351
-					$sql = sprintf($lessons_sql, $user_id, join(', ', $course_lesson_ids[ $course_id ]) );
1351
+					$sql = sprintf($lessons_sql, $user_id, join(', ', $course_lesson_ids[$course_id]));
1352 1352
 					// Get all lesson statuses for this Courses' lessons
1353
-					$lesson_statuses = $wpdb->get_results( $sql, ARRAY_A );
1353
+					$lesson_statuses = $wpdb->get_results($sql, ARRAY_A);
1354 1354
 					// Not enough lesson statuses, thus cannot be complete
1355
-					if ( $total_lessons > count($lesson_statuses) ) {
1355
+					if ($total_lessons > count($lesson_statuses)) {
1356 1356
 						$status = 'in-progress';
1357 1357
 					}
1358 1358
 					// Count each lesson to work out the overall percentage
1359
-					foreach ( $lesson_statuses as $lesson_status ) {
1359
+					foreach ($lesson_statuses as $lesson_status) {
1360 1360
 						$status_date = $lesson_status['comment_date'];
1361
-						switch ( $lesson_status['status'] ) {
1361
+						switch ($lesson_status['status']) {
1362 1362
 							case 'complete': // Lesson has no quiz/questions
1363 1363
 							case 'graded': // Lesson has quiz, but it's not important what the grade was
1364 1364
 							case 'passed':
@@ -1373,7 +1373,7 @@  discard block
 block discarded – undo
1373 1373
 						}
1374 1374
 					}
1375 1375
 					$meta_data['complete'] = $lessons_completed;
1376
-					$meta_data['percent'] = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) );
1376
+					$meta_data['percent'] = abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0));
1377 1377
 				}
1378 1378
 				else {
1379 1379
 					// Course has no lessons, therefore cannot be 'complete'
@@ -1390,26 +1390,26 @@  discard block
 block discarded – undo
1390 1390
 						'comment_author' => '',
1391 1391
 					);
1392 1392
 				// Check it doesn't already exist
1393
-				$sql = $wpdb->prepare( $check_existing_sql, $course_id, $user_id );
1394
-				$comment_ID = $wpdb->get_var( $sql );
1395
-				if ( !$comment_ID ) {
1393
+				$sql = $wpdb->prepare($check_existing_sql, $course_id, $user_id);
1394
+				$comment_ID = $wpdb->get_var($sql);
1395
+				if ( ! $comment_ID) {
1396 1396
 					// Bypassing WP wp_insert_comment( $data ), so no actions/filters are run
1397 1397
 					$wpdb->insert($wpdb->comments, $data);
1398 1398
 					$comment_ID = (int) $wpdb->insert_id;
1399 1399
 
1400
-					if ( $comment_ID && !empty($meta_data) ) {
1401
-						foreach ( $meta_data as $key => $value ) {
1400
+					if ($comment_ID && ! empty($meta_data)) {
1401
+						foreach ($meta_data as $key => $value) {
1402 1402
 							// Bypassing WP wp_insert_comment( $data ), so no actions/filters are run
1403
-							if ( $wpdb->get_var( $wpdb->prepare(
1403
+							if ($wpdb->get_var($wpdb->prepare(
1404 1404
 									"SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ",
1405
-									$comment_ID, $key ) ) ) {
1405
+									$comment_ID, $key ))) {
1406 1406
 									continue; // Found the meta data already
1407 1407
 							}
1408
-							$result = $wpdb->insert( $wpdb->commentmeta, array(
1408
+							$result = $wpdb->insert($wpdb->commentmeta, array(
1409 1409
 								'comment_id' => $comment_ID,
1410 1410
 								'meta_key' => $key,
1411 1411
 								'meta_value' => $value
1412
-							) );
1412
+							));
1413 1413
 						}
1414 1414
 					}
1415 1415
 				}
@@ -1417,7 +1417,7 @@  discard block
 block discarded – undo
1417 1417
 		}
1418 1418
 		$wpdb->flush();
1419 1419
 
1420
-		if ( $current_page == $total_pages ) {
1420
+		if ($current_page == $total_pages) {
1421 1421
 			return true;
1422 1422
 		} else {
1423 1423
 			return false;
@@ -1433,70 +1433,70 @@  discard block
 block discarded – undo
1433 1433
 	 * @param type $offset
1434 1434
 	 * @return boolean
1435 1435
 	 */
1436
-	function status_changes_repair_course_statuses( $n = 50, $offset = 0 ) {
1436
+	function status_changes_repair_course_statuses($n = 50, $offset = 0) {
1437 1437
 		global $wpdb;
1438 1438
 
1439
-		$count_object = wp_count_posts( 'lesson' );
1439
+		$count_object = wp_count_posts('lesson');
1440 1440
 		$count_published = $count_object->publish;
1441 1441
 
1442
-		if ( 0 == $count_published ) {
1442
+		if (0 == $count_published) {
1443 1443
 			return true;
1444 1444
 		}
1445 1445
 
1446 1446
 		// Calculate if this is the last page
1447
-		if ( 0 == $offset ) {
1447
+		if (0 == $offset) {
1448 1448
 			$current_page = 1;
1449 1449
 		} else {
1450
-			$current_page = intval( $offset / $n );
1450
+			$current_page = intval($offset / $n);
1451 1451
 		}
1452
-		$total_pages = ceil( $count_published / $n );
1452
+		$total_pages = ceil($count_published / $n);
1453 1453
 
1454 1454
 		$course_lesson_ids = $lesson_user_statuses = array();
1455 1455
 
1456 1456
 		// Get all Lesson => Course relationships
1457
-		$meta_list = $wpdb->get_results( "SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course' LIMIT $n OFFSET $offset ", ARRAY_A );
1458
-		if ( !empty($meta_list) ) {
1459
-			foreach ( $meta_list as $metarow ) {
1457
+		$meta_list = $wpdb->get_results("SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course' LIMIT $n OFFSET $offset ", ARRAY_A);
1458
+		if ( ! empty($meta_list)) {
1459
+			foreach ($meta_list as $metarow) {
1460 1460
 				$lesson_id = $metarow['post_id'];
1461 1461
 				$course_id = $metarow['meta_value'];
1462
-				$course_lesson_ids[ $course_id ][] = $lesson_id;
1462
+				$course_lesson_ids[$course_id][] = $lesson_id;
1463 1463
 			}
1464 1464
 		}
1465 1465
 
1466 1466
 		// Get all Lesson => Course relationships
1467
-		$status_list = $wpdb->get_results( "SELECT user_id, comment_post_ID, comment_approved FROM $wpdb->comments WHERE comment_type = 'sensei_lesson_status' GROUP BY user_id, comment_post_ID ", ARRAY_A );
1468
-		if ( !empty($status_list) ) {
1469
-			foreach ( $status_list as $status ) {
1470
-				$lesson_user_statuses[ $status['comment_post_ID'] ][ $status['user_id'] ] = $status['comment_approved'];
1467
+		$status_list = $wpdb->get_results("SELECT user_id, comment_post_ID, comment_approved FROM $wpdb->comments WHERE comment_type = 'sensei_lesson_status' GROUP BY user_id, comment_post_ID ", ARRAY_A);
1468
+		if ( ! empty($status_list)) {
1469
+			foreach ($status_list as $status) {
1470
+				$lesson_user_statuses[$status['comment_post_ID']][$status['user_id']] = $status['comment_approved'];
1471 1471
 			}
1472 1472
 		}
1473 1473
 
1474
-		$course_completion = Sensei()->settings->settings[ 'course_completion' ];
1474
+		$course_completion = Sensei()->settings->settings['course_completion'];
1475 1475
 
1476 1476
 		$per_page = 40;
1477 1477
 		$comment_id_offset = $count = 0;
1478 1478
 
1479 1479
 		$course_sql = "SELECT * FROM $wpdb->comments WHERE comment_type = 'sensei_course_status' AND comment_ID > %d LIMIT $per_page";
1480 1480
 		// $per_page users at a time
1481
-		while ( $course_statuses = $wpdb->get_results( $wpdb->prepare($course_sql, $comment_id_offset) ) ) {
1481
+		while ($course_statuses = $wpdb->get_results($wpdb->prepare($course_sql, $comment_id_offset))) {
1482 1482
 
1483
-			foreach ( $course_statuses AS $course_status ) {
1483
+			foreach ($course_statuses AS $course_status) {
1484 1484
 				$user_id = $course_status->user_id;
1485 1485
 				$course_id = $course_status->comment_post_ID;
1486
-				$total_lessons = count( $course_lesson_ids[ $course_id ] );
1487
-				if ( $total_lessons <= 0 ) {
1486
+				$total_lessons = count($course_lesson_ids[$course_id]);
1487
+				if ($total_lessons <= 0) {
1488 1488
 					$total_lessons = 1; // Fix division of zero error, some courses have no lessons
1489 1489
 				}
1490 1490
 				$lessons_completed = 0;
1491 1491
 				$status = 'in-progress';
1492 1492
 
1493 1493
 				// Some Courses have no lessons... (can they ever be complete?)
1494
-				if ( !empty($course_lesson_ids[ $course_id ]) ) {
1495
-					foreach( $course_lesson_ids[ $course_id ] AS $lesson_id ) {
1496
-						$lesson_status = $lesson_user_statuses[ $lesson_id ][ $user_id ];
1494
+				if ( ! empty($course_lesson_ids[$course_id])) {
1495
+					foreach ($course_lesson_ids[$course_id] AS $lesson_id) {
1496
+						$lesson_status = $lesson_user_statuses[$lesson_id][$user_id];
1497 1497
 						// If lessons are complete without needing quizzes to be passed
1498
-						if ( 'passed' != $course_completion ) {
1499
-							switch ( $lesson_status ) {
1498
+						if ('passed' != $course_completion) {
1499
+							switch ($lesson_status) {
1500 1500
 								// A user cannot 'complete' a course if a lesson...
1501 1501
 								case 'in-progress': // ...is still in progress
1502 1502
 								case 'ungraded': // ...hasn't yet been graded
@@ -1508,7 +1508,7 @@  discard block
 block discarded – undo
1508 1508
 							}
1509 1509
 						}
1510 1510
 						else {
1511
-							switch ( $lesson_status ) {
1511
+							switch ($lesson_status) {
1512 1512
 								case 'complete': // Lesson has no quiz/questions
1513 1513
 								case 'graded': // Lesson has quiz, but it's not important what the grade was
1514 1514
 								case 'passed': // Lesson has quiz and the user passed
@@ -1523,79 +1523,79 @@  discard block
 block discarded – undo
1523 1523
 						}
1524 1524
 					} // Each lesson
1525 1525
 				} // Check for lessons
1526
-				if ( $lessons_completed == $total_lessons ) {
1526
+				if ($lessons_completed == $total_lessons) {
1527 1527
 					$status = 'complete';
1528 1528
 				}
1529 1529
 				// update the overall percentage of the course lessons complete (or graded) compared to 'in-progress' regardless of the above
1530 1530
 				$metadata = array(
1531 1531
 					'complete' => $lessons_completed,
1532
-					'percent' => abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) ),
1532
+					'percent' => abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0)),
1533 1533
 				);
1534
-				WooThemes_Sensei_Utils::update_course_status( $user_id, $course_id, $status, $metadata );
1534
+				WooThemes_Sensei_Utils::update_course_status($user_id, $course_id, $status, $metadata);
1535 1535
 				$count++;
1536 1536
 
1537 1537
 			} // per course status
1538 1538
 			$comment_id_offset = $course_status->comment_ID;
1539 1539
 		} // all course statuses
1540 1540
 
1541
-		if ( $current_page == $total_pages ) {
1541
+		if ($current_page == $total_pages) {
1542 1542
 			return true;
1543 1543
 		} else {
1544 1544
 			return false;
1545 1545
 		}
1546 1546
 	}
1547 1547
 
1548
-	function status_changes_convert_questions( $n = 50, $offset = 0 ) {
1548
+	function status_changes_convert_questions($n = 50, $offset = 0) {
1549 1549
 		global $wpdb;
1550 1550
 
1551
-		wp_defer_comment_counting( true );
1551
+		wp_defer_comment_counting(true);
1552 1552
 
1553
-		$user_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users " );
1553
+		$user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users ");
1554 1554
 
1555
-		if ( 0 == $user_count_result ) {
1555
+		if (0 == $user_count_result) {
1556 1556
 			return true;
1557 1557
 		}
1558 1558
 
1559 1559
 		// Calculate if this is the last page
1560
-		if ( 0 == $offset ) {
1560
+		if (0 == $offset) {
1561 1561
 			$current_page = 1;
1562 1562
 		} else {
1563
-			$current_page = intval( $offset / $n );
1563
+			$current_page = intval($offset / $n);
1564 1564
 		}
1565 1565
 
1566
-		$total_pages = ceil( $user_count_result / $n );
1566
+		$total_pages = ceil($user_count_result / $n);
1567 1567
 
1568 1568
 		$users_sql = "SELECT ID FROM $wpdb->users ORDER BY ID ASC LIMIT %d OFFSET %d";
1569 1569
 		$answers_sql = "SELECT * FROM $wpdb->comments WHERE comment_type = 'sensei_user_answer' AND user_id = %d GROUP BY comment_post_ID ";
1570 1570
 		$grades_sql = "SELECT comment_post_ID, comment_content FROM $wpdb->comments WHERE comment_type = 'sensei_user_grade' AND user_id = %d GROUP BY comment_post_ID ";
1571 1571
 		$notes_sql = "SELECT comment_post_ID, comment_content FROM $wpdb->comments WHERE comment_type = 'sensei_answer_notes' AND user_id = %d GROUP BY comment_post_ID ";
1572 1572
 
1573
-		$user_ids = $wpdb->get_col( $wpdb->prepare($users_sql, $n, $offset) );
1573
+		$user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset));
1574 1574
 
1575
-		foreach ( $user_ids AS $user_id ) {
1575
+		foreach ($user_ids AS $user_id) {
1576 1576
 
1577 1577
 			$answer_grades = $answer_notes = array();
1578 1578
 
1579 1579
 			// Pre-process the answer grades
1580
-			$_answer_grades = $wpdb->get_results( $wpdb->prepare($grades_sql, $user_id), ARRAY_A );
1581
-			foreach ( $_answer_grades as $answer_grade ) {
1580
+			$_answer_grades = $wpdb->get_results($wpdb->prepare($grades_sql, $user_id), ARRAY_A);
1581
+			foreach ($_answer_grades as $answer_grade) {
1582 1582
 				// This will overwrite existing entries with the newer ones
1583
-				$answer_grades[ $answer_grade['comment_post_ID'] ] = $answer_grade['comment_content'];
1583
+				$answer_grades[$answer_grade['comment_post_ID']] = $answer_grade['comment_content'];
1584 1584
 			}
1585
-			unset( $_answer_grades );
1585
+			unset($_answer_grades);
1586 1586
 
1587 1587
 			// Pre-process the answer notes
1588
-			$_answer_notes = $wpdb->get_results( $wpdb->prepare($notes_sql, $user_id), ARRAY_A );
1589
-			foreach ( $_answer_notes as $answer_note ) {
1588
+			$_answer_notes = $wpdb->get_results($wpdb->prepare($notes_sql, $user_id), ARRAY_A);
1589
+			foreach ($_answer_notes as $answer_note) {
1590 1590
 				// This will overwrite existing entries with the newer ones
1591
-				$answer_notes[ $answer_note['comment_post_ID'] ] = $answer_note['comment_content'];
1591
+				$answer_notes[$answer_note['comment_post_ID']] = $answer_note['comment_content'];
1592 1592
 			}
1593
-			unset( $_answer_notes );
1593
+			unset($_answer_notes);
1594 1594
 
1595 1595
 			// Grab all the questions for the user
1596 1596
 			$sql = $wpdb->prepare($answers_sql, $user_id);
1597
-			$answers = $wpdb->get_results( $sql, ARRAY_A );
1598
-			foreach ( $answers as $answer ) {
1597
+			$answers = $wpdb->get_results($sql, ARRAY_A);
1598
+			foreach ($answers as $answer) {
1599 1599
 
1600 1600
 				// Excape data
1601 1601
 				$answer = wp_slash($answer);
@@ -1605,12 +1605,12 @@  discard block
 block discarded – undo
1605 1605
 				$meta_data = array();
1606 1606
 
1607 1607
 				// Check if the question has been graded, add as meta
1608
-				if ( !empty($answer_grades[ $answer['comment_post_ID'] ]) ) {
1609
-					$meta_data['user_grade'] = $answer_grades[ $answer['comment_post_ID'] ];
1608
+				if ( ! empty($answer_grades[$answer['comment_post_ID']])) {
1609
+					$meta_data['user_grade'] = $answer_grades[$answer['comment_post_ID']];
1610 1610
 				}
1611 1611
 				// Check if there is an answer note, add as meta
1612
-				if ( !empty($answer_notes[ $answer['comment_post_ID'] ]) ) {
1613
-					$meta_data['answer_note'] = $answer_notes[ $answer['comment_post_ID'] ];
1612
+				if ( ! empty($answer_notes[$answer['comment_post_ID']])) {
1613
+					$meta_data['answer_note'] = $answer_notes[$answer['comment_post_ID']];
1614 1614
 				}
1615 1615
 
1616 1616
 				// Wipe the unnessary data from the main comment
@@ -1623,21 +1623,21 @@  discard block
 block discarded – undo
1623 1623
 					);
1624 1624
 				$data = array_merge($answer, $data);
1625 1625
 
1626
-				$rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) );
1627
-				if ( $rval ) {
1628
-					if ( !empty($meta_data) ) {
1629
-						foreach ( $meta_data as $key => $value ) {
1626
+				$rval = $wpdb->update($wpdb->comments, $data, compact('comment_ID'));
1627
+				if ($rval) {
1628
+					if ( ! empty($meta_data)) {
1629
+						foreach ($meta_data as $key => $value) {
1630 1630
 							// Bypassing WP wp_insert_comment( $data ), so no actions/filters are run
1631
-							if ( $wpdb->get_var( $wpdb->prepare(
1631
+							if ($wpdb->get_var($wpdb->prepare(
1632 1632
 									"SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ",
1633
-									$comment_ID, $key ) ) ) {
1633
+									$comment_ID, $key ))) {
1634 1634
 									continue; // Found the meta data already
1635 1635
 							}
1636
-							$result = $wpdb->insert( $wpdb->commentmeta, array(
1636
+							$result = $wpdb->insert($wpdb->commentmeta, array(
1637 1637
 								'comment_id' => $comment_ID,
1638 1638
 								'meta_key' => $key,
1639 1639
 								'meta_value' => $value
1640
-							) );
1640
+							));
1641 1641
 						}
1642 1642
 					}
1643 1643
 				}
@@ -1645,7 +1645,7 @@  discard block
 block discarded – undo
1645 1645
 		}
1646 1646
 		$wpdb->flush();
1647 1647
 
1648
-		if ( $current_page == $total_pages ) {
1648
+		if ($current_page == $total_pages) {
1649 1649
 			return true;
1650 1650
 		} else {
1651 1651
 			return false;
@@ -1662,10 +1662,10 @@  discard block
 block discarded – undo
1662 1662
 		global $wpdb;
1663 1663
 
1664 1664
 		// Update 'sensei_user_answer' entries to use comment_approved = 'log' so they don't appear in counts
1665
-		$wpdb->query( "UPDATE $wpdb->comments SET comment_approved = 'log' WHERE comment_type = 'sensei_user_answer' " );
1665
+		$wpdb->query("UPDATE $wpdb->comments SET comment_approved = 'log' WHERE comment_type = 'sensei_user_answer' ");
1666 1666
 
1667 1667
 		// Mark all old Sensei comment types with comment_approved = 'legacy' so they no longer appear in counts, but can be restored if required
1668
-		$wpdb->query( "UPDATE $wpdb->comments SET comment_approved = 'legacy' WHERE comment_type IN ('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_answer_notes', 'sensei_quiz_grade') " );
1668
+		$wpdb->query("UPDATE $wpdb->comments SET comment_approved = 'legacy' WHERE comment_type IN ('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_answer_notes', 'sensei_quiz_grade') ");
1669 1669
 
1670 1670
 		return true;
1671 1671
 	}
@@ -1678,50 +1678,50 @@  discard block
 block discarded – undo
1678 1678
 	 * @param type $offset
1679 1679
 	 * @return boolean
1680 1680
 	 */
1681
-	public function update_comment_course_lesson_comment_counts( $n = 50, $offset = 0 ) {
1681
+	public function update_comment_course_lesson_comment_counts($n = 50, $offset = 0) {
1682 1682
 		global $wpdb;
1683 1683
 
1684
-		$item_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') " );
1684
+		$item_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') ");
1685 1685
 
1686
-		if ( 0 == $item_count_result ) {
1686
+		if (0 == $item_count_result) {
1687 1687
 			return true;
1688 1688
 		}
1689 1689
 
1690 1690
 		// Calculate if this is the last page
1691
-		if ( 0 == $offset ) {
1691
+		if (0 == $offset) {
1692 1692
 			$current_page = 1;
1693 1693
 		} else {
1694
-			$current_page = intval( $offset / $n );
1694
+			$current_page = intval($offset / $n);
1695 1695
 		}
1696 1696
 
1697
-		$total_pages = ceil( $item_count_result / $n );
1697
+		$total_pages = ceil($item_count_result / $n);
1698 1698
 
1699 1699
 		// Recalculate all counts
1700
-		$items = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') LIMIT %d OFFSET %d", $n, $offset ) );
1701
-		foreach ( (array) $items as $post ) {
1700
+		$items = $wpdb->get_results($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') LIMIT %d OFFSET %d", $n, $offset));
1701
+		foreach ((array) $items as $post) {
1702 1702
 			// Code copied from wp_update_comment_count_now()
1703
-			$new = (int) $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post->ID) );
1704
-			$wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post->ID) );
1703
+			$new = (int) $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post->ID));
1704
+			$wpdb->update($wpdb->posts, array('comment_count' => $new), array('ID' => $post->ID));
1705 1705
 
1706
-			clean_post_cache( $post->ID );
1706
+			clean_post_cache($post->ID);
1707 1707
 		}
1708 1708
 
1709
-		if ( $current_page == $total_pages ) {
1709
+		if ($current_page == $total_pages) {
1710 1710
 			return true;
1711 1711
 		} else {
1712 1712
 			return false;
1713 1713
 		}
1714 1714
 	}
1715 1715
 
1716
-	public function remove_legacy_comments () {
1716
+	public function remove_legacy_comments() {
1717 1717
 		global $wpdb;
1718 1718
 
1719
-		$result = $wpdb->delete( $wpdb->comments, array( 'comment_approved' => 'legacy' ) );
1719
+		$result = $wpdb->delete($wpdb->comments, array('comment_approved' => 'legacy'));
1720 1720
 
1721 1721
 		return true;
1722 1722
 	}
1723 1723
 
1724
-	public function index_comment_status_field () {
1724
+	public function index_comment_status_field() {
1725 1725
 		global $wpdb;
1726 1726
 
1727 1727
 		$wpdb->query("ALTER TABLE `$wpdb->comments` ADD INDEX `comment_type` ( `comment_type` )");
@@ -1740,7 +1740,7 @@  discard block
 block discarded – undo
1740 1740
      * @since 1.8.0
1741 1741
      * @return bool;
1742 1742
      */
1743
-    public  function enhance_teacher_role ( ) {
1743
+    public  function enhance_teacher_role( ) {
1744 1744
 
1745 1745
         require_once('class-sensei-teacher.php');
1746 1746
         $teacher = new Sensei_Teacher();
Please login to merge, or discard this patch.
Braces   +44 added lines, -26 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Updates Class
@@ -769,9 +772,15 @@  discard block
 block discarded – undo
769 772
 		$all_activity = get_comments( array( 'status' => 'approve' ) );
770 773
 		$activity_count = array();
771 774
 		foreach( $all_activity as $activity ) {
772
-			if( '' == $activity->comment_type ) continue;
773
-			if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue;
774
-			if( 0 == $activity->user_id ) continue;
775
+			if( '' == $activity->comment_type ) {
776
+				continue;
777
+			}
778
+			if( strpos( 'sensei_', $activity->comment_type ) != 0 ) {
779
+				continue;
780
+			}
781
+			if( 0 == $activity->user_id ) {
782
+				continue;
783
+			}
775 784
 			$activity_count[] = $activity->comment_ID;
776 785
 		}
777 786
 
@@ -784,9 +793,15 @@  discard block
 block discarded – undo
784 793
 		$activities = get_comments( $args );
785 794
 
786 795
 		foreach( $activities as $activity ) {
787
-			if( '' == $activity->comment_type ) continue;
788
-			if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue;
789
-			if( 0 == $activity->user_id ) continue;
796
+			if( '' == $activity->comment_type ) {
797
+				continue;
798
+			}
799
+			if( strpos( 'sensei_', $activity->comment_type ) != 0 ) {
800
+				continue;
801
+			}
802
+			if( 0 == $activity->user_id ) {
803
+				continue;
804
+			}
790 805
 
791 806
 			$user_exists = get_userdata( $activity->user_id );
792 807
 
@@ -845,7 +860,9 @@  discard block
 block discarded – undo
845 860
 
846 861
 		foreach( $questions as $question ) {
847 862
 
848
-			if( ! isset( $question->ID ) ) continue;
863
+			if( ! isset( $question->ID ) ) {
864
+				continue;
865
+			}
849 866
 
850 867
 			$quiz_id = get_post_meta( $question->ID, '_quiz_id', true );
851 868
 
@@ -882,7 +899,9 @@  discard block
 block discarded – undo
882 899
 
883 900
 		foreach( $quizzes as $quiz ) {
884 901
 
885
-			if( ! isset( $quiz->ID ) ) continue;
902
+			if( ! isset( $quiz->ID ) ) {
903
+				continue;
904
+			}
886 905
 
887 906
 			if( isset( $lesson_completion ) && 'passed' == $lesson_completion ) {
888 907
 				update_post_meta( $quiz->ID, '_pass_required', 'on' );
@@ -910,7 +929,9 @@  discard block
 block discarded – undo
910 929
 
911 930
 		foreach( $lessons as $lesson ) {
912 931
 
913
-			if( ! isset( $lesson->ID ) ) continue;
932
+			if( ! isset( $lesson->ID ) ) {
933
+				continue;
934
+			}
914 935
 
915 936
 			$course_id = get_post_meta( $lesson->ID, '_lesson_course', true);
916 937
 
@@ -984,11 +1005,15 @@  discard block
 block discarded – undo
984 1005
 
985 1006
 		foreach( $quizzes as $quiz ) {
986 1007
 
987
-			if( ! isset( $quiz->ID ) || 0 != $quiz->post_parent ) continue;
1008
+			if( ! isset( $quiz->ID ) || 0 != $quiz->post_parent ) {
1009
+				continue;
1010
+			}
988 1011
 
989 1012
 			$lesson_id = get_post_meta( $quiz->ID, '_quiz_lesson', true );
990 1013
 
991
-			if( empty( $lesson_id ) ) continue;
1014
+			if( empty( $lesson_id ) ) {
1015
+				continue;
1016
+			}
992 1017
 
993 1018
 			$data = array(
994 1019
 				'ID' => $quiz->ID,
@@ -1071,8 +1096,7 @@  discard block
 block discarded – undo
1071 1096
 				delete_post_meta( $quiz_id, '_quiz_passmark' );
1072 1097
 				delete_post_meta( $lesson_id, '_quiz_has_questions' );
1073 1098
 				$d_count++;
1074
-			}
1075
-			else if ( in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) {
1099
+			} else if ( in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) {
1076 1100
 
1077 1101
 				// Quiz has no questions, drop the corresponding data
1078 1102
 				update_post_meta( $lesson_id, '_quiz_has_questions', true );
@@ -1222,20 +1246,16 @@  discard block
 block discarded – undo
1222 1246
 							// Check if the user has to get the passmark and has or not
1223 1247
 							if ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] <= $quiz_grade ) {
1224 1248
 								$status = 'passed';
1225
-							}
1226
-							elseif ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] > $quiz_grade ) {
1249
+							} elseif ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] > $quiz_grade ) {
1227 1250
 								$status = 'failed';
1228
-							}
1229
-							else {
1251
+							} else {
1230 1252
 								$status = 'graded';
1231 1253
 							}
1232
-						}
1233
-						else {
1254
+						} else {
1234 1255
 							// If the lesson has a quiz, but the user doesn't have a grade, it's not yet been graded
1235 1256
 							$status = 'ungraded';
1236 1257
 						}
1237
-					}
1238
-					else {
1258
+					} else {
1239 1259
 						// Lesson has no quiz, so it can only ever be this status
1240 1260
 						$status = 'complete';
1241 1261
 					}
@@ -1374,8 +1394,7 @@  discard block
 block discarded – undo
1374 1394
 					}
1375 1395
 					$meta_data['complete'] = $lessons_completed;
1376 1396
 					$meta_data['percent'] = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) );
1377
-				}
1378
-				else {
1397
+				} else {
1379 1398
 					// Course has no lessons, therefore cannot be 'complete'
1380 1399
 					$status = 'in-progress';
1381 1400
 				}
@@ -1506,8 +1525,7 @@  discard block
 block discarded – undo
1506 1525
 									$lessons_completed++;
1507 1526
 									break;
1508 1527
 							}
1509
-						}
1510
-						else {
1528
+						} else {
1511 1529
 							switch ( $lesson_status ) {
1512 1530
 								case 'complete': // Lesson has no quiz/questions
1513 1531
 								case 'graded': // Lesson has quiz, but it's not important what the grade was
Please login to merge, or discard this patch.
includes/sensei-functions.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -178,8 +178,8 @@
 block discarded – undo
178 178
  *
179 179
  * @since 1.9.0
180 180
  *
181
- * @param $hook_tag
182
- * @param $version
181
+ * @param string $hook_tag
182
+ * @param string $version
183 183
  * @param $alternative
184 184
  * @param array $args
185 185
  */
Please login to merge, or discard this patch.
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -40,16 +40,16 @@  discard block
 block discarded – undo
40 40
  */
41 41
 function sensei_all_access() {
42 42
 
43
-    $access = current_user_can( 'manage_sensei' ) || current_user_can( 'manage_sensei_grades' );
44
-
45
-    /**
46
-     * Filter sensei_all_access function result
47
-     * which determinse if the current user
48
-     * can access all of Sensei without restrictions
49
-     *
50
-     * @since 1.4.0
51
-     * @param bool $access
52
-     */
43
+	$access = current_user_can( 'manage_sensei' ) || current_user_can( 'manage_sensei_grades' );
44
+
45
+	/**
46
+	 * Filter sensei_all_access function result
47
+	 * which determinse if the current user
48
+	 * can access all of Sensei without restrictions
49
+	 *
50
+	 * @since 1.4.0
51
+	 * @param bool $access
52
+	 */
53 53
 	return apply_filters( 'sensei_all_access', $access );
54 54
 
55 55
 } // End sensei_all_access()
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	 */
68 68
 	function sensei_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
69 69
 
70
-	    $hex = str_replace( '#', '', $color );
70
+		$hex = str_replace( '#', '', $color );
71 71
 
72 72
 		$c_r = hexdec( substr( $hex, 0, 2 ) );
73 73
 		$c_g = hexdec( substr( $hex, 2, 2 ) );
@@ -114,15 +114,15 @@  discard block
 block discarded – undo
114 114
 		$color = '#';
115 115
 
116 116
 		foreach ($base as $k => $v) :
117
-	        $amount = $v / 100;
118
-	        $amount = round($amount * $factor);
119
-	        $new_decimal = $v - $amount;
120
-
121
-	        $new_hex_component = dechex($new_decimal);
122
-	        if(strlen($new_hex_component) < 2) :
123
-	        	$new_hex_component = "0".$new_hex_component;
124
-	        endif;
125
-	        $color .= $new_hex_component;
117
+			$amount = $v / 100;
118
+			$amount = round($amount * $factor);
119
+			$new_decimal = $v - $amount;
120
+
121
+			$new_hex_component = dechex($new_decimal);
122
+			if(strlen($new_hex_component) < 2) :
123
+				$new_hex_component = "0".$new_hex_component;
124
+			endif;
125
+			$color .= $new_hex_component;
126 126
 		endforeach;
127 127
 
128 128
 		return $color;
@@ -143,17 +143,17 @@  discard block
 block discarded – undo
143 143
 		$base = sensei_rgb_from_hex( $color );
144 144
 		$color = '#';
145 145
 
146
-	    foreach ($base as $k => $v) :
147
-	        $amount = 255 - $v;
148
-	        $amount = $amount / 100;
149
-	        $amount = round($amount * $factor);
150
-	        $new_decimal = $v + $amount;
151
-
152
-	        $new_hex_component = dechex($new_decimal);
153
-	        if(strlen($new_hex_component) < 2) :
154
-	        	$new_hex_component = "0".$new_hex_component;
155
-	        endif;
156
-	        $color .= $new_hex_component;
146
+		foreach ($base as $k => $v) :
147
+			$amount = 255 - $v;
148
+			$amount = $amount / 100;
149
+			$amount = round($amount * $factor);
150
+			$new_decimal = $v + $amount;
151
+
152
+			$new_hex_component = dechex($new_decimal);
153
+			if(strlen($new_hex_component) < 2) :
154
+				$new_hex_component = "0".$new_hex_component;
155
+			endif;
156
+			$color .= $new_hex_component;
157 157
 	   	endforeach;
158 158
 
159 159
 	   	return $color;
@@ -167,9 +167,9 @@  discard block
 block discarded – undo
167 167
  * @deprecated since 1.9.0 * It is better to call the Sensei_WC::is_woocommerce_active() directly
168 168
  */
169 169
 if ( ! function_exists( 'is_woocommerce_active' ) ) {
170
-    function is_woocommerce_active() {
171
-        return Sensei_WC::is_woocommerce_active();
172
-    }
170
+	function is_woocommerce_active() {
171
+		return Sensei_WC::is_woocommerce_active();
172
+	}
173 173
 }
174 174
 
175 175
 /**
@@ -185,20 +185,20 @@  discard block
 block discarded – undo
185 185
  */
186 186
 function sensei_do_deprecated_action( $hook_tag, $version, $alternative="" , $args = array()  ){
187 187
 
188
-    if( has_action( $hook_tag ) ){
188
+	if( has_action( $hook_tag ) ){
189 189
 
190
-        $error_message = sprintf( __( "SENSEI: The hook '%s', has been deprecated since '%s'." , 'woothemes-sensei'), $hook_tag ,$version );
190
+		$error_message = sprintf( __( "SENSEI: The hook '%s', has been deprecated since '%s'." , 'woothemes-sensei'), $hook_tag ,$version );
191 191
 
192
-        if( !empty( $alternative ) ){
192
+		if( !empty( $alternative ) ){
193 193
 
194
-            $error_message .= sprintf( __("Please use '%s' instead.", 'woothemes-sensei'), $alternative ) ;
194
+			$error_message .= sprintf( __("Please use '%s' instead.", 'woothemes-sensei'), $alternative ) ;
195 195
 
196
-        }
196
+		}
197 197
 
198
-        trigger_error( $error_message );
199
-        do_action( $hook_tag , $args );
198
+		trigger_error( $error_message );
199
+		do_action( $hook_tag , $args );
200 200
 
201
-    }
201
+	}
202 202
 
203 203
 }// end sensei_do_deprecated_action
204 204
 
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
4 4
 
5 5
 /**
6 6
  * Global Sensei functions
@@ -11,24 +11,24 @@  discard block
 block discarded – undo
11 11
 
12 12
 	$is_sensei = false;
13 13
 
14
-	$post_types = array( 'lesson', 'course', 'quiz', 'question' );
15
-	$taxonomies = array( 'course-category', 'quiz-type', 'question-type', 'lesson-tag' );
14
+	$post_types = array('lesson', 'course', 'quiz', 'question');
15
+	$taxonomies = array('course-category', 'quiz-type', 'question-type', 'lesson-tag');
16 16
 
17
-	if( is_post_type_archive( $post_types ) || is_singular( $post_types ) || is_tax( $taxonomies ) ) {
17
+	if (is_post_type_archive($post_types) || is_singular($post_types) || is_tax($taxonomies)) {
18 18
 		$is_sensei = true;
19 19
 	}
20 20
 
21
-	if( is_object( $post ) && ! is_wp_error( $post ) ) {
21
+	if (is_object($post) && ! is_wp_error($post)) {
22 22
 
23
-		$course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] );
24
-		$my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
23
+		$course_page_id = intval(Sensei()->settings->settings['course_page']);
24
+		$my_courses_page_id = intval(Sensei()->settings->settings['my_course_page']);
25 25
 
26
-		if( in_array( $post->ID, array( $course_page_id, $my_courses_page_id ) ) ) {
26
+		if (in_array($post->ID, array($course_page_id, $my_courses_page_id))) {
27 27
 			$is_sensei = true;
28 28
 		}
29 29
 	}
30 30
 
31
-	return apply_filters( 'is_sensei', $is_sensei, $post );
31
+	return apply_filters('is_sensei', $is_sensei, $post);
32 32
 }
33 33
 
34 34
 /**
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
  */
41 41
 function sensei_all_access() {
42 42
 
43
-    $access = current_user_can( 'manage_sensei' ) || current_user_can( 'manage_sensei_grades' );
43
+    $access = current_user_can('manage_sensei') || current_user_can('manage_sensei_grades');
44 44
 
45 45
     /**
46 46
      * Filter sensei_all_access function result
@@ -50,11 +50,11 @@  discard block
 block discarded – undo
50 50
      * @since 1.4.0
51 51
      * @param bool $access
52 52
      */
53
-	return apply_filters( 'sensei_all_access', $access );
53
+	return apply_filters('sensei_all_access', $access);
54 54
 
55 55
 } // End sensei_all_access()
56 56
 
57
-if ( ! function_exists( 'sensei_light_or_dark' ) ) {
57
+if ( ! function_exists('sensei_light_or_dark')) {
58 58
 
59 59
 	/**
60 60
 	 * Detect if we should use a light or dark colour on a background colour
@@ -65,20 +65,20 @@  discard block
 block discarded – undo
65 65
 	 * @param string $light (default: '#FFFFFF')
66 66
 	 * @return string
67 67
 	 */
68
-	function sensei_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
68
+	function sensei_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
69 69
 
70
-	    $hex = str_replace( '#', '', $color );
70
+	    $hex = str_replace('#', '', $color);
71 71
 
72
-		$c_r = hexdec( substr( $hex, 0, 2 ) );
73
-		$c_g = hexdec( substr( $hex, 2, 2 ) );
74
-		$c_b = hexdec( substr( $hex, 4, 2 ) );
75
-		$brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
72
+		$c_r = hexdec(substr($hex, 0, 2));
73
+		$c_g = hexdec(substr($hex, 2, 2));
74
+		$c_b = hexdec(substr($hex, 4, 2));
75
+		$brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
76 76
 
77 77
 		return $brightness > 155 ? $dark : $light;
78 78
 	}
79 79
 }
80 80
 
81
-if ( ! function_exists( 'sensei_rgb_from_hex' ) ) {
81
+if ( ! function_exists('sensei_rgb_from_hex')) {
82 82
 
83 83
 	/**
84 84
 	 * Hex darker/lighter/contrast functions for colours
@@ -87,19 +87,19 @@  discard block
 block discarded – undo
87 87
 	 * @param mixed $color
88 88
 	 * @return string
89 89
 	 */
90
-	function sensei_rgb_from_hex( $color ) {
91
-		$color = str_replace( '#', '', $color );
90
+	function sensei_rgb_from_hex($color) {
91
+		$color = str_replace('#', '', $color);
92 92
 		// Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
93
-		$color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
93
+		$color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
94 94
 
95
-		$rgb['R'] = hexdec( $color{0}.$color{1} );
96
-		$rgb['G'] = hexdec( $color{2}.$color{3} );
97
-		$rgb['B'] = hexdec( $color{4}.$color{5} );
95
+		$rgb['R'] = hexdec($color{0}.$color{1} );
96
+		$rgb['G'] = hexdec($color{2}.$color{3} );
97
+		$rgb['B'] = hexdec($color{4}.$color{5} );
98 98
 		return $rgb;
99 99
 	}
100 100
 }
101 101
 
102
-if ( ! function_exists( 'sensei_hex_darker' ) ) {
102
+if ( ! function_exists('sensei_hex_darker')) {
103 103
 
104 104
 	/**
105 105
 	 * Hex darker/lighter/contrast functions for colours
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
 	 * @param int $factor (default: 30)
110 110
 	 * @return string
111 111
 	 */
112
-	function sensei_hex_darker( $color, $factor = 30 ) {
113
-		$base = sensei_rgb_from_hex( $color );
112
+	function sensei_hex_darker($color, $factor = 30) {
113
+		$base = sensei_rgb_from_hex($color);
114 114
 		$color = '#';
115 115
 
116 116
 		foreach ($base as $k => $v) :
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	        $new_decimal = $v - $amount;
120 120
 
121 121
 	        $new_hex_component = dechex($new_decimal);
122
-	        if(strlen($new_hex_component) < 2) :
122
+	        if (strlen($new_hex_component) < 2) :
123 123
 	        	$new_hex_component = "0".$new_hex_component;
124 124
 	        endif;
125 125
 	        $color .= $new_hex_component;
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 	}
130 130
 }
131 131
 
132
-if ( ! function_exists( 'sensei_hex_lighter' ) ) {
132
+if ( ! function_exists('sensei_hex_lighter')) {
133 133
 
134 134
 	/**
135 135
 	 * Hex darker/lighter/contrast functions for colours
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
 	 * @param int $factor (default: 30)
140 140
 	 * @return string
141 141
 	 */
142
-	function sensei_hex_lighter( $color, $factor = 30 ) {
143
-		$base = sensei_rgb_from_hex( $color );
142
+	function sensei_hex_lighter($color, $factor = 30) {
143
+		$base = sensei_rgb_from_hex($color);
144 144
 		$color = '#';
145 145
 
146 146
 	    foreach ($base as $k => $v) :
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	        $new_decimal = $v + $amount;
151 151
 
152 152
 	        $new_hex_component = dechex($new_decimal);
153
-	        if(strlen($new_hex_component) < 2) :
153
+	        if (strlen($new_hex_component) < 2) :
154 154
 	        	$new_hex_component = "0".$new_hex_component;
155 155
 	        endif;
156 156
 	        $color .= $new_hex_component;
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
  * @since 1.9.0
167 167
  * @deprecated since 1.9.0 * It is better to call the Sensei_WC::is_woocommerce_active() directly
168 168
  */
169
-if ( ! function_exists( 'is_woocommerce_active' ) ) {
169
+if ( ! function_exists('is_woocommerce_active')) {
170 170
     function is_woocommerce_active() {
171 171
         return Sensei_WC::is_woocommerce_active();
172 172
     }
@@ -183,20 +183,20 @@  discard block
 block discarded – undo
183 183
  * @param $alternative
184 184
  * @param array $args
185 185
  */
186
-function sensei_do_deprecated_action( $hook_tag, $version, $alternative="" , $args = array()  ){
186
+function sensei_do_deprecated_action($hook_tag, $version, $alternative = "", $args = array()) {
187 187
 
188
-    if( has_action( $hook_tag ) ){
188
+    if (has_action($hook_tag)) {
189 189
 
190
-        $error_message = sprintf( __( "SENSEI: The hook '%s', has been deprecated since '%s'." , 'woothemes-sensei'), $hook_tag ,$version );
190
+        $error_message = sprintf(__("SENSEI: The hook '%s', has been deprecated since '%s'.", 'woothemes-sensei'), $hook_tag, $version);
191 191
 
192
-        if( !empty( $alternative ) ){
192
+        if ( ! empty($alternative)) {
193 193
 
194
-            $error_message .= sprintf( __("Please use '%s' instead.", 'woothemes-sensei'), $alternative ) ;
194
+            $error_message .= sprintf(__("Please use '%s' instead.", 'woothemes-sensei'), $alternative);
195 195
 
196 196
         }
197 197
 
198
-        trigger_error( $error_message );
199
-        do_action( $hook_tag , $args );
198
+        trigger_error($error_message);
199
+        do_action($hook_tag, $args);
200 200
 
201 201
     }
202 202
 
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
  * @param $post_id
212 212
  * @return bool
213 213
  */
214
-function sensei_is_a_course( $post ){
214
+function sensei_is_a_course($post) {
215 215
 
216
-	return "course" == get_post_type( $post );
216
+	return "course" == get_post_type($post);
217 217
 
218 218
 }
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Analysis User Profile List Table Class
Please login to merge, or discard this patch.
includes/shortcodes/class-sensei-legacy-shortcodes.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -103,8 +103,8 @@
 block discarded – undo
103 103
      *
104 104
      * @since 1.9.0
105 105
      *
106
-     * @param $title
107
-     * @param $shortcode_specific_override
106
+     * @param string $title
107
+     * @param string $shortcode_specific_override
108 108
      * @return string
109 109
      */
110 110
     public static function generate_shortcode_courses( $title , $shortcode_specific_override  ){
Please login to merge, or discard this patch.
Indentation   +249 added lines, -249 removed lines patch added patch discarded remove patch
@@ -10,323 +10,323 @@  discard block
 block discarded – undo
10 10
  */
11 11
 class Sensei_Legacy_Shortcodes {
12 12
 
13
-    /**
14
-     * Add the legacy shortcodes to WordPress
15
-     *
16
-     * @since 1.9.0
17
-     */
18
-    public static function init(){
19
-
20
-        add_shortcode( 'allcourses',      array( __CLASS__, 'all_courses' ) );
21
-        add_shortcode( 'newcourses',      array( __CLASS__,'new_courses' ) );
22
-        add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') );
23
-        add_shortcode( 'freecourses',     array( __CLASS__,'free_courses') );
24
-        add_shortcode( 'paidcourses',     array( __CLASS__,'paid_courses') );
25
-        add_shortcode( 'usercourses',     array( __CLASS__,'user_courses' ) );
26
-
27
-    }
28
-    /**
29
-     * all_courses shortcode output function.
30
-     *
31
-     * The function should only be called indirectly through do_shortcode()
32
-     *
33
-     * @access public
34
-     * @param mixed $atts
35
-     * @param mixed $content (default: null)
36
-     * @return string
37
-     */
38
-    public static function all_courses( $atts, $content = null ) {
39
-
40
-        return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title
41
-
42
-    } // all_courses()
43
-
44
-    /**
45
-     * paid_courses function.
46
-     *
47
-     * @access public
48
-     * @param mixed $atts
49
-     * @param mixed $content (default: null)
50
-     * @return string
51
-     */
52
-    public static function paid_courses( $atts, $content = null ) {
53
-
54
-        return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' );
55
-
56
-    } // End paid_courses()
57
-
58
-
59
-    /**
60
-     * featured_courses function.
61
-     *
62
-     * @access public
63
-     * @param mixed $atts
64
-     * @param mixed $content (default: null)
65
-     * @return string
66
-     */
67
-    public static function featured_courses( $atts, $content = null ) {
68
-
69
-        return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' );
13
+	/**
14
+	 * Add the legacy shortcodes to WordPress
15
+	 *
16
+	 * @since 1.9.0
17
+	 */
18
+	public static function init(){
19
+
20
+		add_shortcode( 'allcourses',      array( __CLASS__, 'all_courses' ) );
21
+		add_shortcode( 'newcourses',      array( __CLASS__,'new_courses' ) );
22
+		add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') );
23
+		add_shortcode( 'freecourses',     array( __CLASS__,'free_courses') );
24
+		add_shortcode( 'paidcourses',     array( __CLASS__,'paid_courses') );
25
+		add_shortcode( 'usercourses',     array( __CLASS__,'user_courses' ) );
26
+
27
+	}
28
+	/**
29
+	 * all_courses shortcode output function.
30
+	 *
31
+	 * The function should only be called indirectly through do_shortcode()
32
+	 *
33
+	 * @access public
34
+	 * @param mixed $atts
35
+	 * @param mixed $content (default: null)
36
+	 * @return string
37
+	 */
38
+	public static function all_courses( $atts, $content = null ) {
39
+
40
+		return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title
41
+
42
+	} // all_courses()
43
+
44
+	/**
45
+	 * paid_courses function.
46
+	 *
47
+	 * @access public
48
+	 * @param mixed $atts
49
+	 * @param mixed $content (default: null)
50
+	 * @return string
51
+	 */
52
+	public static function paid_courses( $atts, $content = null ) {
53
+
54
+		return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' );
55
+
56
+	} // End paid_courses()
57
+
58
+
59
+	/**
60
+	 * featured_courses function.
61
+	 *
62
+	 * @access public
63
+	 * @param mixed $atts
64
+	 * @param mixed $content (default: null)
65
+	 * @return string
66
+	 */
67
+	public static function featured_courses( $atts, $content = null ) {
68
+
69
+		return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' );
70 70
 
71
-    } // End featured_courses()
71
+	} // End featured_courses()
72 72
 
73
-    /**
74
-     * shortcode_free_courses function.
75
-     *
76
-     * @access public
77
-     * @param mixed $atts
78
-     * @param mixed $content (default: null)
79
-     * @return string
80
-     */
81
-    public static function free_courses( $atts, $content = null ) {
73
+	/**
74
+	 * shortcode_free_courses function.
75
+	 *
76
+	 * @access public
77
+	 * @param mixed $atts
78
+	 * @param mixed $content (default: null)
79
+	 * @return string
80
+	 */
81
+	public static function free_courses( $atts, $content = null ) {
82 82
 
83
-        return self::generate_shortcode_courses( 'Free Courses', 'freecourses' );
83
+		return self::generate_shortcode_courses( 'Free Courses', 'freecourses' );
84 84
 
85
-    } // End free_courses()
85
+	} // End free_courses()
86 86
 
87
-    /**
88
-     * shortcode_new_courses function.
89
-     *
90
-     * @access public
91
-     * @param mixed $atts
92
-     * @param mixed $content (default: null)
93
-     * @return string
94
-     */
95
-    public static function new_courses( $atts, $content = null ) {
87
+	/**
88
+	 * shortcode_new_courses function.
89
+	 *
90
+	 * @access public
91
+	 * @param mixed $atts
92
+	 * @param mixed $content (default: null)
93
+	 * @return string
94
+	 */
95
+	public static function new_courses( $atts, $content = null ) {
96 96
 
97
-        return self::generate_shortcode_courses( 'New Courses', 'newcourses' );
97
+		return self::generate_shortcode_courses( 'New Courses', 'newcourses' );
98 98
 
99
-    } // End new_courses()
99
+	} // End new_courses()
100 100
 
101
-    /**
102
-     * Generate courses adding a title.
103
-     *
104
-     * @since 1.9.0
105
-     *
106
-     * @param $title
107
-     * @param $shortcode_specific_override
108
-     * @return string
109
-     */
110
-    public static function generate_shortcode_courses( $title , $shortcode_specific_override  ){
101
+	/**
102
+	 * Generate courses adding a title.
103
+	 *
104
+	 * @since 1.9.0
105
+	 *
106
+	 * @param $title
107
+	 * @param $shortcode_specific_override
108
+	 * @return string
109
+	 */
110
+	public static function generate_shortcode_courses( $title , $shortcode_specific_override  ){
111 111
 
112
-        global  $shortcode_override, $posts_array;
112
+		global  $shortcode_override, $posts_array;
113 113
 
114
-        $shortcode_override = $shortcode_specific_override;
114
+		$shortcode_override = $shortcode_specific_override;
115 115
 
116
-        // do not show this short code if there is a shortcode int he url and
117
-        // this specific shortcode is not the one requested in the ur.
118
-        $specific_shortcode_requested = isset( $_GET['action'] ) ?  sanitize_text_field(  $_GET['action']  ) : '';
119
-        if( ! empty( $specific_shortcode_requested) &&
120
-            $specific_shortcode_requested != $shortcode_override ){
116
+		// do not show this short code if there is a shortcode int he url and
117
+		// this specific shortcode is not the one requested in the ur.
118
+		$specific_shortcode_requested = isset( $_GET['action'] ) ?  sanitize_text_field(  $_GET['action']  ) : '';
119
+		if( ! empty( $specific_shortcode_requested) &&
120
+			$specific_shortcode_requested != $shortcode_override ){
121 121
 
122
-            return '';
122
+			return '';
123 123
 
124
-        }
124
+		}
125 125
 
126
-        // loop and get all courses html
127
-        ob_start();
128
-        self::initialise_legacy_course_loop();
129
-        $courses = ob_get_clean();
126
+		// loop and get all courses html
127
+		ob_start();
128
+		self::initialise_legacy_course_loop();
129
+		$courses = ob_get_clean();
130 130
 
131
-        $content = '';
132
-        if( count( $posts_array ) > 0 ){
131
+		$content = '';
132
+		if( count( $posts_array ) > 0 ){
133 133
 
134
-            $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>';
135
-            $before .= '<section id="main-course" class="course-container">';
134
+			$before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>';
135
+			$before .= '<section id="main-course" class="course-container">';
136 136
 
137
-            $after = '</section>';
137
+			$after = '</section>';
138 138
 
139
-            //assemble
140
-            $content = $before . $courses . $after;
139
+			//assemble
140
+			$content = $before . $courses . $after;
141 141
 
142
-        }
142
+		}
143 143
 
144
-        return $content;
144
+		return $content;
145 145
 
146
-    }// end generate_shortcode_courses
146
+	}// end generate_shortcode_courses
147 147
 
148 148
 
149
-    /**
150
-     * user_courses function.
151
-     *
152
-     * @access public
153
-     * @param mixed $atts
154
-     * @param mixed $content (default: null)
155
-     * @return string
156
-     */
157
-    public static function user_courses( $atts, $content = null ) {
158
-        global $shortcode_override;
159
-        extract( shortcode_atts( array(	'amount' => 0 ), $atts ) );
149
+	/**
150
+	 * user_courses function.
151
+	 *
152
+	 * @access public
153
+	 * @param mixed $atts
154
+	 * @param mixed $content (default: null)
155
+	 * @return string
156
+	 */
157
+	public static function user_courses( $atts, $content = null ) {
158
+		global $shortcode_override;
159
+		extract( shortcode_atts( array(	'amount' => 0 ), $atts ) );
160 160
 
161
-        $shortcode_override = 'usercourses';
161
+		$shortcode_override = 'usercourses';
162 162
 
163
-        ob_start();
163
+		ob_start();
164 164
 
165
-        if( is_user_logged_in() ){
165
+		if( is_user_logged_in() ){
166 166
 
167
-            Sensei_Templates::get_template( 'user/my-courses.php' );
167
+			Sensei_Templates::get_template( 'user/my-courses.php' );
168 168
 
169
-        }else{
169
+		}else{
170 170
 
171
-            Sensei()->frontend->sensei_login_form();
171
+			Sensei()->frontend->sensei_login_form();
172 172
 
173
-        }
173
+		}
174 174
 
175
-        $content = ob_get_clean();
176
-        return $content;
175
+		$content = ob_get_clean();
176
+		return $content;
177 177
 
178
-    } // End user_courses()
178
+	} // End user_courses()
179 179
 
180
-    /**
181
-     * This function is simply to honor the legacy
182
-     * loop-course.php for the old shortcodes.
183
-     * @since 1.9.0
184
-     */
185
-    public static function initialise_legacy_course_loop(){
180
+	/**
181
+	 * This function is simply to honor the legacy
182
+	 * loop-course.php for the old shortcodes.
183
+	 * @since 1.9.0
184
+	 */
185
+	public static function initialise_legacy_course_loop(){
186 186
 
187
-        global  $post, $wp_query, $shortcode_override, $course_excludes;
187
+		global  $post, $wp_query, $shortcode_override, $course_excludes;
188 188
 
189
-        // Handle Query Type
190
-        $query_type = '';
189
+		// Handle Query Type
190
+		$query_type = '';
191 191
 
192
-        if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) {
193
-            $query_type = esc_html( $_GET[ 'action' ] );
194
-        } // End If Statement
192
+		if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) {
193
+			$query_type = esc_html( $_GET[ 'action' ] );
194
+		} // End If Statement
195 195
 
196
-        if ( '' != $shortcode_override ) {
197
-            $query_type = $shortcode_override;
198
-        } // End If Statement
196
+		if ( '' != $shortcode_override ) {
197
+			$query_type = $shortcode_override;
198
+		} // End If Statement
199 199
 
200
-        if ( !is_array( $course_excludes ) ) { $course_excludes = array(); }
200
+		if ( !is_array( $course_excludes ) ) { $course_excludes = array(); }
201 201
 
202
-        // Check that query returns results
203
-        // Handle Pagination
204
-        $paged = $wp_query->get( 'paged' );
205
-        $paged = empty( $paged ) ? 1 : $paged;
202
+		// Check that query returns results
203
+		// Handle Pagination
204
+		$paged = $wp_query->get( 'paged' );
205
+		$paged = empty( $paged ) ? 1 : $paged;
206 206
 
207 207
 
208
-        // Check for pagination settings
209
-        if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) {
208
+		// Check for pagination settings
209
+		if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) {
210 210
 
211
-            $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] );
211
+			$amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] );
212 212
 
213
-        } else {
213
+		} else {
214 214
 
215
-            $amount = $wp_query->get( 'posts_per_page' );
215
+			$amount = $wp_query->get( 'posts_per_page' );
216 216
 
217
-        } // End If Statement
217
+		} // End If Statement
218 218
 
219
-        // This is not a paginated page (or it's simply the first page of a paginated page/post)
219
+		// This is not a paginated page (or it's simply the first page of a paginated page/post)
220 220
 
221
-        global $posts_array;
222
-        $course_includes   = array();
221
+		global $posts_array;
222
+		$course_includes   = array();
223 223
 
224
-        $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes );
225
-        $course_query = new WP_Query( $query_args );
226
-        $posts_array = $course_query->get_posts();
224
+		$query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes );
225
+		$course_query = new WP_Query( $query_args );
226
+		$posts_array = $course_query->get_posts();
227 227
 
228
-        // output the courses
229
-        if( ! empty( $posts_array ) ) {
228
+		// output the courses
229
+		if( ! empty( $posts_array ) ) {
230 230
 
231
-            //output all courses for current query
232
-            self::loop_courses( $course_query, $amount );
231
+			//output all courses for current query
232
+			self::loop_courses( $course_query, $amount );
233 233
 
234
-        }
234
+		}
235 235
 
236
-    }
236
+	}
237 237
 
238
-    /**
239
-     * Loop through courses in the query and output the infomration needed
240
-     *
241
-     * @since 1.9.0
242
-     *
243
-     * @param WP_Query $course_query
244
-     */
245
-    public static function loop_courses( $course_query, $amount ){
238
+	/**
239
+	 * Loop through courses in the query and output the infomration needed
240
+	 *
241
+	 * @since 1.9.0
242
+	 *
243
+	 * @param WP_Query $course_query
244
+	 */
245
+	public static function loop_courses( $course_query, $amount ){
246 246
 
247
-        global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes;
247
+		global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes;
248 248
 
249
-        if ( count( $course_query->get_posts() ) > 0 ) {
249
+		if ( count( $course_query->get_posts() ) > 0 ) {
250 250
 
251
-            do_action( 'sensei_course_archive_header', $shortcode_override );
251
+			do_action( 'sensei_course_archive_header', $shortcode_override );
252 252
 
253
-            foreach ( $course_query->get_posts() as $course){
253
+			foreach ( $course_query->get_posts() as $course){
254 254
 
255
-                // Make sure the other loops dont include the same post twice!
256
-                array_push( $course_excludes, $course->ID );
255
+				// Make sure the other loops dont include the same post twice!
256
+				array_push( $course_excludes, $course->ID );
257 257
 
258
-                // output the course markup
259
-                self::the_course( $course->ID );
258
+				// output the course markup
259
+				self::the_course( $course->ID );
260 260
 
261
-            } // End For Loop
261
+			} // End For Loop
262 262
 
263
-            // More and Prev links
264
-            $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) );
265
-            $posts_array       = $posts_array_query->get_posts();
266
-            $max_pages = $course_query->found_posts / $amount;
267
-            if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) {
263
+			// More and Prev links
264
+			$posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) );
265
+			$posts_array       = $posts_array_query->get_posts();
266
+			$max_pages = $course_query->found_posts / $amount;
267
+			if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) {
268 268
 
269
-                switch( $shortcode_override ){
270
-                    case 'paidcourses':
271
-                        $filter = 'paid';
272
-                        break;
273
-                    case 'featuredcourses':
274
-                        $filter = 'featured';
275
-                        break;
276
-                    case 'freecourses':
277
-                        $filter = 'free';
278
-                        break;
279
-                    default:
280
-                        $filter = '';
281
-                        break;
282
-                }
269
+				switch( $shortcode_override ){
270
+					case 'paidcourses':
271
+						$filter = 'paid';
272
+						break;
273
+					case 'featuredcourses':
274
+						$filter = 'featured';
275
+						break;
276
+					case 'freecourses':
277
+						$filter = 'free';
278
+						break;
279
+					default:
280
+						$filter = '';
281
+						break;
282
+				}
283 283
 
284
-                $quer_args = array();
285
-                $quer_args[ 'paged' ] = '2';
286
-                if( !empty( $filter ) ){
287
-                    $quer_args[ 'course_filter' ] = $filter;
288
-                }
284
+				$quer_args = array();
285
+				$quer_args[ 'paged' ] = '2';
286
+				if( !empty( $filter ) ){
287
+					$quer_args[ 'course_filter' ] = $filter;
288
+				}
289 289
 
290
-                $course_pagination_link = get_post_type_archive_link( 'course' );
291
-                $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] );
292
-                $more_link_url =  esc_url( add_query_arg( $quer_args, $course_pagination_link ) );
290
+				$course_pagination_link = get_post_type_archive_link( 'course' );
291
+				$more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] );
292
+				$more_link_url =  esc_url( add_query_arg( $quer_args, $course_pagination_link ) );
293 293
 
294
-                // next/more
295
-                $html  = '<div class="navigation"><div class="nav-next">';
296
-                $html .= '<a href="' . $more_link_url . '">';
297
-                $html .= $more_link_text;
298
-                $html .= '<span class="meta-nav"></span></a></div>';
294
+				// next/more
295
+				$html  = '<div class="navigation"><div class="nav-next">';
296
+				$html .= '<a href="' . $more_link_url . '">';
297
+				$html .= $more_link_text;
298
+				$html .= '<span class="meta-nav"></span></a></div>';
299 299
 
300
-                echo apply_filters( 'course_archive_next_link', $html );
300
+				echo apply_filters( 'course_archive_next_link', $html );
301 301
 
302
-            } // End If Statement
302
+			} // End If Statement
303 303
 
304
-        } // End If Statement
305
-    }
304
+		} // End If Statement
305
+	}
306 306
 
307
-    /**
308
-     * Print a single course markup
309
-     *
310
-     * @param $course_id
311
-     */
312
-    public static function the_course( $course_id ){
307
+	/**
308
+	 * Print a single course markup
309
+	 *
310
+	 * @param $course_id
311
+	 */
312
+	public static function the_course( $course_id ){
313 313
 
314
-        // Get meta data
315
-        $course =  get_post( $course_id );
316
-        $user_info = get_userdata( absint( $course->post_author ) );
317
-        $author_link = get_author_posts_url( absint( $course->post_author ) );
318
-        $author_display_name = $user_info->display_name;
319
-        $author_id = $course->post_author;
320
-        $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' );
321
-        $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) );
322
-        $is_user_taking_course = WooThemes_Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
323
-        ?>
314
+		// Get meta data
315
+		$course =  get_post( $course_id );
316
+		$user_info = get_userdata( absint( $course->post_author ) );
317
+		$author_link = get_author_posts_url( absint( $course->post_author ) );
318
+		$author_display_name = $user_info->display_name;
319
+		$author_id = $course->post_author;
320
+		$category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' );
321
+		$preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) );
322
+		$is_user_taking_course = WooThemes_Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
323
+		?>
324 324
 
325 325
         <article class="<?php echo esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_id ) ) ); ?>">
326 326
             <?php
327
-            // so that legacy shortcodes work with thir party plugins that wants to hook in
328
-            do_action('sensei_course_content_before',$course );
329
-            ?>
327
+			// so that legacy shortcodes work with thir party plugins that wants to hook in
328
+			do_action('sensei_course_content_before',$course );
329
+			?>
330 330
             <div class="course-content">
331 331
 
332 332
                 <?php Sensei()->course->course_image($course_id); ?>
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
                     </p>
363 363
 
364 364
                     <?php if ( 0 < $preview_lesson_count && !$is_user_taking_course ) {
365
-                        $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?>
365
+						$preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?>
366 366
                         <p class="sensei-free-lessons">
367 367
                             <a href="<?php echo get_permalink( $course_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?>
368 368
                             </a> - <?php echo $preview_lessons; ?>
@@ -373,15 +373,15 @@  discard block
 block discarded – undo
373 373
 
374 374
             </div>
375 375
             <?php
376
-            // so that legacy shortcodes work with thir party plugins that wants to hook in
377
-            do_action('sensei_course_content_after', $course);
378
-            ?>
376
+			// so that legacy shortcodes work with thir party plugins that wants to hook in
377
+			do_action('sensei_course_content_after', $course);
378
+			?>
379 379
 
380 380
         </article>
381 381
 
382 382
         <?php
383 383
 
384 384
 
385
-    } // end the_course
385
+	} // end the_course
386 386
 
387 387
 }// end class legacy shortcodes
388 388
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -15,14 +15,14 @@  discard block
 block discarded – undo
15 15
      *
16 16
      * @since 1.9.0
17 17
      */
18
-    public static function init(){
18
+    public static function init() {
19 19
 
20
-        add_shortcode( 'allcourses',      array( __CLASS__, 'all_courses' ) );
21
-        add_shortcode( 'newcourses',      array( __CLASS__,'new_courses' ) );
22
-        add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') );
23
-        add_shortcode( 'freecourses',     array( __CLASS__,'free_courses') );
24
-        add_shortcode( 'paidcourses',     array( __CLASS__,'paid_courses') );
25
-        add_shortcode( 'usercourses',     array( __CLASS__,'user_courses' ) );
20
+        add_shortcode('allcourses', array(__CLASS__, 'all_courses'));
21
+        add_shortcode('newcourses', array(__CLASS__, 'new_courses'));
22
+        add_shortcode('featuredcourses', array(__CLASS__, 'featured_courses'));
23
+        add_shortcode('freecourses', array(__CLASS__, 'free_courses'));
24
+        add_shortcode('paidcourses', array(__CLASS__, 'paid_courses'));
25
+        add_shortcode('usercourses', array(__CLASS__, 'user_courses'));
26 26
 
27 27
     }
28 28
     /**
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
      * @param mixed $content (default: null)
36 36
      * @return string
37 37
      */
38
-    public static function all_courses( $atts, $content = null ) {
38
+    public static function all_courses($atts, $content = null) {
39 39
 
40
-        return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title
40
+        return self::generate_shortcode_courses('', 'allcourses'); // all courses but no title
41 41
 
42 42
     } // all_courses()
43 43
 
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
      * @param mixed $content (default: null)
50 50
      * @return string
51 51
      */
52
-    public static function paid_courses( $atts, $content = null ) {
52
+    public static function paid_courses($atts, $content = null) {
53 53
 
54
-        return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' );
54
+        return self::generate_shortcode_courses('Paid Courses', 'paidcourses');
55 55
 
56 56
     } // End paid_courses()
57 57
 
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
      * @param mixed $content (default: null)
65 65
      * @return string
66 66
      */
67
-    public static function featured_courses( $atts, $content = null ) {
67
+    public static function featured_courses($atts, $content = null) {
68 68
 
69
-        return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' );
69
+        return self::generate_shortcode_courses('Featured Courses', 'featuredcourses');
70 70
 
71 71
     } // End featured_courses()
72 72
 
@@ -78,9 +78,9 @@  discard block
 block discarded – undo
78 78
      * @param mixed $content (default: null)
79 79
      * @return string
80 80
      */
81
-    public static function free_courses( $atts, $content = null ) {
81
+    public static function free_courses($atts, $content = null) {
82 82
 
83
-        return self::generate_shortcode_courses( 'Free Courses', 'freecourses' );
83
+        return self::generate_shortcode_courses('Free Courses', 'freecourses');
84 84
 
85 85
     } // End free_courses()
86 86
 
@@ -92,9 +92,9 @@  discard block
 block discarded – undo
92 92
      * @param mixed $content (default: null)
93 93
      * @return string
94 94
      */
95
-    public static function new_courses( $atts, $content = null ) {
95
+    public static function new_courses($atts, $content = null) {
96 96
 
97
-        return self::generate_shortcode_courses( 'New Courses', 'newcourses' );
97
+        return self::generate_shortcode_courses('New Courses', 'newcourses');
98 98
 
99 99
     } // End new_courses()
100 100
 
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
      * @param $shortcode_specific_override
108 108
      * @return string
109 109
      */
110
-    public static function generate_shortcode_courses( $title , $shortcode_specific_override  ){
110
+    public static function generate_shortcode_courses($title, $shortcode_specific_override) {
111 111
 
112 112
         global  $shortcode_override, $posts_array;
113 113
 
@@ -115,9 +115,9 @@  discard block
 block discarded – undo
115 115
 
116 116
         // do not show this short code if there is a shortcode int he url and
117 117
         // this specific shortcode is not the one requested in the ur.
118
-        $specific_shortcode_requested = isset( $_GET['action'] ) ?  sanitize_text_field(  $_GET['action']  ) : '';
119
-        if( ! empty( $specific_shortcode_requested) &&
120
-            $specific_shortcode_requested != $shortcode_override ){
118
+        $specific_shortcode_requested = isset($_GET['action']) ? sanitize_text_field($_GET['action']) : '';
119
+        if ( ! empty($specific_shortcode_requested) &&
120
+            $specific_shortcode_requested != $shortcode_override) {
121 121
 
122 122
             return '';
123 123
 
@@ -129,15 +129,15 @@  discard block
 block discarded – undo
129 129
         $courses = ob_get_clean();
130 130
 
131 131
         $content = '';
132
-        if( count( $posts_array ) > 0 ){
132
+        if (count($posts_array) > 0) {
133 133
 
134
-            $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>';
134
+            $before = empty($title) ? '' : '<header class="archive-header"><h2>'.$title.'</h2></header>';
135 135
             $before .= '<section id="main-course" class="course-container">';
136 136
 
137 137
             $after = '</section>';
138 138
 
139 139
             //assemble
140
-            $content = $before . $courses . $after;
140
+            $content = $before.$courses.$after;
141 141
 
142 142
         }
143 143
 
@@ -154,19 +154,19 @@  discard block
 block discarded – undo
154 154
      * @param mixed $content (default: null)
155 155
      * @return string
156 156
      */
157
-    public static function user_courses( $atts, $content = null ) {
157
+    public static function user_courses($atts, $content = null) {
158 158
         global $shortcode_override;
159
-        extract( shortcode_atts( array(	'amount' => 0 ), $atts ) );
159
+        extract(shortcode_atts(array('amount' => 0), $atts));
160 160
 
161 161
         $shortcode_override = 'usercourses';
162 162
 
163 163
         ob_start();
164 164
 
165
-        if( is_user_logged_in() ){
165
+        if (is_user_logged_in()) {
166 166
 
167
-            Sensei_Templates::get_template( 'user/my-courses.php' );
167
+            Sensei_Templates::get_template('user/my-courses.php');
168 168
 
169
-        }else{
169
+        } else {
170 170
 
171 171
             Sensei()->frontend->sensei_login_form();
172 172
 
@@ -182,54 +182,54 @@  discard block
 block discarded – undo
182 182
      * loop-course.php for the old shortcodes.
183 183
      * @since 1.9.0
184 184
      */
185
-    public static function initialise_legacy_course_loop(){
185
+    public static function initialise_legacy_course_loop() {
186 186
 
187 187
         global  $post, $wp_query, $shortcode_override, $course_excludes;
188 188
 
189 189
         // Handle Query Type
190 190
         $query_type = '';
191 191
 
192
-        if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) {
193
-            $query_type = esc_html( $_GET[ 'action' ] );
192
+        if (isset($_GET['action']) && ('' != esc_html($_GET['action']))) {
193
+            $query_type = esc_html($_GET['action']);
194 194
         } // End If Statement
195 195
 
196
-        if ( '' != $shortcode_override ) {
196
+        if ('' != $shortcode_override) {
197 197
             $query_type = $shortcode_override;
198 198
         } // End If Statement
199 199
 
200
-        if ( !is_array( $course_excludes ) ) { $course_excludes = array(); }
200
+        if ( ! is_array($course_excludes)) { $course_excludes = array(); }
201 201
 
202 202
         // Check that query returns results
203 203
         // Handle Pagination
204
-        $paged = $wp_query->get( 'paged' );
205
-        $paged = empty( $paged ) ? 1 : $paged;
204
+        $paged = $wp_query->get('paged');
205
+        $paged = empty($paged) ? 1 : $paged;
206 206
 
207 207
 
208 208
         // Check for pagination settings
209
-        if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) {
209
+        if (isset(Sensei()->settings->settings['course_archive_amount']) && (0 < absint(Sensei()->settings->settings['course_archive_amount']))) {
210 210
 
211
-            $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] );
211
+            $amount = absint(Sensei()->settings->settings['course_archive_amount']);
212 212
 
213 213
         } else {
214 214
 
215
-            $amount = $wp_query->get( 'posts_per_page' );
215
+            $amount = $wp_query->get('posts_per_page');
216 216
 
217 217
         } // End If Statement
218 218
 
219 219
         // This is not a paginated page (or it's simply the first page of a paginated page/post)
220 220
 
221 221
         global $posts_array;
222
-        $course_includes   = array();
222
+        $course_includes = array();
223 223
 
224
-        $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes );
225
-        $course_query = new WP_Query( $query_args );
224
+        $query_args = Sensei()->course->get_archive_query_args($shortcode_override, $amount, $course_includes, $course_excludes);
225
+        $course_query = new WP_Query($query_args);
226 226
         $posts_array = $course_query->get_posts();
227 227
 
228 228
         // output the courses
229
-        if( ! empty( $posts_array ) ) {
229
+        if ( ! empty($posts_array)) {
230 230
 
231 231
             //output all courses for current query
232
-            self::loop_courses( $course_query, $amount );
232
+            self::loop_courses($course_query, $amount);
233 233
 
234 234
         }
235 235
 
@@ -242,31 +242,31 @@  discard block
 block discarded – undo
242 242
      *
243 243
      * @param WP_Query $course_query
244 244
      */
245
-    public static function loop_courses( $course_query, $amount ){
245
+    public static function loop_courses($course_query, $amount) {
246 246
 
247 247
         global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes;
248 248
 
249
-        if ( count( $course_query->get_posts() ) > 0 ) {
249
+        if (count($course_query->get_posts()) > 0) {
250 250
 
251
-            do_action( 'sensei_course_archive_header', $shortcode_override );
251
+            do_action('sensei_course_archive_header', $shortcode_override);
252 252
 
253
-            foreach ( $course_query->get_posts() as $course){
253
+            foreach ($course_query->get_posts() as $course) {
254 254
 
255 255
                 // Make sure the other loops dont include the same post twice!
256
-                array_push( $course_excludes, $course->ID );
256
+                array_push($course_excludes, $course->ID);
257 257
 
258 258
                 // output the course markup
259
-                self::the_course( $course->ID );
259
+                self::the_course($course->ID);
260 260
 
261 261
             } // End For Loop
262 262
 
263 263
             // More and Prev links
264
-            $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) );
264
+            $posts_array_query = new WP_Query(Sensei()->course->course_query($shortcode_override, $amount, $course_includes, $course_excludes));
265 265
             $posts_array       = $posts_array_query->get_posts();
266 266
             $max_pages = $course_query->found_posts / $amount;
267
-            if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) {
267
+            if ('' != $shortcode_override && ($max_pages > $course_query->get('paged'))) {
268 268
 
269
-                switch( $shortcode_override ){
269
+                switch ($shortcode_override) {
270 270
                     case 'paidcourses':
271 271
                         $filter = 'paid';
272 272
                         break;
@@ -282,22 +282,22 @@  discard block
 block discarded – undo
282 282
                 }
283 283
 
284 284
                 $quer_args = array();
285
-                $quer_args[ 'paged' ] = '2';
286
-                if( !empty( $filter ) ){
287
-                    $quer_args[ 'course_filter' ] = $filter;
285
+                $quer_args['paged'] = '2';
286
+                if ( ! empty($filter)) {
287
+                    $quer_args['course_filter'] = $filter;
288 288
                 }
289 289
 
290
-                $course_pagination_link = get_post_type_archive_link( 'course' );
291
-                $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] );
292
-                $more_link_url =  esc_url( add_query_arg( $quer_args, $course_pagination_link ) );
290
+                $course_pagination_link = get_post_type_archive_link('course');
291
+                $more_link_text = esc_html(Sensei()->settings->settings['course_archive_more_link_text']);
292
+                $more_link_url = esc_url(add_query_arg($quer_args, $course_pagination_link));
293 293
 
294 294
                 // next/more
295 295
                 $html  = '<div class="navigation"><div class="nav-next">';
296
-                $html .= '<a href="' . $more_link_url . '">';
296
+                $html .= '<a href="'.$more_link_url.'">';
297 297
                 $html .= $more_link_text;
298 298
                 $html .= '<span class="meta-nav"></span></a></div>';
299 299
 
300
-                echo apply_filters( 'course_archive_next_link', $html );
300
+                echo apply_filters('course_archive_next_link', $html);
301 301
 
302 302
             } // End If Statement
303 303
 
@@ -309,23 +309,23 @@  discard block
 block discarded – undo
309 309
      *
310 310
      * @param $course_id
311 311
      */
312
-    public static function the_course( $course_id ){
312
+    public static function the_course($course_id) {
313 313
 
314 314
         // Get meta data
315
-        $course =  get_post( $course_id );
316
-        $user_info = get_userdata( absint( $course->post_author ) );
317
-        $author_link = get_author_posts_url( absint( $course->post_author ) );
315
+        $course = get_post($course_id);
316
+        $user_info = get_userdata(absint($course->post_author));
317
+        $author_link = get_author_posts_url(absint($course->post_author));
318 318
         $author_display_name = $user_info->display_name;
319 319
         $author_id = $course->post_author;
320
-        $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' );
321
-        $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) );
322
-        $is_user_taking_course = WooThemes_Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
320
+        $category_output = get_the_term_list($course_id, 'course-category', '', ', ', '');
321
+        $preview_lesson_count = intval(Sensei()->course->course_lesson_preview_count($course_id));
322
+        $is_user_taking_course = WooThemes_Sensei_Utils::user_started_course($course_id, get_current_user_id());
323 323
         ?>
324 324
 
325
-        <article class="<?php echo esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_id ) ) ); ?>">
325
+        <article class="<?php echo esc_attr(join(' ', get_post_class(array('course', 'post'), $course_id))); ?>">
326 326
             <?php
327 327
             // so that legacy shortcodes work with thir party plugins that wants to hook in
328
-            do_action('sensei_course_content_before',$course );
328
+            do_action('sensei_course_content_before', $course);
329 329
             ?>
330 330
             <div class="course-content">
331 331
 
@@ -341,19 +341,19 @@  discard block
 block discarded – undo
341 341
 
342 342
                     <p class="sensei-course-meta">
343 343
 
344
-                        <?php if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { ?>
345
-                            <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?><a href="<?php echo $author_link; ?>" title="<?php echo esc_attr( $author_display_name ); ?>"><?php echo esc_html( $author_display_name   ); ?></a></span>
344
+                        <?php if (isset(Sensei()->settings->settings['course_author']) && (Sensei()->settings->settings['course_author'])) { ?>
345
+                            <span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?><a href="<?php echo $author_link; ?>" title="<?php echo esc_attr($author_display_name); ?>"><?php echo esc_html($author_display_name); ?></a></span>
346 346
                         <?php } // End If Statement ?>
347 347
 
348 348
                         <span class="course-lesson-count">
349
-                                    <?php echo Sensei()->course->course_lesson_count( $course_id ) . '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' ); ?>
349
+                                    <?php echo Sensei()->course->course_lesson_count($course_id).'&nbsp;'.__('Lessons', 'woothemes-sensei'); ?>
350 350
                                 </span>
351 351
 
352
-                        <?php if ( '' != $category_output ) { ?>
353
-                            <span class="course-category"><?php echo sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ); ?></span>
352
+                        <?php if ('' != $category_output) { ?>
353
+                            <span class="course-category"><?php echo sprintf(__('in %s', 'woothemes-sensei'), $category_output); ?></span>
354 354
                         <?php } // End If Statement ?>
355 355
 
356
-                        <?php sensei_simple_course_price( $course_id ); ?>
356
+                        <?php sensei_simple_course_price($course_id); ?>
357 357
 
358 358
                     </p>
359 359
 
@@ -361,10 +361,10 @@  discard block
 block discarded – undo
361 361
 
362 362
                     </p>
363 363
 
364
-                    <?php if ( 0 < $preview_lesson_count && !$is_user_taking_course ) {
365
-                        $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?>
364
+                    <?php if (0 < $preview_lesson_count && ! $is_user_taking_course) {
365
+                        $preview_lessons = sprintf(__('(%d preview lessons)', 'woothemes-sensei'), $preview_lesson_count); ?>
366 366
                         <p class="sensei-free-lessons">
367
-                            <a href="<?php echo get_permalink( $course_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?>
367
+                            <a href="<?php echo get_permalink($course_id); ?>"><?php _e('Preview this course', 'woothemes-sensei') ?>
368 368
                             </a> - <?php echo $preview_lessons; ?>
369 369
                         </p>
370 370
                     <?php } ?>
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -166,7 +166,7 @@
 block discarded – undo
166 166
 
167 167
             Sensei_Templates::get_template( 'user/my-courses.php' );
168 168
 
169
-        }else{
169
+        } else{
170 170
 
171 171
             Sensei()->frontend->sensei_login_form();
172 172
 
Please login to merge, or discard this patch.