Completed
Push — master ( d51ce1...80c0ca )
by Dwain
05:52
created
includes/class-sensei-course-results.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -14,10 +14,10 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class Sensei_Course_Results {
16 16
 
17
-    /**
18
-     * @var string
19
-     */
20
-    public  $courses_url_base;
17
+	/**
18
+	 * @var string
19
+	 */
20
+	public  $courses_url_base;
21 21
 
22 22
 	/**
23 23
 	 * Constructor.
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 		global $wp_query,  $current_user;
99 99
 
100 100
 		if( isset( $wp_query->query_vars['course_results'] ) ) {
101
-            Sensei_Templates::get_template( 'course-results/course-info.php' );
101
+			Sensei_Templates::get_template( 'course-results/course-info.php' );
102 102
 		}
103 103
 
104 104
 	}
@@ -117,20 +117,20 @@  discard block
 block discarded – undo
117 117
 
118 118
 		sensei_do_deprecated_action( 'sensei_course_results_lessons','1.9.','sensei_course_results_content_inside_after', $course );
119 119
 
120
-        sensei_do_deprecated_action( 'sensei_course_results_bottom','1.9.','sensei_course_results_content_inside_after', $course->ID );
120
+		sensei_do_deprecated_action( 'sensei_course_results_bottom','1.9.','sensei_course_results_content_inside_after', $course->ID );
121 121
 
122 122
 	}
123 123
 
124 124
 	/**
125 125
 	 * Load template for displaying course lessons
126
-     *
126
+	 *
127 127
 	 * @since  1.4.0
128 128
 	 * @return void
129 129
 	 */
130 130
 	public function course_lessons() {
131 131
 
132 132
 		global $course;
133
-        _deprecated_function( 'Sensei_modules course_lessons ', '1.9.0' );
133
+		_deprecated_function( 'Sensei_modules course_lessons ', '1.9.0' );
134 134
 
135 135
 	}
136 136
 
@@ -147,62 +147,62 @@  discard block
 block discarded – undo
147 147
 		return $classes;
148 148
 	}
149 149
 
150
-    /**
151
-     * Deprecate the sensei_course_results_content hook
152
-     *
153
-     * @deprecated since 1.9.0
154
-     */
155
-    public static function deprecate_sensei_course_results_content_hook(){
150
+	/**
151
+	 * Deprecate the sensei_course_results_content hook
152
+	 *
153
+	 * @deprecated since 1.9.0
154
+	 */
155
+	public static function deprecate_sensei_course_results_content_hook(){
156 156
 
157
-        sensei_do_deprecated_action('sensei_course_results_content', '1.9.0','sensei_course_results_content_before');
157
+		sensei_do_deprecated_action('sensei_course_results_content', '1.9.0','sensei_course_results_content_before');
158 158
 
159
-    }
159
+	}
160 160
 
161
-    /**
162
-     * Fire the sensei frontend message hook
163
-     *
164
-     * @since 1.9.0
165
-     */
166
-    public static function fire_sensei_message_hook(){
161
+	/**
162
+	 * Fire the sensei frontend message hook
163
+	 *
164
+	 * @since 1.9.0
165
+	 */
166
+	public static function fire_sensei_message_hook(){
167 167
 
168
-        do_action( 'sensei_frontend_messages' );
168
+		do_action( 'sensei_frontend_messages' );
169 169
 
170
-    }
170
+	}
171 171
 
172
-    /**
173
-     * Deprecate the course_results info hook
174
-     *
175
-     * @since 1.9.0
176
-     */
177
-    public static function deprecate_course_result_info_hook(){
172
+	/**
173
+	 * Deprecate the course_results info hook
174
+	 *
175
+	 * @since 1.9.0
176
+	 */
177
+	public static function deprecate_course_result_info_hook(){
178 178
 
179
-        sensei_do_deprecated_action( 'sensei_course_results_info', '1.9.0', 'sensei_course_results_content_inside_before' );
179
+		sensei_do_deprecated_action( 'sensei_course_results_info', '1.9.0', 'sensei_course_results_content_inside_before' );
180 180
 
181
-    }
181
+	}
182 182
 
183
-    /**
184
-     * Deprecate the sensei_course_results_top hook
185
-     *
186
-     * @deprecate since 1.9.0
187
-     */
188
-    public static function deprecate_course_results_top_hook(){
183
+	/**
184
+	 * Deprecate the sensei_course_results_top hook
185
+	 *
186
+	 * @deprecate since 1.9.0
187
+	 */
188
+	public static function deprecate_course_results_top_hook(){
189 189
 
190
-        global $course;
191
-        sensei_do_deprecated_action( 'sensei_course_results_top', '1.9.0' ,'sensei_course_results_content_inside_before',$course->ID );
190
+		global $course;
191
+		sensei_do_deprecated_action( 'sensei_course_results_top', '1.9.0' ,'sensei_course_results_content_inside_before',$course->ID );
192 192
 
193
-    }
193
+	}
194 194
 
195
-    /**
196
-     * Fire the course image hook
197
-     *
198
-     * @since 1.8.0
199
-     */
200
-    public static function fire_course_image_hook(){
195
+	/**
196
+	 * Fire the course image hook
197
+	 *
198
+	 * @since 1.8.0
199
+	 */
200
+	public static function fire_course_image_hook(){
201 201
 
202
-        global $course;
203
-        do_action( 'sensei_course_image', $course->ID );
202
+		global $course;
203
+		do_action( 'sensei_course_image', $course->ID );
204 204
 
205
-    }
205
+	}
206 206
 
207 207
 } // End Class
208 208
 
Please login to merge, or discard this patch.
includes/shortcodes/class-sensei-shortcode-user-messages.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -15,91 +15,91 @@
 block discarded – undo
15 15
  */
16 16
 class Sensei_Shortcode_User_Messages implements Sensei_Shortcode_Interface {
17 17
 
18
-    /**
19
-     * @var WP_Query
20
-     * messages for the current user
21
-     */
22
-    protected $messages_query;
23
-
24
-    /**
25
-     * Setup the shortcode object
26
-     *
27
-     * @since 1.9.0
28
-     * @param array $attributes
29
-     * @param string $content
30
-     * @param string $shortcode the shortcode that was called for this instance
31
-     */
32
-    public function __construct( $attributes, $content, $shortcode ){
33
-
34
-        $this->setup_messages_query();
35
-
36
-    }
37
-
38
-    /**
39
-     * create the messages query .
40
-     *
41
-     * @return mixed
42
-     */
43
-    public function setup_messages_query(){
44
-
45
-        $user = wp_get_current_user();
46
-
47
-        $args = array(
48
-            'post_type' => 'sensei_message',
49
-            'posts_per_page' => 500,
50
-            'orderby' => 'date',
51
-            'order' => 'DESC',
52
-            'post_status' => 'publish',
53
-            'meta_query' => array(
54
-                array(
55
-                    'key'     => '_sender',
56
-                    'value'   => $user->user_login,
57
-                    'compare' => '=',
58
-                ),
59
-            ),
60
-        );
61
-
62
-        $this->messages_query  = new WP_Query( $args );
63
-    }
64
-
65
-    /**
66
-     * Rendering the shortcode this class is responsible for.
67
-     *
68
-     * @return string $content
69
-     */
70
-    public function render(){
71
-
72
-        if( !is_user_logged_in() ){
73
-
74
-            Sensei()->notices->add_notice( __('Please login to view your messages.','woothemes-sensei') , 'alert'  );
75
-
76
-        } elseif( 0 == $this->messages_query->post_count ){
77
-
78
-            Sensei()->notices->add_notice( __( 'You do not have any messages.', 'woothemes-sensei') , 'alert'  );
79
-        }
80
-
81
-        $messages_disabled_in_settings =  ! ( ! isset( Sensei()->settings->settings['messages_disable'] )
82
-                                            || ! Sensei()->settings->settings['messages_disable'] ) ;
83
-
84
-        // don't show anything if messages are disable
85
-        if( $messages_disabled_in_settings ){
86
-            return '';
87
-        }
88
-
89
-        //set the wp_query to the current messages query
90
-        global $wp_query;
91
-        $wp_query = $this->messages_query;
92
-
93
-        ob_start();
94
-        Sensei()->notices->print_notices();
95
-        Sensei_Templates::get_part('loop', 'message');
96
-        $messages_html = ob_get_clean();
97
-
98
-        // set back the global query
99
-        wp_reset_query();
100
-
101
-        return $messages_html;
102
-
103
-    }// end render
18
+	/**
19
+	 * @var WP_Query
20
+	 * messages for the current user
21
+	 */
22
+	protected $messages_query;
23
+
24
+	/**
25
+	 * Setup the shortcode object
26
+	 *
27
+	 * @since 1.9.0
28
+	 * @param array $attributes
29
+	 * @param string $content
30
+	 * @param string $shortcode the shortcode that was called for this instance
31
+	 */
32
+	public function __construct( $attributes, $content, $shortcode ){
33
+
34
+		$this->setup_messages_query();
35
+
36
+	}
37
+
38
+	/**
39
+	 * create the messages query .
40
+	 *
41
+	 * @return mixed
42
+	 */
43
+	public function setup_messages_query(){
44
+
45
+		$user = wp_get_current_user();
46
+
47
+		$args = array(
48
+			'post_type' => 'sensei_message',
49
+			'posts_per_page' => 500,
50
+			'orderby' => 'date',
51
+			'order' => 'DESC',
52
+			'post_status' => 'publish',
53
+			'meta_query' => array(
54
+				array(
55
+					'key'     => '_sender',
56
+					'value'   => $user->user_login,
57
+					'compare' => '=',
58
+				),
59
+			),
60
+		);
61
+
62
+		$this->messages_query  = new WP_Query( $args );
63
+	}
64
+
65
+	/**
66
+	 * Rendering the shortcode this class is responsible for.
67
+	 *
68
+	 * @return string $content
69
+	 */
70
+	public function render(){
71
+
72
+		if( !is_user_logged_in() ){
73
+
74
+			Sensei()->notices->add_notice( __('Please login to view your messages.','woothemes-sensei') , 'alert'  );
75
+
76
+		} elseif( 0 == $this->messages_query->post_count ){
77
+
78
+			Sensei()->notices->add_notice( __( 'You do not have any messages.', 'woothemes-sensei') , 'alert'  );
79
+		}
80
+
81
+		$messages_disabled_in_settings =  ! ( ! isset( Sensei()->settings->settings['messages_disable'] )
82
+											|| ! Sensei()->settings->settings['messages_disable'] ) ;
83
+
84
+		// don't show anything if messages are disable
85
+		if( $messages_disabled_in_settings ){
86
+			return '';
87
+		}
88
+
89
+		//set the wp_query to the current messages query
90
+		global $wp_query;
91
+		$wp_query = $this->messages_query;
92
+
93
+		ob_start();
94
+		Sensei()->notices->print_notices();
95
+		Sensei_Templates::get_part('loop', 'message');
96
+		$messages_html = ob_get_clean();
97
+
98
+		// set back the global query
99
+		wp_reset_query();
100
+
101
+		return $messages_html;
102
+
103
+	}// end render
104 104
 
105 105
 }// end class
106 106
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-sensei.php 1 patch
Indentation   +1306 added lines, -1306 removed lines patch added patch discarded remove patch
@@ -14,1323 +14,1323 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class Sensei_Main {
16 16
 
17
-    /**
18
-     * @var string
19
-     * Reference to the main plugin file
20
-     */
21
-    private $file;
22
-
23
-    /**
24
-     * @var Sensei_Main $_instance to the the main and only instance of the Sensei class.
25
-     * @since 1.8.0
26
-     */
27
-    protected static $_instance = null;
28
-
29
-    /**
30
-     * Main reference to the plugins current version
31
-     */
32
-    public $version;
33
-
34
-    /**
35
-     * Public token, referencing for the text domain.
36
-     */
37
-    public $token = 'woothemes-sensei';
38
-
39
-    /**
40
-     * Plugin url and path for use when access resources.
41
-     */
42
-    public $plugin_url;
43
-    public $plugin_path;
44
-    public $template_url;
45
-
46
-    /**
47
-     * @var Sensei_PostTypes
48
-     * All Sensei sub classes. Currently used to access functionality contained within
49
-     * within Sensei sub classes e.g. Sensei()->course->all_courses()
50
-     */
51
-    public $post_types;
52
-
53
-    /**
54
-     * @var WooThemes_Sensei_Settings
55
-     */
56
-    public $settings;
57
-
58
-    /**
59
-     * @var WooThemes_Sensei_Course_Results
60
-     */
61
-    public $course_results;
62
-
63
-    /**
64
-     * @var Sensei_Updates
65
-     */
66
-    public $updates;
67
-    /**
68
-     * @var WooThemes_Sensei_Course
69
-     */
70
-    public $course;
71
-
72
-    /**
73
-     * @var WooThemes_Sensei_Lesson
74
-     */
75
-    public $lesson;
76
-
77
-    /**
78
-     * @var WooThemes_Sensei_Quiz
79
-     */
80
-    public $quiz;
81
-
82
-    /**
83
-     * @var WooThemes_Sensei_Question
84
-     */
85
-    public $question;
86
-
87
-    /**
88
-     * @var WooThemes_Sensei_Admin
89
-     */
90
-    public $admin;
91
-
92
-    /**
93
-     * @var WooThemes_Sensei_Frontend
94
-     */
95
-    public $frontend;
96
-
97
-    /**
98
-     * @var Sensei_Notices
99
-     */
100
-    public $notices;
101
-
102
-    /**
103
-     * @var WooThemes_Sensei_Grading
104
-     */
105
-    public $grading;
106
-
107
-    /**
108
-     * @var WooThemes_Sensei_Emails
109
-     */
110
-    public $emails;
111
-
112
-    /**
113
-     * @var WooThemes_Sensei_Learner_Profiles
114
-     */
115
-    public $learner_profiles;
116
-
117
-    /**
118
-     * @var Sensei_Teacher
119
-     */
120
-    public $teacher;
121
-
122
-    /**
123
-     * @var WooThemes_Sensei_Learners
124
-     */
125
-    public $learners;
126
-
127
-    /**
128
-     * @var array
129
-     * Global instance for access to the permissions message shown
130
-     * when users do not have the right privileges to access resources.
131
-     */
132
-    public $permissions_message;
133
-
134
-    /**
135
-     * @var Sensei_Core_Modules Sensei Modules functionality
136
-     */
137
-    public $modules;
138
-
139
-    /**
140
-     * @var Sensei_Analysis
141
-     */
142
-    public $analysis;
143
-
144
-    /**
145
-     * Constructor method.
146
-     * @param  string $file The base file of the plugin.
147
-     * @since  1.0.0
148
-     */
149
-    public function __construct ( $file ) {
150
-
151
-        // Setup object data
152
-        $this->file = $file;
153
-        $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) );
154
-        $this->plugin_path = trailingslashit( dirname( $file ) );
155
-        $this->template_url	= apply_filters( 'sensei_template_url', 'sensei/' );
156
-        $this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) );
157
-
158
-        // Initialize the core Sensei functionality
159
-        $this->init();
160
-
161
-        // Installation
162
-        if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install();
163
-
164
-        // Run this on activation.
165
-        register_activation_hook( $this->file, array( $this, 'activation' ) );
166
-
167
-        // load the classes need throughout sensei
168
-        $this->initialize_global_objects();
169
-
170
-        // Image Sizes
171
-        $this->init_image_sizes();
172
-
173
-        // Force WooCommerce Required Settings
174
-        $this->set_woocommerce_functionality();
175
-
176
-        // load all hooks
177
-        $this->load_hooks();
178
-
179
-    } // End __construct()
180
-
181
-    /**
182
-     * Load the foundations of Sensei.
183
-     * @since 1.9.0
184
-     */
185
-    protected function init(){
186
-
187
-        // Localisation
188
-        $this->load_plugin_textdomain();
189
-        add_action( 'init', array( $this, 'load_localisation' ), 0 );
190
-
191
-        // load the shortcode loader into memory, so as to listen to all for
192
-        // all shortcodes on the front end
193
-        new Sensei_Shortcode_Loader();
194
-
195
-    }
17
+	/**
18
+	 * @var string
19
+	 * Reference to the main plugin file
20
+	 */
21
+	private $file;
22
+
23
+	/**
24
+	 * @var Sensei_Main $_instance to the the main and only instance of the Sensei class.
25
+	 * @since 1.8.0
26
+	 */
27
+	protected static $_instance = null;
28
+
29
+	/**
30
+	 * Main reference to the plugins current version
31
+	 */
32
+	public $version;
33
+
34
+	/**
35
+	 * Public token, referencing for the text domain.
36
+	 */
37
+	public $token = 'woothemes-sensei';
38
+
39
+	/**
40
+	 * Plugin url and path for use when access resources.
41
+	 */
42
+	public $plugin_url;
43
+	public $plugin_path;
44
+	public $template_url;
45
+
46
+	/**
47
+	 * @var Sensei_PostTypes
48
+	 * All Sensei sub classes. Currently used to access functionality contained within
49
+	 * within Sensei sub classes e.g. Sensei()->course->all_courses()
50
+	 */
51
+	public $post_types;
52
+
53
+	/**
54
+	 * @var WooThemes_Sensei_Settings
55
+	 */
56
+	public $settings;
57
+
58
+	/**
59
+	 * @var WooThemes_Sensei_Course_Results
60
+	 */
61
+	public $course_results;
62
+
63
+	/**
64
+	 * @var Sensei_Updates
65
+	 */
66
+	public $updates;
67
+	/**
68
+	 * @var WooThemes_Sensei_Course
69
+	 */
70
+	public $course;
71
+
72
+	/**
73
+	 * @var WooThemes_Sensei_Lesson
74
+	 */
75
+	public $lesson;
76
+
77
+	/**
78
+	 * @var WooThemes_Sensei_Quiz
79
+	 */
80
+	public $quiz;
81
+
82
+	/**
83
+	 * @var WooThemes_Sensei_Question
84
+	 */
85
+	public $question;
86
+
87
+	/**
88
+	 * @var WooThemes_Sensei_Admin
89
+	 */
90
+	public $admin;
91
+
92
+	/**
93
+	 * @var WooThemes_Sensei_Frontend
94
+	 */
95
+	public $frontend;
96
+
97
+	/**
98
+	 * @var Sensei_Notices
99
+	 */
100
+	public $notices;
101
+
102
+	/**
103
+	 * @var WooThemes_Sensei_Grading
104
+	 */
105
+	public $grading;
106
+
107
+	/**
108
+	 * @var WooThemes_Sensei_Emails
109
+	 */
110
+	public $emails;
111
+
112
+	/**
113
+	 * @var WooThemes_Sensei_Learner_Profiles
114
+	 */
115
+	public $learner_profiles;
116
+
117
+	/**
118
+	 * @var Sensei_Teacher
119
+	 */
120
+	public $teacher;
121
+
122
+	/**
123
+	 * @var WooThemes_Sensei_Learners
124
+	 */
125
+	public $learners;
126
+
127
+	/**
128
+	 * @var array
129
+	 * Global instance for access to the permissions message shown
130
+	 * when users do not have the right privileges to access resources.
131
+	 */
132
+	public $permissions_message;
133
+
134
+	/**
135
+	 * @var Sensei_Core_Modules Sensei Modules functionality
136
+	 */
137
+	public $modules;
138
+
139
+	/**
140
+	 * @var Sensei_Analysis
141
+	 */
142
+	public $analysis;
143
+
144
+	/**
145
+	 * Constructor method.
146
+	 * @param  string $file The base file of the plugin.
147
+	 * @since  1.0.0
148
+	 */
149
+	public function __construct ( $file ) {
150
+
151
+		// Setup object data
152
+		$this->file = $file;
153
+		$this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) );
154
+		$this->plugin_path = trailingslashit( dirname( $file ) );
155
+		$this->template_url	= apply_filters( 'sensei_template_url', 'sensei/' );
156
+		$this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) );
157
+
158
+		// Initialize the core Sensei functionality
159
+		$this->init();
160
+
161
+		// Installation
162
+		if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install();
163
+
164
+		// Run this on activation.
165
+		register_activation_hook( $this->file, array( $this, 'activation' ) );
166
+
167
+		// load the classes need throughout sensei
168
+		$this->initialize_global_objects();
169
+
170
+		// Image Sizes
171
+		$this->init_image_sizes();
172
+
173
+		// Force WooCommerce Required Settings
174
+		$this->set_woocommerce_functionality();
175
+
176
+		// load all hooks
177
+		$this->load_hooks();
178
+
179
+	} // End __construct()
180
+
181
+	/**
182
+	 * Load the foundations of Sensei.
183
+	 * @since 1.9.0
184
+	 */
185
+	protected function init(){
186
+
187
+		// Localisation
188
+		$this->load_plugin_textdomain();
189
+		add_action( 'init', array( $this, 'load_localisation' ), 0 );
190
+
191
+		// load the shortcode loader into memory, so as to listen to all for
192
+		// all shortcodes on the front end
193
+		new Sensei_Shortcode_Loader();
194
+
195
+	}
196 196
 
197
-    /**
198
-     * Global Sensei Instance
199
-     *
200
-     * Ensure that only one instance of the main Sensei class can be loaded.
201
-     *
202
-     * @since 1.8.0
203
-     * @static
204
-     * @see WC()
205
-     * @return WooThemes_Sensei Instance.
206
-     */
207
-    public static function instance() {
197
+	/**
198
+	 * Global Sensei Instance
199
+	 *
200
+	 * Ensure that only one instance of the main Sensei class can be loaded.
201
+	 *
202
+	 * @since 1.8.0
203
+	 * @static
204
+	 * @see WC()
205
+	 * @return WooThemes_Sensei Instance.
206
+	 */
207
+	public static function instance() {
208 208
 
209
-        if ( is_null( self::$_instance ) ) {
209
+		if ( is_null( self::$_instance ) ) {
210 210
 
211
-            //Sensei requires a reference to the main Sensei plugin file
212
-            $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php';
211
+			//Sensei requires a reference to the main Sensei plugin file
212
+			$sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php';
213 213
 
214
-            self::$_instance = new self( $sensei_main_plugin_file  );
214
+			self::$_instance = new self( $sensei_main_plugin_file  );
215 215
 
216
-        }
216
+		}
217 217
 
218
-        return self::$_instance;
218
+		return self::$_instance;
219 219
 
220
-    } // end instance()
220
+	} // end instance()
221 221
 
222
-    /**
223
-     * This function is linked into the activation
224
-     * hook to reset flush the urls to ensure Sensei post types show up.
225
-     *
226
-     * @since 1.9.0
227
-     *
228
-     * @param $plugin
229
-     */
230
-    public static function activation_flush_rules( $plugin ){
222
+	/**
223
+	 * This function is linked into the activation
224
+	 * hook to reset flush the urls to ensure Sensei post types show up.
225
+	 *
226
+	 * @since 1.9.0
227
+	 *
228
+	 * @param $plugin
229
+	 */
230
+	public static function activation_flush_rules( $plugin ){
231 231
 
232
-        if( strpos( $plugin, '/woothemes-sensei.php' ) > 0  ){
232
+		if( strpos( $plugin, '/woothemes-sensei.php' ) > 0  ){
233 233
 
234
-            flush_rewrite_rules(true);
234
+			flush_rewrite_rules(true);
235 235
 
236
-        }
236
+		}
237 237
 
238
-    }
238
+	}
239 239
 
240
-    /**
241
-     * Cloning is forbidden.
242
-     * @since 1.8.0
243
-     */
244
-    public function __clone() {
245
-        _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' );
246
-    }
240
+	/**
241
+	 * Cloning is forbidden.
242
+	 * @since 1.8.0
243
+	 */
244
+	public function __clone() {
245
+		_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' );
246
+	}
247 247
 
248
-    /**
249
-     * Unserializing instances of this class is forbidden.
250
-     * @since 1.8.0
251
-     */
252
-    public function __wakeup() {
253
-        _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' );
254
-    }
248
+	/**
249
+	 * Unserializing instances of this class is forbidden.
250
+	 * @since 1.8.0
251
+	 */
252
+	public function __wakeup() {
253
+		_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' );
254
+	}
255 255
 
256
-    /**
257
-     * Load the properties for the main Sensei object
258
-     *
259
-     * @since 1.9.0
260
-     */
261
-    public function initialize_global_objects(){
256
+	/**
257
+	 * Load the properties for the main Sensei object
258
+	 *
259
+	 * @since 1.9.0
260
+	 */
261
+	public function initialize_global_objects(){
262 262
 
263
-        // Setup post types.
264
-        $this->post_types = new Sensei_PostTypes();
263
+		// Setup post types.
264
+		$this->post_types = new Sensei_PostTypes();
265 265
 
266
-        // Lad the updates class
267
-        $this->updates = new Sensei_Updates( $this );
266
+		// Lad the updates class
267
+		$this->updates = new Sensei_Updates( $this );
268 268
 
269
-        // Setup settings
270
-        $this->settings = new Sensei_Settings();
269
+		// Setup settings
270
+		$this->settings = new Sensei_Settings();
271 271
 
272
-        // Load Course Results Class
273
-        $this->course_results = new Sensei_Course_Results();
272
+		// Load Course Results Class
273
+		$this->course_results = new Sensei_Course_Results();
274 274
 
275
-        // Load the teacher role
276
-        $this->teacher = new Sensei_Teacher();
275
+		// Load the teacher role
276
+		$this->teacher = new Sensei_Teacher();
277 277
 
278
-        // Add the Course class
279
-        $this->course = $this->post_types->course;
278
+		// Add the Course class
279
+		$this->course = $this->post_types->course;
280 280
 
281
-        // Add the lesson class
282
-        $this->lesson = $this->post_types->lesson;
281
+		// Add the lesson class
282
+		$this->lesson = $this->post_types->lesson;
283 283
 
284
-        // Add the question class
285
-        $this->question = $this->post_types->question;
284
+		// Add the question class
285
+		$this->question = $this->post_types->question;
286 286
 
287
-        //Add the quiz class
288
-        $this->quiz = $this->post_types->quiz;
287
+		//Add the quiz class
288
+		$this->quiz = $this->post_types->quiz;
289 289
 
290
-        // load the modules class after all plugsin are loaded
291
-        add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) );
290
+		// load the modules class after all plugsin are loaded
291
+		add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) );
292 292
 
293
-        // Load Learner Management Functionality
294
-        $this->learners = new Sensei_Learner_Management( $this->file );
293
+		// Load Learner Management Functionality
294
+		$this->learners = new Sensei_Learner_Management( $this->file );
295 295
 
296
-        // Differentiate between administration and frontend logic.
297
-        if ( is_admin() ) {
296
+		// Differentiate between administration and frontend logic.
297
+		if ( is_admin() ) {
298 298
 
299
-            // Load Admin Welcome class
300
-            new Sensei_Welcome();
299
+			// Load Admin Welcome class
300
+			new Sensei_Welcome();
301 301
 
302
-            // Load Admin Class
303
-            $this->admin = new Sensei_Admin( $this->file );
302
+			// Load Admin Class
303
+			$this->admin = new Sensei_Admin( $this->file );
304 304
 
305
-            // Load Analysis Reports
306
-            $this->analysis = new Sensei_Analysis( $this->file );
305
+			// Load Analysis Reports
306
+			$this->analysis = new Sensei_Analysis( $this->file );
307 307
 
308
-        } else {
308
+		} else {
309 309
 
310
-            // Load Frontend Class
311
-            $this->frontend = new Sensei_Frontend();
310
+			// Load Frontend Class
311
+			$this->frontend = new Sensei_Frontend();
312 312
 
313
-            // Load notice Class
314
-            $this->notices = new Sensei_Notices();
313
+			// Load notice Class
314
+			$this->notices = new Sensei_Notices();
315 315
 
316
-        }
316
+		}
317 317
 
318
-        // Load Grading Functionality
319
-        $this->grading = new Sensei_Grading( $this->file );
318
+		// Load Grading Functionality
319
+		$this->grading = new Sensei_Grading( $this->file );
320 320
 
321
-        // Load Email Class
322
-        $this->emails = new Sensei_Emails( $this->file );
321
+		// Load Email Class
322
+		$this->emails = new Sensei_Emails( $this->file );
323 323
 
324
-        // Load Learner Profiles Class
325
-        $this->learner_profiles = new Sensei_Learner_Profiles();
324
+		// Load Learner Profiles Class
325
+		$this->learner_profiles = new Sensei_Learner_Profiles();
326 326
 
327
-    }
327
+	}
328 328
 
329
-    /**
330
-     * Initialize all Sensei hooks
331
-     *
332
-     * @since 1.9.0
333
-     */
334
-    public function load_hooks(){
335
-
336
-        add_action( 'widgets_init', array( $this, 'register_widgets' ) );
337
-        add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) );
338
-
339
-        // WooCommerce Payment Actions
340
-        add_action( 'woocommerce_payment_complete' , array( $this, 'sensei_woocommerce_complete_order' ) );
341
-        add_action( 'woocommerce_thankyou' , array( $this, 'sensei_woocommerce_complete_order' ) );
342
-        add_action( 'woocommerce_order_status_completed' , array( $this, 'sensei_woocommerce_complete_order' ) );
343
-        add_action( 'woocommerce_order_status_processing' , array( $this, 'sensei_woocommerce_complete_order' ) );
344
-        add_action( 'woocommerce_order_status_cancelled' , array( $this, 'sensei_woocommerce_cancel_order' ) );
345
-        add_action( 'woocommerce_order_status_refunded' , array( $this, 'sensei_woocommerce_cancel_order' ) );
346
-        add_action( 'subscriptions_activated_for_order', array( $this, 'sensei_activate_subscription' ) );
347
-
348
-        // WooCommerce Subscriptions Actions
349
-        add_action( 'reactivated_subscription', array( $this, 'sensei_woocommerce_reactivate_subscription' ), 10, 2 );
350
-        add_action( 'subscription_expired' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
351
-        add_action( 'subscription_end_of_prepaid_term' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
352
-        add_action( 'cancelled_subscription' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
353
-        add_action( 'subscription_put_on-hold' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
354
-
355
-        // Add Email link to course orders
356
-        add_action( 'woocommerce_email_after_order_table', array( $this, 'sensei_woocommerce_email_course_details' ), 10, 1 );
357
-
358
-        // Filter comment counts
359
-        add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 );
360
-
361
-        add_action( 'body_class', array( $this, 'body_class' ) );
362
-
363
-        // Check for and activate JetPack LaTeX support
364
-        add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules
365
-
366
-        // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1
367
-        add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 );
368
-
369
-    }
370
-
371
-    /**
372
-     * Run Sensei updates.
373
-     * @access  public
374
-     * @since   1.1.0
375
-     * @return  void
376
-     */
377
-    public function run_updates() {
378
-        // Run updates if administrator
379
-        if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) {
380
-
381
-            $this->updates->update();
382
-
383
-        } // End If Statement
384
-    } // End run_updates()
385
-
386
-
387
-
388
-    /**
389
-     * Setup required WooCommerce settings.
390
-     * @access  public
391
-     * @since   1.1.0
392
-     * @return  void
393
-     */
394
-    public function set_woocommerce_functionality() {
395
-        // Disable guest checkout if a course is in the cart as we need a valid user to store data for
396
-        add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( $this, 'disable_guest_checkout' ) );
397
-
398
-        // Mark orders with virtual products as complete rather then stay processing
399
-        add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'virtual_order_payment_complete' ), 10, 2 );
400
-
401
-    } // End set_woocommerce_functionality()
402
-
403
-    /**
404
-     * Disable guest checkout if a course product is in the cart
405
-     * @param  boolean $guest_checkout Current guest checkout setting
406
-     * @return boolean                 Modified guest checkout setting
407
-     */
408
-    public function disable_guest_checkout( $guest_checkout ) {
409
-        global $woocommerce;
410
-
411
-        if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
412
-
413
-            if( isset( $woocommerce->cart->cart_contents ) && count( $woocommerce->cart->cart_contents ) > 0 ) {
414
-                foreach( $woocommerce->cart->cart_contents as $cart_key => $product ) {
415
-                    if( isset( $product['product_id'] ) ) {
416
-                        $args = array(
417
-                            'posts_per_page' => -1,
418
-                            'post_type' => 'course',
419
-                            'meta_query' => array(
420
-                                array(
421
-                                    'key' => '_course_woocommerce_product',
422
-                                    'value' => $product['product_id']
423
-                                )
424
-                            )
425
-                        );
426
-                        $posts = get_posts( $args );
427
-                        if( $posts && count( $posts ) > 0 ) {
428
-                            foreach( $posts as $course ) {
429
-                                $guest_checkout = '';
430
-                                break;
431
-                            }
432
-                        }
433
-                    }
434
-                }
435
-            }
436
-        }
437
-
438
-        return $guest_checkout;
439
-    }
440
-
441
-    /**
442
-     * Change order status with virtual products to completed
443
-     * @since  1.1.0
444
-     * @param string $order_status
445
-     * @param int $order_id
446
-     * @return string
447
-     **/
448
-    public function virtual_order_payment_complete( $order_status, $order_id ) {
449
-        $order = new WC_Order( $order_id );
450
-        if ( ! isset ( $order ) ) return '';
451
-        if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
452
-            $virtual_order = true;
453
-
454
-            if ( count( $order->get_items() ) > 0 ) {
455
-                foreach( $order->get_items() as $item ) {
456
-                    if ( $item['product_id'] > 0 ) {
457
-                        $_product = $order->get_product_from_item( $item );
458
-                        if ( ! $_product->is_virtual() ) {
459
-                            $virtual_order = false;
460
-                            break;
461
-                        } // End If Statement
462
-                    } // End If Statement
463
-                } // End For Loop
464
-            } // End If Statement
465
-
466
-            // virtual order, mark as completed
467
-            if ( $virtual_order ) {
468
-                return 'completed';
469
-            } // End If Statement
470
-        } // End If Statement
471
-        return $order_status;
472
-    }
473
-
474
-    /**
475
-     * Register the widgets.
476
-     * @access public
477
-     * @since  1.0.0
478
-     * @return void
479
-     */
480
-    public function register_widgets () {
481
-        // Widget List (key => value is filename => widget class).
482
-        $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 	'course-component' 	=> 'Course_Component',
483
-                'lesson-component' 	=> 'Lesson_Component',
484
-                'course-categories' => 'Course_Categories',
485
-                'category-courses' 	=> 'Category_Courses' )
486
-        );
487
-        foreach ( $widget_list as $key => $value ) {
488
-            if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key  . '.php' ) ) {
489
-                require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key  . '.php' );
490
-                register_widget( 'WooThemes_Sensei_' . $value . '_Widget' );
491
-            }
492
-        } // End For Loop
493
-
494
-        do_action( 'sensei_register_widgets' );
495
-
496
-    } // End register_widgets()
497
-
498
-    /**
499
-     * Load the plugin's localisation file.
500
-     * @access public
501
-     * @since  1.0.0
502
-     * @return void
503
-     */
504
-    public function load_localisation () {
505
-        load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' );
506
-    } // End load_localisation()
507
-
508
-    /**
509
-     * Load the plugin textdomain from the main WordPress "languages" folder.
510
-     * @access  public
511
-     * @since   1.0.0
512
-     * @return  void
513
-     */
514
-    public function load_plugin_textdomain () {
515
-        $domain = 'woothemes-sensei';
516
-        // The "plugin_locale" filter is also used in load_plugin_textdomain()
517
-        $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
518
-        load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
519
-        load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' );
520
-    } // End load_plugin_textdomain()
521
-
522
-    /**
523
-     * Run on activation.
524
-     * @access public
525
-     * @since  1.0.0
526
-     * @return void
527
-     */
528
-    public function activation () {
529
-        $this->register_plugin_version();
530
-    } // End activation()
531
-
532
-
533
-    /**
534
-     * Register activation hooks.
535
-     * @access public
536
-     * @since  1.0.0
537
-     * @return void
538
-     */
539
-    public function install () {
540
-        register_activation_hook( $this->file, array( $this, 'activate_sensei' ) );
541
-        register_activation_hook( $this->file, 'flush_rewrite_rules' );
542
-    } // End install()
543
-
544
-
545
-    /**
546
-     * Run on activation of the plugin.
547
-     * @access public
548
-     * @since  1.0.0
549
-     * @return void
550
-     */
551
-    public function activate_sensei () {
552
-        update_option( 'skip_install_sensei_pages', 0 );
553
-        update_option( 'sensei_installed', 1 );
554
-    } // End activate_sensei()
555
-
556
-    /**
557
-     * Register the plugin's version.
558
-     * @access public
559
-     * @since  1.0.0
560
-     * @return void
561
-     */
562
-    private function register_plugin_version () {
563
-        if ( $this->version != '' ) {
564
-
565
-            // Check previous version to see if forced updates must run
566
-            // $old_version = get_option( 'woothemes-sensei-version', false );
567
-            // if( $old_version && version_compare( $old_version, '1.7.0', '<' )  ) {
568
-            // 	update_option( 'woothemes-sensei-force-updates', $this->version );
569
-            // } else {
570
-            // 	delete_option( 'woothemes-sensei-force-updates' );
571
-            // }
572
-
573
-            update_option( 'woothemes-sensei-version', $this->version );
574
-        }
575
-    } // End register_plugin_version()
576
-
577
-    /**
578
-     * Ensure that "post-thumbnails" support is available for those themes that don't register it.
579
-     * @access  public
580
-     * @since   1.0.1
581
-     * @return  void
582
-     */
583
-    public function ensure_post_thumbnails_support () {
584
-        if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); }
585
-    } // End ensure_post_thumbnails_support()
586
-
587
-
588
-    /**
589
-     * template_loader function.
590
-     *
591
-     * @access public
592
-     * @param mixed $template
593
-     * @return void
594
-     * @deprecated
595
-     */
596
-    public function template_loader ( $template = '' ) {
597
-
598
-        _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' );
599
-        Sensei_Templates::template_loader( $template );
600
-
601
-    } // End template_loader()
602
-
603
-    /**
604
-     * Determine the relative path to the plugin's directory.
605
-     * @access public
606
-     * @since  1.0.0
607
-     * @return string $sensei_plugin_path
608
-     */
609
-    public function plugin_path () {
610
-
611
-        if ( $this->plugin_path ) {
612
-
613
-            $sensei_plugin_path =  $this->plugin_path;
614
-
615
-        }else{
616
-
617
-            $sensei_plugin_path = plugin_dir_path( __FILE__ );
618
-
619
-        }
620
-
621
-        return $sensei_plugin_path;
622
-
623
-    } // End plugin_path()
624
-
625
-
626
-    /**
627
-     * Retrieve the ID of a specified page setting.
628
-     * @access public
629
-     * @since  1.0.0
630
-     * @param  string $page
631
-     * @return int
632
-     */
633
-    public function get_page_id ( $page ) {
634
-        $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) );
635
-        return ( $page ) ? $page : -1;
636
-    } // End get_page_id()
637
-
638
-
639
-    /**
640
-     * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course.
641
-     * @access public
642
-     * @since  1.0.0
643
-     * @param  int 			$course_id  (default: 0)
644
-     * @param  array/Object $order_user (default: array()) Specific user's data.
645
-     * @return bool|int
646
-     */
647
-    public function woocommerce_course_update ( $course_id = 0, $order_user = array()  ) {
648
-        global $current_user;
649
-
650
-        if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false;
651
-
652
-        $data_update = false;
653
-
654
-        // Get the product ID
655
-        $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true );
656
-
657
-        // Check if in the admin
658
-        if ( is_admin() ) {
659
-            $user_login = $order_user['user_login'];
660
-            $user_email = $order_user['user_email'];
661
-            $user_url = $order_user['user_url'];
662
-            $user_id = $order_user['ID'];
663
-        } else {
664
-            $user_login = $current_user->user_login;
665
-            $user_email = $current_user->user_email;
666
-            $user_url = $current_user->user_url;
667
-            $user_id = $current_user->ID;
668
-        } // End If Statement
669
-
670
-        // This doesn't appear to be purely WooCommerce related. Should it be in a separate function?
671
-        $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true );
672
-        if( 0 < absint( $course_prerequisite_id ) ) {
673
-            $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) );
674
-            if ( ! $prereq_course_complete ) {
675
-                // Remove all course user meta
676
-                return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id );
677
-            }
678
-        }
679
-
680
-        $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) );
681
-
682
-        if( ! $is_user_taking_course ) {
683
-
684
-            if ( Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product( $user_email, $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) {
685
-
686
-                $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) );
687
-
688
-                $is_user_taking_course = false;
689
-                if ( true == $activity_logged ) {
690
-                    $is_user_taking_course = true;
691
-                } // End If Statement
692
-            } // End If Statement
693
-        }
694
-
695
-        return $is_user_taking_course;
696
-    } // End woocommerce_course_update()
697
-
698
-
699
-    /**
700
-     * check_user_permissions function.
701
-     *
702
-     * @access public
703
-     * @param string $page (default: '')
704
-     *
705
-     * @return bool
706
-     */
707
-    public function check_user_permissions ( $page = '' ) {
708
-        // REFACTOR
709
-        global $current_user, $post;
710
-
711
-        // if use is not logged in
712
-        if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission') ){
713
-            $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' );
714
-            $this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() );
715
-            return false;
716
-        }
717
-
718
-
719
-        // Get User Meta
720
-        get_currentuserinfo();
721
-
722
-        $user_allowed = false;
723
-
724
-        switch ( $page ) {
725
-            case 'course-single':
726
-                // check for prerequisite course or lesson,
727
-                $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true);
728
-                $update_course = $this->woocommerce_course_update( $post->ID );
729
-                // Count completed lessons
730
-                if ( 0 < absint( $course_prerequisite_id ) ) {
731
-
732
-                    $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID );
733
-
734
-                }
735
-                else {
736
-                    $prerequisite_complete = true;
737
-                } // End If Statement
738
-                // Handles restrictions
739
-                if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) {
740
-                    $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
741
-                    $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
742
-                    $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link );
743
-                } else {
744
-                    $user_allowed = true;
745
-                } // End If Statement
746
-                break;
747
-            case 'lesson-single':
748
-                // Check for WC purchase
749
-                $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true );
750
-
751
-                $update_course = $this->woocommerce_course_update( $lesson_course_id );
752
-                $is_preview = Sensei_Utils::is_preview_lesson( $post->ID );
753
-                if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) {
754
-                    $user_allowed = true;
755
-                } elseif( $this->access_settings() && false == $is_preview ) {
756
-
757
-                    $user_allowed = true;
758
-                } else {
759
-                    $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
760
-                    $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
761
-                    $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true );
762
-                    if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
763
-                        if ( $is_preview ) {
764
-                            $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link );
765
-                        } else {
766
-                            $this->permissions_message['message'] =  sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link );
767
-                        }
768
-                    } else {
769
-                        if ( $is_preview ) {
770
-                            $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link );
771
-                        } else {
772
-                            /** This filter is documented in class-woothemes-sensei-frontend.php */
773
-                            $this->permissions_message['message'] =  sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link );
774
-                        }
775
-                    } // End If Statement
776
-                } // End If Statement
777
-                break;
778
-            case 'quiz-single':
779
-                $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true );
780
-                $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true );
781
-
782
-                $update_course = $this->woocommerce_course_update( $lesson_course_id );
783
-                if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) {
784
-
785
-                    // Check for prerequisite lesson for this quiz
786
-                    $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true);
787
-                    $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID);
788
-
789
-                    // Handle restrictions
790
-                    if( sensei_all_access() ) {
791
-                        $user_allowed = true;
792
-                    } else {
793
-                        if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) {
794
-                            $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
795
-                            $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>';
796
-                            $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link );
797
-                        } else {
798
-                            $user_allowed = true;
799
-                        } // End If Statement
800
-                    } // End If Statement
801
-                } elseif( $this->access_settings() ) {
802
-                    // Check if the user has started the course
803
-
804
-                    if ( is_user_logged_in() && ! Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) && ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) ) {
805
-
806
-                        $user_allowed = false;
807
-                        $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
808
-                        $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
809
-                        $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true );
810
-                        if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
811
-                            $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link );
812
-                        } else {
813
-                            $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link );
814
-                        } // End If Statement
815
-                    } else {
816
-                        $user_allowed = true;
817
-                    } // End If Statement
818
-                } else {
819
-                    $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
820
-                    $course_link = '<a href="' . esc_url( get_permalink( get_post_meta( get_post_meta( $post->ID, '_quiz_lesson', true ), '_lesson_course', true ) ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
821
-                    $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link );
822
-                } // End If Statement
823
-                break;
824
-            default:
825
-                $user_allowed = true;
826
-                break;
827
-
828
-        } // End Switch Statement
829
-
830
-        /**
831
-         * filter the permissions message shown on sensei post types.
832
-         *
833
-         * @since 1.8.7
834
-         *
835
-         * @param array $permissions_message{
836
-         *
837
-         *   @type string $title
838
-         *   @type string $message
839
-         *
840
-         * }
841
-         * @param string $post_id
842
-         */
843
-        $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID );
844
-
845
-
846
-        if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) {
847
-            $user_allowed = true;
848
-        }
849
-
850
-        return apply_filters( 'sensei_access_permissions', $user_allowed );
851
-    } // End get_placeholder_image()
852
-
853
-
854
-    /**
855
-     * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check.
856
-     * @since  1.0.0
857
-     * @access public
858
-     * @return bool
859
-     */
860
-    public function access_settings () {
861
-
862
-        if( sensei_all_access() ) return true;
863
-
864
-        if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) {
865
-            if ( is_user_logged_in() ) {
866
-                return true;
867
-            } else {
868
-                return false;
869
-            } // End If Statement
870
-        } else {
871
-            return true;
872
-        } // End If Statement
873
-    } // End access_settings()
874
-
875
-    /**
876
-     * sensei_woocommerce_complete_order description
877
-     * @since   1.0.3
878
-     * @access  public
879
-     * @param   int $order_id WC order ID
880
-     * @return  void
881
-     */
882
-    public function sensei_woocommerce_complete_order ( $order_id = 0 ) {
883
-        $order_user = array();
884
-        // Check for WooCommerce
885
-        if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) {
886
-            // Get order object
887
-            $order = new WC_Order( $order_id );
888
-            $user = get_user_by( 'id', $order->get_user_id() );
889
-            $order_user['ID'] = $user->ID;
890
-            $order_user['user_login'] = $user->user_login;
891
-            $order_user['user_email'] = $user->user_email;
892
-            $order_user['user_url'] = $user->user_url;
893
-            // Run through each product ordered
894
-            if ( 0 < sizeof( $order->get_items() ) ) {
895
-                foreach( $order->get_items() as $item ) {
896
-                    $product_type = '';
897
-                    if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
898
-                        $item_id = $item['variation_id'];
899
-                        $product_type = 'variation';
900
-                    } else {
901
-                        $item_id = $item['product_id'];
902
-                    } // End If Statement
903
-                    $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
904
-                    // Get courses that use the WC product
905
-                    $courses = $this->post_types->course->get_product_courses( $_product->id );
906
-                    // Loop and update those courses
907
-                    foreach ( $courses as $course_item ) {
908
-                        $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
909
-                    } // End For Loop
910
-                } // End For Loop
911
-            } // End If Statement
912
-            // Add meta to indicate that payment has been completed successfully
913
-            update_post_meta( $order_id, 'sensei_payment_complete', '1' );
914
-        } // End If Statement
915
-    } // End sensei_woocommerce_complete_order()
916
-
917
-    /**
918
-     * Runs when an order is cancelled.
919
-     * @since   1.2.0
920
-     * @access  public
921
-     * @param   integer $order_id order ID
922
-     * @return  void
923
-     */
924
-    public function sensei_woocommerce_cancel_order ( $order_id ) {
925
-
926
-        // Get order object
927
-        $order = new WC_Order( $order_id );
928
-
929
-        // Run through each product ordered
930
-        if ( 0 < sizeof( $order->get_items() ) ) {
931
-
932
-            // Get order user
933
-            $user_id = $order->__get( 'user_id' );
934
-
935
-            foreach( $order->get_items() as $item ) {
936
-
937
-                $product_type = '';
938
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
939
-                    $item_id = $item['variation_id'];
940
-                    $product_type = 'variation';
941
-                } else {
942
-                    $item_id = $item['product_id'];
943
-                } // End If Statement
944
-                $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
945
-
946
-                // Get courses that use the WC product
947
-                $courses = array();
948
-                $courses = $this->post_types->course->get_product_courses( $item_id );
949
-
950
-                // Loop and update those courses
951
-                foreach ($courses as $course_item){
952
-                    // Check and Remove course from courses user meta
953
-                    $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id );
954
-                } // End For Loop
955
-            } // End For Loop
956
-        } // End If Statement
957
-    } // End sensei_woocommerce_cancel_order()
958
-
959
-    /**
960
-     * Runs when an subscription is cancelled or expires.
961
-     * @since   1.3.3
962
-     * @access  public
963
-     * @param   integer $user_id User ID
964
-     * @param   integer $subscription_key Subscription Unique Key
965
-     * @return  void
966
-     */
967
-    public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ) {
968
-        $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key );
969
-        self::sensei_woocommerce_cancel_order( $subscription['order_id'] );
970
-    }
971
-
972
-    /**
973
-     * Runs when an subscription is re-activated after suspension.
974
-     * @since   1.3.3
975
-     * @access  public
976
-     * @param   integer $user_id User ID
977
-     * @param   integer $subscription_key Subscription Unique Key
978
-     * @return  void
979
-     */
980
-    public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ) {
981
-        $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key );
982
-        $order = new WC_Order( $subscription['order_id'] );
983
-        $user = get_user_by( 'id', $order->get_user_id() );
984
-        $order_user = array();
985
-        $order_user['ID'] = $user->ID;
986
-        $order_user['user_login'] = $user->user_login;
987
-        $order_user['user_email'] = $user->user_email;
988
-        $order_user['user_url'] = $user->user_url;
989
-        $courses = $this->post_types->course->get_product_courses( $subscription['product_id'] );
990
-        foreach ( $courses as $course_item ){
991
-            $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
992
-        } // End For Loop
993
-    } // End sensei_woocommerce_reactivate_subscription
994
-
995
-    /**
996
-     * Returns the WooCommerce Product Object
997
-     *
998
-     * The code caters for pre and post WooCommerce 2.2 installations.
999
-     *
1000
-     * @since   1.1.1
1001
-     * @access  public
1002
-     * @param   integer $wc_product_id Product ID or Variation ID
1003
-     * @param   string  $product_type  '' or 'variation'
1004
-     * @return   WC_Product $wc_product_object
1005
-     */
1006
-    public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) {
1007
-
1008
-        $wc_product_object = false;
1009
-        if ( 0 < intval( $wc_product_id ) ) {
1010
-
1011
-            // Get the product
1012
-            if ( function_exists( 'wc_get_product' ) ) {
1013
-
1014
-                $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3
1015
-
1016
-            } elseif ( function_exists( 'get_product' ) ) {
1017
-
1018
-                $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0
1019
-
1020
-            } else {
1021
-
1022
-                // Pre WC 2.0
1023
-                if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) {
1024
-
1025
-                    $wc_product_object = new WC_Product_Variation( $wc_product_id );
1026
-
1027
-                } else {
1028
-
1029
-                    $wc_product_object = new WC_Product( $wc_product_id );
1030
-
1031
-                } // End If Statement
1032
-
1033
-            } // End If Statement
1034
-
1035
-        } // End If Statement
1036
-
1037
-        return $wc_product_object;
1038
-
1039
-    } // End sensei_get_woocommerce_product_object()
1040
-
1041
-    /**
1042
-     * load_class loads in class files
1043
-     * @since   1.2.0
1044
-     * @access  public
1045
-     * @return  void
1046
-     */
1047
-    public function load_class ( $class_name = '' ) {
1048
-        if ( '' != $class_name && '' != $this->token ) {
1049
-            require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' );
1050
-        } // End If Statement
1051
-    } // End load_class()
1052
-
1053
-    /**
1054
-     * sensei_activate_subscription runs when a subscription product is purchased
1055
-     * @since   1.2.0
1056
-     * @access  public
1057
-     * @param   integer $order_id order ID
1058
-     * @return  void
1059
-     */
1060
-    public function sensei_activate_subscription(  $order_id = 0 ) {
1061
-        if ( 0 < intval( $order_id ) ) {
1062
-            $order = new WC_Order( $order_id );
1063
-            $user = get_user_by('id', $order->user_id);
1064
-            $order_user['ID'] = $user->ID;
1065
-            $order_user['user_login'] = $user->user_login;
1066
-            $order_user['user_email'] = $user->user_email;
1067
-            $order_user['user_url'] = $user->user_url;
1068
-            // Run through each product ordered
1069
-            if (sizeof($order->get_items())>0) {
1070
-                foreach($order->get_items() as $item) {
1071
-                    $product_type = '';
1072
-                    if (isset($item['variation_id']) && $item['variation_id'] > 0) {
1073
-                        $item_id = $item['variation_id'];
1074
-                        $product_type = 'subscription_variation';
1075
-                    } else {
1076
-                        $item_id = $item['product_id'];
1077
-                    } // End If Statement
1078
-                    $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
1079
-                    // Get courses that use the WC product
1080
-                    $courses = array();
1081
-                    if ( $product_type == 'subscription_variation' ) {
1082
-                        $courses = $this->post_types->course->get_product_courses( $item_id );
1083
-                    } // End If Statement
1084
-                    // Loop and update those courses
1085
-                    foreach ($courses as $course_item){
1086
-                        $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
1087
-                    } // End For Loop
1088
-                } // End For Loop
1089
-            } // End If Statement
1090
-        } // End If Statement
1091
-    } // End sensei_activate_subscription()
1092
-
1093
-    /**
1094
-     * sensei_woocommerce_email_course_details adds detail to email
1095
-     * @since   1.4.5
1096
-     * @access  public
1097
-     * @param   WC_Order $order
1098
-     * @return  void
1099
-     */
1100
-    public function sensei_woocommerce_email_course_details( $order ) {
1101
-        global $woocommerce;
1102
-
1103
-        // exit early if not wc-completed or wc-processing
1104
-        if( 'wc-completed' != $order->post_status
1105
-            && 'wc-processing' != $order->post_status  ) {
1106
-            return;
1107
-        }
1108
-
1109
-        $order_items = $order->get_items();
1110
-        $order_id = $order->id;
1111
-
1112
-        //If object have items go through them all to find course
1113
-        if ( 0 < sizeof( $order_items ) ) {
1114
-
1115
-        echo '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>';
1116
-
1117
-        foreach ( $order_items as $item ) {
1118
-
1119
-                $product_type = '';
1120
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1121
-                    // If item has variation_id then its from variation
1122
-                    $item_id = $item['variation_id'];
1123
-                    $product_type = 'variation';
1124
-                } else {
1125
-                    // If not its real product set its id to item_id
1126
-                    $item_id = $item['product_id'];
1127
-                } // End If Statement
1128
-
1129
-                $user_id = get_post_meta( $order_id, '_customer_user', true );
1130
-
1131
-                if( $user_id ) {
1132
-
1133
-                    // Get all courses for product
1134
-                    $args = array(
1135
-                        'posts_per_page' => -1,
1136
-                        'post_type' => 'course',
1137
-                        'meta_query' => array(
1138
-                            array(
1139
-                                'key' => '_course_woocommerce_product',
1140
-                                'value' => $item_id
1141
-                            )
1142
-                        ),
1143
-                        'orderby' => 'menu_order date',
1144
-                        'order' => 'ASC',
1145
-                    );
1146
-                    $courses = get_posts( $args );
1147
-
1148
-                    if( $courses && count( $courses ) > 0 ) {
1149
-
1150
-                        foreach( $courses as $course ) {
1151
-
1152
-                            $title = $course->post_title;
1153
-                            $permalink = get_permalink( $course->ID );
1154
-
1155
-                            echo '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>';
1156
-                        }
1157
-                    }
1158
-                }
1159
-            }
1160
-        }
1161
-    }
1162
-
1163
-    /**
1164
-     * Filtering wp_count_comments to ensure that Sensei comments are ignored
1165
-     * @since   1.4.0
1166
-     * @access  public
1167
-     * @param  array   $comments
1168
-     * @param  integer $post_id
1169
-     * @return array
1170
-     */
1171
-    public function sensei_count_comments( $comments, $post_id ) {
1172
-        global $wpdb;
1173
-
1174
-        $post_id = (int) $post_id;
1175
-
1176
-        $count = wp_cache_get("comments-{$post_id}", 'counts');
1177
-
1178
-        if ( false !== $count ) {
1179
-            return $count;
1180
-        }
1181
-
1182
-        $statuses = array( '' ); // Default to the WP normal comments
1183
-        $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A );
1184
-        foreach ( (array) $stati AS $status ) {
1185
-            if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) {
1186
-                $statuses[] = $status['comment_type'];
1187
-            }
1188
-        }
1189
-        $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')";
1190
-
1191
-        if ( $post_id > 0 )
1192
-            $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id );
1193
-
1194
-        $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );
1195
-
1196
-        $total = 0;
1197
-        $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed');
1198
-        foreach ( (array) $count as $row ) {
1199
-            // Don't count post-trashed toward totals
1200
-            if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] )
1201
-                $total += $row['num_comments'];
1202
-            if ( isset( $approved[$row['comment_approved']] ) )
1203
-                $stats[$approved[$row['comment_approved']]] = $row['num_comments'];
1204
-        }
1205
-
1206
-        $stats['total_comments'] = $total;
1207
-        foreach ( $approved as $key ) {
1208
-            if ( empty($stats[$key]) )
1209
-                $stats[$key] = 0;
1210
-        }
1211
-
1212
-        $stats = (object) $stats;
1213
-        wp_cache_set("comments-{$post_id}", $stats, 'counts');
1214
-
1215
-        return $stats;
1216
-    }
1217
-
1218
-    /**
1219
-     * Init images.
1220
-     *
1221
-     * @since 1.4.5
1222
-     * @access public
1223
-     * @return void
1224
-     */
1225
-    public function init_image_sizes() {
1226
-        $course_archive_thumbnail 	= $this->get_image_size( 'course_archive_image' );
1227
-        $course_single_thumbnail	= $this->get_image_size( 'course_single_image' );
1228
-        $lesson_archive_thumbnail 	= $this->get_image_size( 'lesson_archive_image' );
1229
-        $lesson_single_thumbnail	= $this->get_image_size( 'lesson_single_image' );
1230
-
1231
-        add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] );
1232
-        add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] );
1233
-        add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] );
1234
-        add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] );
1235
-    }
1236
-
1237
-    /**
1238
-     * Get an image size.
1239
-     *
1240
-     * Variable is filtered by sensei_get_image_size_{image_size}
1241
-     *
1242
-     * @since 1.4.5
1243
-     * @access public
1244
-     * @param mixed $image_size
1245
-     * @return string
1246
-     */
1247
-    public function get_image_size( $image_size ) {
1248
-
1249
-        // Only return sizes we define in settings
1250
-        if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) )
1251
-            return apply_filters( 'sensei_get_image_size_' . $image_size, '' );
1252
-
1253
-        if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) {
1254
-            $this->settings->settings[ $image_size . '_width' ] = false;
1255
-        }
1256
-        if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) {
1257
-            $this->settings->settings[ $image_size . '_height' ] = false;
1258
-        }
1259
-        if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) {
1260
-            $this->settings->settings[ $image_size . '_hard_crop' ] = false;
1261
-        }
1262
-
1263
-        $size = array_filter( array(
1264
-            'width' => $this->settings->settings[ $image_size . '_width' ],
1265
-            'height' => $this->settings->settings[ $image_size . '_height' ],
1266
-            'crop' => $this->settings->settings[ $image_size . '_hard_crop' ]
1267
-        ) );
1268
-
1269
-        $size['width'] 	= isset( $size['width'] ) ? $size['width'] : '100';
1270
-        $size['height'] = isset( $size['height'] ) ? $size['height'] : '100';
1271
-        $size['crop'] 	= isset( $size['crop'] ) ? $size['crop'] : 0;
1272
-
1273
-        return apply_filters( 'sensei_get_image_size_' . $image_size, $size );
1274
-    }
1275
-
1276
-    public function body_class( $classes ) {
1277
-        if( is_sensei() ) {
1278
-            $classes[] = 'sensei';
1279
-        }
1280
-        return $classes;
1281
-    }
1282
-
1283
-    /**
1284
-     * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers
1285
-     *
1286
-     * @return null
1287
-     * @since 1.7.0
1288
-     */
1289
-    public function jetpack_latex_support() {
1290
-        if ( function_exists( 'latex_markup') ) {
1291
-            add_filter( 'sensei_question_title', 'latex_markup' );
1292
-            add_filter( 'sensei_answer_text', 'latex_markup' );
1293
-        }
1294
-    }
1295
-
1296
-    /**
1297
-     * Load the module functionality.
1298
-     *
1299
-     * This function is hooked into plugins_loaded to avoid conflicts with
1300
-     * the retired modules extension.
1301
-     *
1302
-     * @since 1.8.0
1303
-     */
1304
-    public function load_modules_class(){
1305
-        global $sensei_modules;
1306
-
1307
-        if( !class_exists( 'Sensei_Modules' )
1308
-            &&  'Sensei_Modules' != get_class( $sensei_modules ) ) {
1309
-
1310
-            //Load the modules class
1311
-            require_once( 'class-sensei-modules.php');
1312
-            Sensei()->modules = new Sensei_Core_Modules( $this->file );
1313
-
1314
-        }else{
1315
-            // fallback for people still using the modules extension.
1316
-            global $sensei_modules;
1317
-            Sensei()->modules = $sensei_modules;
1318
-            add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 );
1319
-        }
1320
-    }
1321
-
1322
-    /**
1323
-     * Tell the user to that the modules extension is no longer needed.
1324
-     *
1325
-     * @since 1.8.0
1326
-     */
1327
-    public function disable_sensei_modules_extension(){ ?>
329
+	/**
330
+	 * Initialize all Sensei hooks
331
+	 *
332
+	 * @since 1.9.0
333
+	 */
334
+	public function load_hooks(){
335
+
336
+		add_action( 'widgets_init', array( $this, 'register_widgets' ) );
337
+		add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) );
338
+
339
+		// WooCommerce Payment Actions
340
+		add_action( 'woocommerce_payment_complete' , array( $this, 'sensei_woocommerce_complete_order' ) );
341
+		add_action( 'woocommerce_thankyou' , array( $this, 'sensei_woocommerce_complete_order' ) );
342
+		add_action( 'woocommerce_order_status_completed' , array( $this, 'sensei_woocommerce_complete_order' ) );
343
+		add_action( 'woocommerce_order_status_processing' , array( $this, 'sensei_woocommerce_complete_order' ) );
344
+		add_action( 'woocommerce_order_status_cancelled' , array( $this, 'sensei_woocommerce_cancel_order' ) );
345
+		add_action( 'woocommerce_order_status_refunded' , array( $this, 'sensei_woocommerce_cancel_order' ) );
346
+		add_action( 'subscriptions_activated_for_order', array( $this, 'sensei_activate_subscription' ) );
347
+
348
+		// WooCommerce Subscriptions Actions
349
+		add_action( 'reactivated_subscription', array( $this, 'sensei_woocommerce_reactivate_subscription' ), 10, 2 );
350
+		add_action( 'subscription_expired' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
351
+		add_action( 'subscription_end_of_prepaid_term' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
352
+		add_action( 'cancelled_subscription' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
353
+		add_action( 'subscription_put_on-hold' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
354
+
355
+		// Add Email link to course orders
356
+		add_action( 'woocommerce_email_after_order_table', array( $this, 'sensei_woocommerce_email_course_details' ), 10, 1 );
357
+
358
+		// Filter comment counts
359
+		add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 );
360
+
361
+		add_action( 'body_class', array( $this, 'body_class' ) );
362
+
363
+		// Check for and activate JetPack LaTeX support
364
+		add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules
365
+
366
+		// check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1
367
+		add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 );
368
+
369
+	}
370
+
371
+	/**
372
+	 * Run Sensei updates.
373
+	 * @access  public
374
+	 * @since   1.1.0
375
+	 * @return  void
376
+	 */
377
+	public function run_updates() {
378
+		// Run updates if administrator
379
+		if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) {
380
+
381
+			$this->updates->update();
382
+
383
+		} // End If Statement
384
+	} // End run_updates()
385
+
386
+
387
+
388
+	/**
389
+	 * Setup required WooCommerce settings.
390
+	 * @access  public
391
+	 * @since   1.1.0
392
+	 * @return  void
393
+	 */
394
+	public function set_woocommerce_functionality() {
395
+		// Disable guest checkout if a course is in the cart as we need a valid user to store data for
396
+		add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( $this, 'disable_guest_checkout' ) );
397
+
398
+		// Mark orders with virtual products as complete rather then stay processing
399
+		add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'virtual_order_payment_complete' ), 10, 2 );
400
+
401
+	} // End set_woocommerce_functionality()
402
+
403
+	/**
404
+	 * Disable guest checkout if a course product is in the cart
405
+	 * @param  boolean $guest_checkout Current guest checkout setting
406
+	 * @return boolean                 Modified guest checkout setting
407
+	 */
408
+	public function disable_guest_checkout( $guest_checkout ) {
409
+		global $woocommerce;
410
+
411
+		if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
412
+
413
+			if( isset( $woocommerce->cart->cart_contents ) && count( $woocommerce->cart->cart_contents ) > 0 ) {
414
+				foreach( $woocommerce->cart->cart_contents as $cart_key => $product ) {
415
+					if( isset( $product['product_id'] ) ) {
416
+						$args = array(
417
+							'posts_per_page' => -1,
418
+							'post_type' => 'course',
419
+							'meta_query' => array(
420
+								array(
421
+									'key' => '_course_woocommerce_product',
422
+									'value' => $product['product_id']
423
+								)
424
+							)
425
+						);
426
+						$posts = get_posts( $args );
427
+						if( $posts && count( $posts ) > 0 ) {
428
+							foreach( $posts as $course ) {
429
+								$guest_checkout = '';
430
+								break;
431
+							}
432
+						}
433
+					}
434
+				}
435
+			}
436
+		}
437
+
438
+		return $guest_checkout;
439
+	}
440
+
441
+	/**
442
+	 * Change order status with virtual products to completed
443
+	 * @since  1.1.0
444
+	 * @param string $order_status
445
+	 * @param int $order_id
446
+	 * @return string
447
+	 **/
448
+	public function virtual_order_payment_complete( $order_status, $order_id ) {
449
+		$order = new WC_Order( $order_id );
450
+		if ( ! isset ( $order ) ) return '';
451
+		if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
452
+			$virtual_order = true;
453
+
454
+			if ( count( $order->get_items() ) > 0 ) {
455
+				foreach( $order->get_items() as $item ) {
456
+					if ( $item['product_id'] > 0 ) {
457
+						$_product = $order->get_product_from_item( $item );
458
+						if ( ! $_product->is_virtual() ) {
459
+							$virtual_order = false;
460
+							break;
461
+						} // End If Statement
462
+					} // End If Statement
463
+				} // End For Loop
464
+			} // End If Statement
465
+
466
+			// virtual order, mark as completed
467
+			if ( $virtual_order ) {
468
+				return 'completed';
469
+			} // End If Statement
470
+		} // End If Statement
471
+		return $order_status;
472
+	}
473
+
474
+	/**
475
+	 * Register the widgets.
476
+	 * @access public
477
+	 * @since  1.0.0
478
+	 * @return void
479
+	 */
480
+	public function register_widgets () {
481
+		// Widget List (key => value is filename => widget class).
482
+		$widget_list = apply_filters( 'sensei_registered_widgets_list', array( 	'course-component' 	=> 'Course_Component',
483
+				'lesson-component' 	=> 'Lesson_Component',
484
+				'course-categories' => 'Course_Categories',
485
+				'category-courses' 	=> 'Category_Courses' )
486
+		);
487
+		foreach ( $widget_list as $key => $value ) {
488
+			if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key  . '.php' ) ) {
489
+				require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key  . '.php' );
490
+				register_widget( 'WooThemes_Sensei_' . $value . '_Widget' );
491
+			}
492
+		} // End For Loop
493
+
494
+		do_action( 'sensei_register_widgets' );
495
+
496
+	} // End register_widgets()
497
+
498
+	/**
499
+	 * Load the plugin's localisation file.
500
+	 * @access public
501
+	 * @since  1.0.0
502
+	 * @return void
503
+	 */
504
+	public function load_localisation () {
505
+		load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' );
506
+	} // End load_localisation()
507
+
508
+	/**
509
+	 * Load the plugin textdomain from the main WordPress "languages" folder.
510
+	 * @access  public
511
+	 * @since   1.0.0
512
+	 * @return  void
513
+	 */
514
+	public function load_plugin_textdomain () {
515
+		$domain = 'woothemes-sensei';
516
+		// The "plugin_locale" filter is also used in load_plugin_textdomain()
517
+		$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
518
+		load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
519
+		load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' );
520
+	} // End load_plugin_textdomain()
521
+
522
+	/**
523
+	 * Run on activation.
524
+	 * @access public
525
+	 * @since  1.0.0
526
+	 * @return void
527
+	 */
528
+	public function activation () {
529
+		$this->register_plugin_version();
530
+	} // End activation()
531
+
532
+
533
+	/**
534
+	 * Register activation hooks.
535
+	 * @access public
536
+	 * @since  1.0.0
537
+	 * @return void
538
+	 */
539
+	public function install () {
540
+		register_activation_hook( $this->file, array( $this, 'activate_sensei' ) );
541
+		register_activation_hook( $this->file, 'flush_rewrite_rules' );
542
+	} // End install()
543
+
544
+
545
+	/**
546
+	 * Run on activation of the plugin.
547
+	 * @access public
548
+	 * @since  1.0.0
549
+	 * @return void
550
+	 */
551
+	public function activate_sensei () {
552
+		update_option( 'skip_install_sensei_pages', 0 );
553
+		update_option( 'sensei_installed', 1 );
554
+	} // End activate_sensei()
555
+
556
+	/**
557
+	 * Register the plugin's version.
558
+	 * @access public
559
+	 * @since  1.0.0
560
+	 * @return void
561
+	 */
562
+	private function register_plugin_version () {
563
+		if ( $this->version != '' ) {
564
+
565
+			// Check previous version to see if forced updates must run
566
+			// $old_version = get_option( 'woothemes-sensei-version', false );
567
+			// if( $old_version && version_compare( $old_version, '1.7.0', '<' )  ) {
568
+			// 	update_option( 'woothemes-sensei-force-updates', $this->version );
569
+			// } else {
570
+			// 	delete_option( 'woothemes-sensei-force-updates' );
571
+			// }
572
+
573
+			update_option( 'woothemes-sensei-version', $this->version );
574
+		}
575
+	} // End register_plugin_version()
576
+
577
+	/**
578
+	 * Ensure that "post-thumbnails" support is available for those themes that don't register it.
579
+	 * @access  public
580
+	 * @since   1.0.1
581
+	 * @return  void
582
+	 */
583
+	public function ensure_post_thumbnails_support () {
584
+		if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); }
585
+	} // End ensure_post_thumbnails_support()
586
+
587
+
588
+	/**
589
+	 * template_loader function.
590
+	 *
591
+	 * @access public
592
+	 * @param mixed $template
593
+	 * @return void
594
+	 * @deprecated
595
+	 */
596
+	public function template_loader ( $template = '' ) {
597
+
598
+		_deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' );
599
+		Sensei_Templates::template_loader( $template );
600
+
601
+	} // End template_loader()
602
+
603
+	/**
604
+	 * Determine the relative path to the plugin's directory.
605
+	 * @access public
606
+	 * @since  1.0.0
607
+	 * @return string $sensei_plugin_path
608
+	 */
609
+	public function plugin_path () {
610
+
611
+		if ( $this->plugin_path ) {
612
+
613
+			$sensei_plugin_path =  $this->plugin_path;
614
+
615
+		}else{
616
+
617
+			$sensei_plugin_path = plugin_dir_path( __FILE__ );
618
+
619
+		}
620
+
621
+		return $sensei_plugin_path;
622
+
623
+	} // End plugin_path()
624
+
625
+
626
+	/**
627
+	 * Retrieve the ID of a specified page setting.
628
+	 * @access public
629
+	 * @since  1.0.0
630
+	 * @param  string $page
631
+	 * @return int
632
+	 */
633
+	public function get_page_id ( $page ) {
634
+		$page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) );
635
+		return ( $page ) ? $page : -1;
636
+	} // End get_page_id()
637
+
638
+
639
+	/**
640
+	 * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course.
641
+	 * @access public
642
+	 * @since  1.0.0
643
+	 * @param  int 			$course_id  (default: 0)
644
+	 * @param  array/Object $order_user (default: array()) Specific user's data.
645
+	 * @return bool|int
646
+	 */
647
+	public function woocommerce_course_update ( $course_id = 0, $order_user = array()  ) {
648
+		global $current_user;
649
+
650
+		if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false;
651
+
652
+		$data_update = false;
653
+
654
+		// Get the product ID
655
+		$wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true );
656
+
657
+		// Check if in the admin
658
+		if ( is_admin() ) {
659
+			$user_login = $order_user['user_login'];
660
+			$user_email = $order_user['user_email'];
661
+			$user_url = $order_user['user_url'];
662
+			$user_id = $order_user['ID'];
663
+		} else {
664
+			$user_login = $current_user->user_login;
665
+			$user_email = $current_user->user_email;
666
+			$user_url = $current_user->user_url;
667
+			$user_id = $current_user->ID;
668
+		} // End If Statement
669
+
670
+		// This doesn't appear to be purely WooCommerce related. Should it be in a separate function?
671
+		$course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true );
672
+		if( 0 < absint( $course_prerequisite_id ) ) {
673
+			$prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) );
674
+			if ( ! $prereq_course_complete ) {
675
+				// Remove all course user meta
676
+				return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id );
677
+			}
678
+		}
679
+
680
+		$is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) );
681
+
682
+		if( ! $is_user_taking_course ) {
683
+
684
+			if ( Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product( $user_email, $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) {
685
+
686
+				$activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) );
687
+
688
+				$is_user_taking_course = false;
689
+				if ( true == $activity_logged ) {
690
+					$is_user_taking_course = true;
691
+				} // End If Statement
692
+			} // End If Statement
693
+		}
694
+
695
+		return $is_user_taking_course;
696
+	} // End woocommerce_course_update()
697
+
698
+
699
+	/**
700
+	 * check_user_permissions function.
701
+	 *
702
+	 * @access public
703
+	 * @param string $page (default: '')
704
+	 *
705
+	 * @return bool
706
+	 */
707
+	public function check_user_permissions ( $page = '' ) {
708
+		// REFACTOR
709
+		global $current_user, $post;
710
+
711
+		// if use is not logged in
712
+		if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission') ){
713
+			$this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' );
714
+			$this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() );
715
+			return false;
716
+		}
717
+
718
+
719
+		// Get User Meta
720
+		get_currentuserinfo();
721
+
722
+		$user_allowed = false;
723
+
724
+		switch ( $page ) {
725
+			case 'course-single':
726
+				// check for prerequisite course or lesson,
727
+				$course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true);
728
+				$update_course = $this->woocommerce_course_update( $post->ID );
729
+				// Count completed lessons
730
+				if ( 0 < absint( $course_prerequisite_id ) ) {
731
+
732
+					$prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID );
733
+
734
+				}
735
+				else {
736
+					$prerequisite_complete = true;
737
+				} // End If Statement
738
+				// Handles restrictions
739
+				if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) {
740
+					$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
741
+					$course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
742
+					$this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link );
743
+				} else {
744
+					$user_allowed = true;
745
+				} // End If Statement
746
+				break;
747
+			case 'lesson-single':
748
+				// Check for WC purchase
749
+				$lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true );
750
+
751
+				$update_course = $this->woocommerce_course_update( $lesson_course_id );
752
+				$is_preview = Sensei_Utils::is_preview_lesson( $post->ID );
753
+				if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) {
754
+					$user_allowed = true;
755
+				} elseif( $this->access_settings() && false == $is_preview ) {
756
+
757
+					$user_allowed = true;
758
+				} else {
759
+					$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
760
+					$course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
761
+					$wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true );
762
+					if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
763
+						if ( $is_preview ) {
764
+							$this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link );
765
+						} else {
766
+							$this->permissions_message['message'] =  sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link );
767
+						}
768
+					} else {
769
+						if ( $is_preview ) {
770
+							$this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link );
771
+						} else {
772
+							/** This filter is documented in class-woothemes-sensei-frontend.php */
773
+							$this->permissions_message['message'] =  sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link );
774
+						}
775
+					} // End If Statement
776
+				} // End If Statement
777
+				break;
778
+			case 'quiz-single':
779
+				$lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true );
780
+				$lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true );
781
+
782
+				$update_course = $this->woocommerce_course_update( $lesson_course_id );
783
+				if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) {
784
+
785
+					// Check for prerequisite lesson for this quiz
786
+					$lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true);
787
+					$user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID);
788
+
789
+					// Handle restrictions
790
+					if( sensei_all_access() ) {
791
+						$user_allowed = true;
792
+					} else {
793
+						if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) {
794
+							$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
795
+							$lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>';
796
+							$this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link );
797
+						} else {
798
+							$user_allowed = true;
799
+						} // End If Statement
800
+					} // End If Statement
801
+				} elseif( $this->access_settings() ) {
802
+					// Check if the user has started the course
803
+
804
+					if ( is_user_logged_in() && ! Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) && ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) ) {
805
+
806
+						$user_allowed = false;
807
+						$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
808
+						$course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
809
+						$wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true );
810
+						if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
811
+							$this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link );
812
+						} else {
813
+							$this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link );
814
+						} // End If Statement
815
+					} else {
816
+						$user_allowed = true;
817
+					} // End If Statement
818
+				} else {
819
+					$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
820
+					$course_link = '<a href="' . esc_url( get_permalink( get_post_meta( get_post_meta( $post->ID, '_quiz_lesson', true ), '_lesson_course', true ) ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
821
+					$this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link );
822
+				} // End If Statement
823
+				break;
824
+			default:
825
+				$user_allowed = true;
826
+				break;
827
+
828
+		} // End Switch Statement
829
+
830
+		/**
831
+		 * filter the permissions message shown on sensei post types.
832
+		 *
833
+		 * @since 1.8.7
834
+		 *
835
+		 * @param array $permissions_message{
836
+		 *
837
+		 *   @type string $title
838
+		 *   @type string $message
839
+		 *
840
+		 * }
841
+		 * @param string $post_id
842
+		 */
843
+		$this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID );
844
+
845
+
846
+		if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) {
847
+			$user_allowed = true;
848
+		}
849
+
850
+		return apply_filters( 'sensei_access_permissions', $user_allowed );
851
+	} // End get_placeholder_image()
852
+
853
+
854
+	/**
855
+	 * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check.
856
+	 * @since  1.0.0
857
+	 * @access public
858
+	 * @return bool
859
+	 */
860
+	public function access_settings () {
861
+
862
+		if( sensei_all_access() ) return true;
863
+
864
+		if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) {
865
+			if ( is_user_logged_in() ) {
866
+				return true;
867
+			} else {
868
+				return false;
869
+			} // End If Statement
870
+		} else {
871
+			return true;
872
+		} // End If Statement
873
+	} // End access_settings()
874
+
875
+	/**
876
+	 * sensei_woocommerce_complete_order description
877
+	 * @since   1.0.3
878
+	 * @access  public
879
+	 * @param   int $order_id WC order ID
880
+	 * @return  void
881
+	 */
882
+	public function sensei_woocommerce_complete_order ( $order_id = 0 ) {
883
+		$order_user = array();
884
+		// Check for WooCommerce
885
+		if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) {
886
+			// Get order object
887
+			$order = new WC_Order( $order_id );
888
+			$user = get_user_by( 'id', $order->get_user_id() );
889
+			$order_user['ID'] = $user->ID;
890
+			$order_user['user_login'] = $user->user_login;
891
+			$order_user['user_email'] = $user->user_email;
892
+			$order_user['user_url'] = $user->user_url;
893
+			// Run through each product ordered
894
+			if ( 0 < sizeof( $order->get_items() ) ) {
895
+				foreach( $order->get_items() as $item ) {
896
+					$product_type = '';
897
+					if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
898
+						$item_id = $item['variation_id'];
899
+						$product_type = 'variation';
900
+					} else {
901
+						$item_id = $item['product_id'];
902
+					} // End If Statement
903
+					$_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
904
+					// Get courses that use the WC product
905
+					$courses = $this->post_types->course->get_product_courses( $_product->id );
906
+					// Loop and update those courses
907
+					foreach ( $courses as $course_item ) {
908
+						$update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
909
+					} // End For Loop
910
+				} // End For Loop
911
+			} // End If Statement
912
+			// Add meta to indicate that payment has been completed successfully
913
+			update_post_meta( $order_id, 'sensei_payment_complete', '1' );
914
+		} // End If Statement
915
+	} // End sensei_woocommerce_complete_order()
916
+
917
+	/**
918
+	 * Runs when an order is cancelled.
919
+	 * @since   1.2.0
920
+	 * @access  public
921
+	 * @param   integer $order_id order ID
922
+	 * @return  void
923
+	 */
924
+	public function sensei_woocommerce_cancel_order ( $order_id ) {
925
+
926
+		// Get order object
927
+		$order = new WC_Order( $order_id );
928
+
929
+		// Run through each product ordered
930
+		if ( 0 < sizeof( $order->get_items() ) ) {
931
+
932
+			// Get order user
933
+			$user_id = $order->__get( 'user_id' );
934
+
935
+			foreach( $order->get_items() as $item ) {
936
+
937
+				$product_type = '';
938
+				if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
939
+					$item_id = $item['variation_id'];
940
+					$product_type = 'variation';
941
+				} else {
942
+					$item_id = $item['product_id'];
943
+				} // End If Statement
944
+				$_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
945
+
946
+				// Get courses that use the WC product
947
+				$courses = array();
948
+				$courses = $this->post_types->course->get_product_courses( $item_id );
949
+
950
+				// Loop and update those courses
951
+				foreach ($courses as $course_item){
952
+					// Check and Remove course from courses user meta
953
+					$dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id );
954
+				} // End For Loop
955
+			} // End For Loop
956
+		} // End If Statement
957
+	} // End sensei_woocommerce_cancel_order()
958
+
959
+	/**
960
+	 * Runs when an subscription is cancelled or expires.
961
+	 * @since   1.3.3
962
+	 * @access  public
963
+	 * @param   integer $user_id User ID
964
+	 * @param   integer $subscription_key Subscription Unique Key
965
+	 * @return  void
966
+	 */
967
+	public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ) {
968
+		$subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key );
969
+		self::sensei_woocommerce_cancel_order( $subscription['order_id'] );
970
+	}
971
+
972
+	/**
973
+	 * Runs when an subscription is re-activated after suspension.
974
+	 * @since   1.3.3
975
+	 * @access  public
976
+	 * @param   integer $user_id User ID
977
+	 * @param   integer $subscription_key Subscription Unique Key
978
+	 * @return  void
979
+	 */
980
+	public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ) {
981
+		$subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key );
982
+		$order = new WC_Order( $subscription['order_id'] );
983
+		$user = get_user_by( 'id', $order->get_user_id() );
984
+		$order_user = array();
985
+		$order_user['ID'] = $user->ID;
986
+		$order_user['user_login'] = $user->user_login;
987
+		$order_user['user_email'] = $user->user_email;
988
+		$order_user['user_url'] = $user->user_url;
989
+		$courses = $this->post_types->course->get_product_courses( $subscription['product_id'] );
990
+		foreach ( $courses as $course_item ){
991
+			$update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
992
+		} // End For Loop
993
+	} // End sensei_woocommerce_reactivate_subscription
994
+
995
+	/**
996
+	 * Returns the WooCommerce Product Object
997
+	 *
998
+	 * The code caters for pre and post WooCommerce 2.2 installations.
999
+	 *
1000
+	 * @since   1.1.1
1001
+	 * @access  public
1002
+	 * @param   integer $wc_product_id Product ID or Variation ID
1003
+	 * @param   string  $product_type  '' or 'variation'
1004
+	 * @return   WC_Product $wc_product_object
1005
+	 */
1006
+	public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) {
1007
+
1008
+		$wc_product_object = false;
1009
+		if ( 0 < intval( $wc_product_id ) ) {
1010
+
1011
+			// Get the product
1012
+			if ( function_exists( 'wc_get_product' ) ) {
1013
+
1014
+				$wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3
1015
+
1016
+			} elseif ( function_exists( 'get_product' ) ) {
1017
+
1018
+				$wc_product_object = get_product( $wc_product_id ); // Post WC 2.0
1019
+
1020
+			} else {
1021
+
1022
+				// Pre WC 2.0
1023
+				if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) {
1024
+
1025
+					$wc_product_object = new WC_Product_Variation( $wc_product_id );
1026
+
1027
+				} else {
1028
+
1029
+					$wc_product_object = new WC_Product( $wc_product_id );
1030
+
1031
+				} // End If Statement
1032
+
1033
+			} // End If Statement
1034
+
1035
+		} // End If Statement
1036
+
1037
+		return $wc_product_object;
1038
+
1039
+	} // End sensei_get_woocommerce_product_object()
1040
+
1041
+	/**
1042
+	 * load_class loads in class files
1043
+	 * @since   1.2.0
1044
+	 * @access  public
1045
+	 * @return  void
1046
+	 */
1047
+	public function load_class ( $class_name = '' ) {
1048
+		if ( '' != $class_name && '' != $this->token ) {
1049
+			require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' );
1050
+		} // End If Statement
1051
+	} // End load_class()
1052
+
1053
+	/**
1054
+	 * sensei_activate_subscription runs when a subscription product is purchased
1055
+	 * @since   1.2.0
1056
+	 * @access  public
1057
+	 * @param   integer $order_id order ID
1058
+	 * @return  void
1059
+	 */
1060
+	public function sensei_activate_subscription(  $order_id = 0 ) {
1061
+		if ( 0 < intval( $order_id ) ) {
1062
+			$order = new WC_Order( $order_id );
1063
+			$user = get_user_by('id', $order->user_id);
1064
+			$order_user['ID'] = $user->ID;
1065
+			$order_user['user_login'] = $user->user_login;
1066
+			$order_user['user_email'] = $user->user_email;
1067
+			$order_user['user_url'] = $user->user_url;
1068
+			// Run through each product ordered
1069
+			if (sizeof($order->get_items())>0) {
1070
+				foreach($order->get_items() as $item) {
1071
+					$product_type = '';
1072
+					if (isset($item['variation_id']) && $item['variation_id'] > 0) {
1073
+						$item_id = $item['variation_id'];
1074
+						$product_type = 'subscription_variation';
1075
+					} else {
1076
+						$item_id = $item['product_id'];
1077
+					} // End If Statement
1078
+					$_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
1079
+					// Get courses that use the WC product
1080
+					$courses = array();
1081
+					if ( $product_type == 'subscription_variation' ) {
1082
+						$courses = $this->post_types->course->get_product_courses( $item_id );
1083
+					} // End If Statement
1084
+					// Loop and update those courses
1085
+					foreach ($courses as $course_item){
1086
+						$update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
1087
+					} // End For Loop
1088
+				} // End For Loop
1089
+			} // End If Statement
1090
+		} // End If Statement
1091
+	} // End sensei_activate_subscription()
1092
+
1093
+	/**
1094
+	 * sensei_woocommerce_email_course_details adds detail to email
1095
+	 * @since   1.4.5
1096
+	 * @access  public
1097
+	 * @param   WC_Order $order
1098
+	 * @return  void
1099
+	 */
1100
+	public function sensei_woocommerce_email_course_details( $order ) {
1101
+		global $woocommerce;
1102
+
1103
+		// exit early if not wc-completed or wc-processing
1104
+		if( 'wc-completed' != $order->post_status
1105
+			&& 'wc-processing' != $order->post_status  ) {
1106
+			return;
1107
+		}
1108
+
1109
+		$order_items = $order->get_items();
1110
+		$order_id = $order->id;
1111
+
1112
+		//If object have items go through them all to find course
1113
+		if ( 0 < sizeof( $order_items ) ) {
1114
+
1115
+		echo '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>';
1116
+
1117
+		foreach ( $order_items as $item ) {
1118
+
1119
+				$product_type = '';
1120
+				if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1121
+					// If item has variation_id then its from variation
1122
+					$item_id = $item['variation_id'];
1123
+					$product_type = 'variation';
1124
+				} else {
1125
+					// If not its real product set its id to item_id
1126
+					$item_id = $item['product_id'];
1127
+				} // End If Statement
1128
+
1129
+				$user_id = get_post_meta( $order_id, '_customer_user', true );
1130
+
1131
+				if( $user_id ) {
1132
+
1133
+					// Get all courses for product
1134
+					$args = array(
1135
+						'posts_per_page' => -1,
1136
+						'post_type' => 'course',
1137
+						'meta_query' => array(
1138
+							array(
1139
+								'key' => '_course_woocommerce_product',
1140
+								'value' => $item_id
1141
+							)
1142
+						),
1143
+						'orderby' => 'menu_order date',
1144
+						'order' => 'ASC',
1145
+					);
1146
+					$courses = get_posts( $args );
1147
+
1148
+					if( $courses && count( $courses ) > 0 ) {
1149
+
1150
+						foreach( $courses as $course ) {
1151
+
1152
+							$title = $course->post_title;
1153
+							$permalink = get_permalink( $course->ID );
1154
+
1155
+							echo '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>';
1156
+						}
1157
+					}
1158
+				}
1159
+			}
1160
+		}
1161
+	}
1162
+
1163
+	/**
1164
+	 * Filtering wp_count_comments to ensure that Sensei comments are ignored
1165
+	 * @since   1.4.0
1166
+	 * @access  public
1167
+	 * @param  array   $comments
1168
+	 * @param  integer $post_id
1169
+	 * @return array
1170
+	 */
1171
+	public function sensei_count_comments( $comments, $post_id ) {
1172
+		global $wpdb;
1173
+
1174
+		$post_id = (int) $post_id;
1175
+
1176
+		$count = wp_cache_get("comments-{$post_id}", 'counts');
1177
+
1178
+		if ( false !== $count ) {
1179
+			return $count;
1180
+		}
1181
+
1182
+		$statuses = array( '' ); // Default to the WP normal comments
1183
+		$stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A );
1184
+		foreach ( (array) $stati AS $status ) {
1185
+			if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) {
1186
+				$statuses[] = $status['comment_type'];
1187
+			}
1188
+		}
1189
+		$where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')";
1190
+
1191
+		if ( $post_id > 0 )
1192
+			$where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id );
1193
+
1194
+		$count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );
1195
+
1196
+		$total = 0;
1197
+		$approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed');
1198
+		foreach ( (array) $count as $row ) {
1199
+			// Don't count post-trashed toward totals
1200
+			if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] )
1201
+				$total += $row['num_comments'];
1202
+			if ( isset( $approved[$row['comment_approved']] ) )
1203
+				$stats[$approved[$row['comment_approved']]] = $row['num_comments'];
1204
+		}
1205
+
1206
+		$stats['total_comments'] = $total;
1207
+		foreach ( $approved as $key ) {
1208
+			if ( empty($stats[$key]) )
1209
+				$stats[$key] = 0;
1210
+		}
1211
+
1212
+		$stats = (object) $stats;
1213
+		wp_cache_set("comments-{$post_id}", $stats, 'counts');
1214
+
1215
+		return $stats;
1216
+	}
1217
+
1218
+	/**
1219
+	 * Init images.
1220
+	 *
1221
+	 * @since 1.4.5
1222
+	 * @access public
1223
+	 * @return void
1224
+	 */
1225
+	public function init_image_sizes() {
1226
+		$course_archive_thumbnail 	= $this->get_image_size( 'course_archive_image' );
1227
+		$course_single_thumbnail	= $this->get_image_size( 'course_single_image' );
1228
+		$lesson_archive_thumbnail 	= $this->get_image_size( 'lesson_archive_image' );
1229
+		$lesson_single_thumbnail	= $this->get_image_size( 'lesson_single_image' );
1230
+
1231
+		add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] );
1232
+		add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] );
1233
+		add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] );
1234
+		add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] );
1235
+	}
1236
+
1237
+	/**
1238
+	 * Get an image size.
1239
+	 *
1240
+	 * Variable is filtered by sensei_get_image_size_{image_size}
1241
+	 *
1242
+	 * @since 1.4.5
1243
+	 * @access public
1244
+	 * @param mixed $image_size
1245
+	 * @return string
1246
+	 */
1247
+	public function get_image_size( $image_size ) {
1248
+
1249
+		// Only return sizes we define in settings
1250
+		if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) )
1251
+			return apply_filters( 'sensei_get_image_size_' . $image_size, '' );
1252
+
1253
+		if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) {
1254
+			$this->settings->settings[ $image_size . '_width' ] = false;
1255
+		}
1256
+		if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) {
1257
+			$this->settings->settings[ $image_size . '_height' ] = false;
1258
+		}
1259
+		if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) {
1260
+			$this->settings->settings[ $image_size . '_hard_crop' ] = false;
1261
+		}
1262
+
1263
+		$size = array_filter( array(
1264
+			'width' => $this->settings->settings[ $image_size . '_width' ],
1265
+			'height' => $this->settings->settings[ $image_size . '_height' ],
1266
+			'crop' => $this->settings->settings[ $image_size . '_hard_crop' ]
1267
+		) );
1268
+
1269
+		$size['width'] 	= isset( $size['width'] ) ? $size['width'] : '100';
1270
+		$size['height'] = isset( $size['height'] ) ? $size['height'] : '100';
1271
+		$size['crop'] 	= isset( $size['crop'] ) ? $size['crop'] : 0;
1272
+
1273
+		return apply_filters( 'sensei_get_image_size_' . $image_size, $size );
1274
+	}
1275
+
1276
+	public function body_class( $classes ) {
1277
+		if( is_sensei() ) {
1278
+			$classes[] = 'sensei';
1279
+		}
1280
+		return $classes;
1281
+	}
1282
+
1283
+	/**
1284
+	 * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers
1285
+	 *
1286
+	 * @return null
1287
+	 * @since 1.7.0
1288
+	 */
1289
+	public function jetpack_latex_support() {
1290
+		if ( function_exists( 'latex_markup') ) {
1291
+			add_filter( 'sensei_question_title', 'latex_markup' );
1292
+			add_filter( 'sensei_answer_text', 'latex_markup' );
1293
+		}
1294
+	}
1295
+
1296
+	/**
1297
+	 * Load the module functionality.
1298
+	 *
1299
+	 * This function is hooked into plugins_loaded to avoid conflicts with
1300
+	 * the retired modules extension.
1301
+	 *
1302
+	 * @since 1.8.0
1303
+	 */
1304
+	public function load_modules_class(){
1305
+		global $sensei_modules;
1306
+
1307
+		if( !class_exists( 'Sensei_Modules' )
1308
+			&&  'Sensei_Modules' != get_class( $sensei_modules ) ) {
1309
+
1310
+			//Load the modules class
1311
+			require_once( 'class-sensei-modules.php');
1312
+			Sensei()->modules = new Sensei_Core_Modules( $this->file );
1313
+
1314
+		}else{
1315
+			// fallback for people still using the modules extension.
1316
+			global $sensei_modules;
1317
+			Sensei()->modules = $sensei_modules;
1318
+			add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 );
1319
+		}
1320
+	}
1321
+
1322
+	/**
1323
+	 * Tell the user to that the modules extension is no longer needed.
1324
+	 *
1325
+	 * @since 1.8.0
1326
+	 */
1327
+	public function disable_sensei_modules_extension(){ ?>
1328 1328
         <div class="notice updated fade">
1329 1329
             <p>
1330 1330
                 <?php
1331
-                $plugin_manage_url = admin_url().'plugins.php#sensei-modules';
1332
-                $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> ';
1333
-                ?>
1331
+				$plugin_manage_url = admin_url().'plugins.php#sensei-modules';
1332
+				$plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> ';
1333
+				?>
1334 1334
                 <strong> Modules are now included in Sensei,</strong> so you no longer need the Sensei Modules extension.
1335 1335
                 Please deactivate and delete it from your <?php echo $plugin_link_element; ?>. (This will not affect your existing modules).
1336 1336
             </p>
@@ -1338,46 +1338,46 @@  discard block
 block discarded – undo
1338 1338
 
1339 1339
     <?php }// end function
1340 1340
 
1341
-    /**
1342
-     * Sensei wide rewrite flush call.
1343
-     *
1344
-     * To use this simply update the option 'sensei_flush_rewrite_rules' to 1
1345
-     *
1346
-     * After the option is one the Rules will be flushed.
1347
-     *
1348
-     * @since 1.9.0
1349
-     */
1350
-    public function flush_rewrite_rules(){
1341
+	/**
1342
+	 * Sensei wide rewrite flush call.
1343
+	 *
1344
+	 * To use this simply update the option 'sensei_flush_rewrite_rules' to 1
1345
+	 *
1346
+	 * After the option is one the Rules will be flushed.
1347
+	 *
1348
+	 * @since 1.9.0
1349
+	 */
1350
+	public function flush_rewrite_rules(){
1351 1351
 
1352
-        // ensures that the rewrite rules are flushed on the second
1353
-        // attempt. This ensure that the settings for any other process
1354
-        // have been completed and saved to the database before we refresh the
1355
-        // rewrite rules.
1356
-        $option =  get_option('sensei_flush_rewrite_rules');
1357
-        if( '1' == $option ) {
1352
+		// ensures that the rewrite rules are flushed on the second
1353
+		// attempt. This ensure that the settings for any other process
1354
+		// have been completed and saved to the database before we refresh the
1355
+		// rewrite rules.
1356
+		$option =  get_option('sensei_flush_rewrite_rules');
1357
+		if( '1' == $option ) {
1358 1358
 
1359
-            update_option('sensei_flush_rewrite_rules', '2');
1359
+			update_option('sensei_flush_rewrite_rules', '2');
1360 1360
 
1361
-        }elseif( '2' == $option ) {
1361
+		}elseif( '2' == $option ) {
1362 1362
 
1363
-            flush_rewrite_rules();
1364
-            update_option('sensei_flush_rewrite_rules', '0');
1363
+			flush_rewrite_rules();
1364
+			update_option('sensei_flush_rewrite_rules', '0');
1365 1365
 
1366
-        }
1366
+		}
1367 1367
 
1368
-    } // end flush_rewrite_rules
1368
+	} // end flush_rewrite_rules
1369 1369
 
1370
-    /**
1371
-     * Calling this function will tell Sensei to flush rewrite
1372
-     * rules on the next load.
1373
-     *
1374
-     * @since 1.9.0
1375
-     */
1376
-    public function initiate_rewrite_rules_flush(){
1370
+	/**
1371
+	 * Calling this function will tell Sensei to flush rewrite
1372
+	 * rules on the next load.
1373
+	 *
1374
+	 * @since 1.9.0
1375
+	 */
1376
+	public function initiate_rewrite_rules_flush(){
1377 1377
 
1378
-        update_option('sensei_flush_rewrite_rules', '1');
1378
+		update_option('sensei_flush_rewrite_rules', '1');
1379 1379
 
1380
-    }
1380
+	}
1381 1381
 
1382 1382
 } // End Class
1383 1383
 
Please login to merge, or discard this patch.
includes/class-sensei-analysis-overview-list-table.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -162,10 +162,10 @@  discard block
 block discarded – undo
162 162
 			'order' => $order,
163 163
 		);
164 164
 
165
-        // Handle search
166
-        if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
167
-            $args['search'] = esc_html( $_GET['s'] );
168
-        }
165
+		// Handle search
166
+		if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
167
+			$args['search'] = esc_html( $_GET['s'] );
168
+		}
169 169
 
170 170
 		switch ( $this->type ) {
171 171
 			case 'courses':
@@ -222,10 +222,10 @@  discard block
 block discarded – undo
222 222
 		);
223 223
 
224 224
 
225
-        // Handle search
226
-        if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
227
-            $args['search'] = esc_html( $_GET['s'] );
228
-        }
225
+		// Handle search
226
+		if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
227
+			$args['search'] = esc_html( $_GET['s'] );
228
+		}
229 229
 
230 230
 
231 231
 		// Start the csv with the column headings
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 	 * Generates the overall array for a single item in the display
264 264
 	 * @since  1.7.0
265 265
 	 * @param object $item The current item
266
-     * @return array $column_data;
266
+	 * @return array $column_data;
267 267
 	 */
268 268
 	protected function get_row_data( $item ) {
269 269
 
@@ -422,8 +422,8 @@  discard block
 block discarded – undo
422 422
 
423 423
 				// Output the users data
424 424
 				if ( $this->csv_output ) {
425
-                    $user_name = Sensei_Student::get_full_name( $item->ID );
426
-                }
425
+					$user_name = Sensei_Student::get_full_name( $item->ID );
426
+				}
427 427
 				else {
428 428
 					$url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->ID ), admin_url( 'admin.php' ) );
429 429
 					$user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $item->display_name . '</a></strong>';
@@ -517,17 +517,17 @@  discard block
 block discarded – undo
517 517
 		// This stops the full meta data of each user being loaded
518 518
 		$args['fields'] = array( 'ID', 'user_login', 'user_email', 'user_registered', 'display_name' );
519 519
 
520
-        /**
521
-         * Filter the WP_User_Query arguments
522
-         * @since 1.6.0
523
-         * @param $args
524
-         */
525
-        $args = apply_filters( 'sensei_analysis_overview_filter_users', $args );
520
+		/**
521
+		 * Filter the WP_User_Query arguments
522
+		 * @since 1.6.0
523
+		 * @param $args
524
+		 */
525
+		$args = apply_filters( 'sensei_analysis_overview_filter_users', $args );
526 526
 		$wp_user_search = new WP_User_Query( $args );
527
-        $learners = $wp_user_search->get_results();
527
+		$learners = $wp_user_search->get_results();
528 528
 		$this->total_items = $wp_user_search->get_total();
529 529
 
530
-        return $learners;
530
+		return $learners;
531 531
 
532 532
 	} // End get_learners()
533 533
 
Please login to merge, or discard this patch.
includes/class-sensei-teacher.php 1 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' , 'woothemes-sensei'),  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' , 'woothemes-sensei'),  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 =  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 =  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.
includes/class-sensei-grading-main.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 			$grade = __( 'N/A', 'woothemes-sensei' );
254 254
 		}
255 255
 
256
-        $title = Sensei_Student::get_full_name( $item->user_id );
256
+		$title = Sensei_Student::get_full_name( $item->user_id );
257 257
 
258 258
 		// QuizID to be deprecated
259 259
 		$quiz_id = get_post_meta( $item->comment_post_ID, '_lesson_quiz', true );
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 	 */
304 304
 	public function no_items() {
305 305
 
306
-        _e( 'No submissions found.', 'woothemes-sensei' );
306
+		_e( 'No submissions found.', 'woothemes-sensei' );
307 307
 
308 308
 	} // End no_items()
309 309
 
Please login to merge, or discard this patch.
includes/class-sensei-autoloader.php 1 patch
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -13,124 +13,124 @@
 block discarded – undo
13 13
  */
14 14
 class Sensei_Autoloader {
15 15
 
16
-    /**
17
-     * @var path to the includes directory within Sensei.
18
-     */
19
-    private $include_path = 'includes';
20
-
21
-    /**
22
-     * @var array $class_file_map. List of classes mapped to their files
23
-     */
24
-    private $class_file_map = array();
25
-
26
-    /**
27
-     * Constructor
28
-     * @since 1.9.0
29
-     */
30
-    public function __construct(){
31
-
32
-        // make sure we do not override an existing autoload function
33
-        if( function_exists('__autoload') ){
34
-           spl_autoload_register( '__autoload' );
35
-        }
36
-
37
-        // setup a relative path for the current autoload instance
38
-        $this->include_path = trailingslashit( untrailingslashit( dirname( __FILE__ ) ) );
39
-
40
-        //setup the class file map
41
-        $this->initialize_class_file_map();
42
-
43
-        // add Sensei custom auto loader
44
-        spl_autoload_register( array( $this, 'autoload' )  );
45
-
46
-    }
47
-
48
-    /**
49
-     * Generate a list of Sensei class and map them the their respective
50
-     * files within the includes directory
51
-     *
52
-     * @since 1.9.0
53
-     */
54
-    public function initialize_class_file_map(){
55
-
56
-        $this->class_file_map = array(
57
-
58
-            /**
59
-             * Main Sensei class
60
-             */
61
-            'Sensei_Main' => 'class-sensei.php',
62
-
63
-            /**
64
-             * Admin
65
-             */
66
-            'Sensei_Welcome'            => 'admin/class-sensei-welcome.php' ,
67
-            'Sensei_Learner_Management' => 'admin/class-sensei-learner-management.php' ,
68
-
69
-            /**
70
-             * Shortcodes
71
-             */
72
-            'Sensei_Shortcode_Loader'              => 'shortcodes/class-sensei-shortcode-loader.php',
73
-            'Sensei_Shortcode_Interface'           => 'shortcodes/interface-sensei-shortcode.php',
74
-            'Sensei_Shortcode_Featured_Courses'    => 'shortcodes/class-sensei-shortcode-featured-courses.php',
75
-            'Sensei_Shortcode_User_Courses'        => 'shortcodes/class-sensei-shortcode-user-courses.php',
76
-            'Sensei_Shortcode_Courses'             => 'shortcodes/class-sensei-shortcode-courses.php',
77
-            'Sensei_Shortcode_Teachers'            => 'shortcodes/class-sensei-shortcode-teachers.php',
78
-            'Sensei_Shortcode_User_Messages'       => 'shortcodes/class-sensei-shortcode-user-messages.php',
79
-            'Sensei_Shortcode_Course_Page'         => 'shortcodes/class-sensei-shortcode-course-page.php',
80
-            'Sensei_Shortcode_Lesson_Page'         => 'shortcodes/class-sensei-shortcode-lesson-page.php',
81
-            'Sensei_Shortcode_Course_Categories'   => 'shortcodes/class-sensei-shortcode-course-categories.php',
82
-            'Sensei_Shortcode_Unpurchased_Courses' => 'shortcodes/class-sensei-shortcode-unpurchased-courses.php',
83
-            'Sensei_Legacy_Shortcodes'             => 'shortcodes/class-sensei-legacy-shortcodes.php',
84
-
85
-            /**
86
-             * WooCommerce
87
-             */
88
-            'Sensei_WC' => 'class-sensei-wc.php',
89
-
90
-        );
91
-    }
92
-
93
-    /**
94
-     * Autoload all sensei files as the class names are used.
95
-     */
96
-    public function autoload( $class ){
97
-
98
-        // only handle classes with the word `sensei` in it
99
-        if( ! is_numeric( strpos ( strtolower( $class ), 'sensei') ) ){
100
-
101
-            return;
102
-
103
-        }
104
-
105
-        // exit if we didn't provide mapping for this class
106
-        if( isset( $this->class_file_map[ $class ] ) ){
107
-
108
-            $file_location = $this->include_path . $this->class_file_map[ $class ];
109
-            require_once( $file_location);
110
-            return;
111
-
112
-        }
113
-
114
-        // check for file in the main includes directory
115
-        $class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $class ) ) . '.php';
116
-        if( file_exists( $class_file_path ) ){
117
-
118
-            require_once( $class_file_path );
119
-            return;
120
-        }
121
-
122
-        // lastly check legacy types
123
-        $stripped_woothemes_from_class = str_replace( 'woothemes_','', strtolower( $class ) ); // remove woothemes
124
-        $legacy_class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $stripped_woothemes_from_class ) ) . '.php';
125
-        if( file_exists( $legacy_class_file_path ) ){
126
-
127
-            require_once( $legacy_class_file_path );
128
-            return;
129
-        }
130
-
131
-        return;
132
-
133
-    }// end autoload
16
+	/**
17
+	 * @var path to the includes directory within Sensei.
18
+	 */
19
+	private $include_path = 'includes';
20
+
21
+	/**
22
+	 * @var array $class_file_map. List of classes mapped to their files
23
+	 */
24
+	private $class_file_map = array();
25
+
26
+	/**
27
+	 * Constructor
28
+	 * @since 1.9.0
29
+	 */
30
+	public function __construct(){
31
+
32
+		// make sure we do not override an existing autoload function
33
+		if( function_exists('__autoload') ){
34
+		   spl_autoload_register( '__autoload' );
35
+		}
36
+
37
+		// setup a relative path for the current autoload instance
38
+		$this->include_path = trailingslashit( untrailingslashit( dirname( __FILE__ ) ) );
39
+
40
+		//setup the class file map
41
+		$this->initialize_class_file_map();
42
+
43
+		// add Sensei custom auto loader
44
+		spl_autoload_register( array( $this, 'autoload' )  );
45
+
46
+	}
47
+
48
+	/**
49
+	 * Generate a list of Sensei class and map them the their respective
50
+	 * files within the includes directory
51
+	 *
52
+	 * @since 1.9.0
53
+	 */
54
+	public function initialize_class_file_map(){
55
+
56
+		$this->class_file_map = array(
57
+
58
+			/**
59
+			 * Main Sensei class
60
+			 */
61
+			'Sensei_Main' => 'class-sensei.php',
62
+
63
+			/**
64
+			 * Admin
65
+			 */
66
+			'Sensei_Welcome'            => 'admin/class-sensei-welcome.php' ,
67
+			'Sensei_Learner_Management' => 'admin/class-sensei-learner-management.php' ,
68
+
69
+			/**
70
+			 * Shortcodes
71
+			 */
72
+			'Sensei_Shortcode_Loader'              => 'shortcodes/class-sensei-shortcode-loader.php',
73
+			'Sensei_Shortcode_Interface'           => 'shortcodes/interface-sensei-shortcode.php',
74
+			'Sensei_Shortcode_Featured_Courses'    => 'shortcodes/class-sensei-shortcode-featured-courses.php',
75
+			'Sensei_Shortcode_User_Courses'        => 'shortcodes/class-sensei-shortcode-user-courses.php',
76
+			'Sensei_Shortcode_Courses'             => 'shortcodes/class-sensei-shortcode-courses.php',
77
+			'Sensei_Shortcode_Teachers'            => 'shortcodes/class-sensei-shortcode-teachers.php',
78
+			'Sensei_Shortcode_User_Messages'       => 'shortcodes/class-sensei-shortcode-user-messages.php',
79
+			'Sensei_Shortcode_Course_Page'         => 'shortcodes/class-sensei-shortcode-course-page.php',
80
+			'Sensei_Shortcode_Lesson_Page'         => 'shortcodes/class-sensei-shortcode-lesson-page.php',
81
+			'Sensei_Shortcode_Course_Categories'   => 'shortcodes/class-sensei-shortcode-course-categories.php',
82
+			'Sensei_Shortcode_Unpurchased_Courses' => 'shortcodes/class-sensei-shortcode-unpurchased-courses.php',
83
+			'Sensei_Legacy_Shortcodes'             => 'shortcodes/class-sensei-legacy-shortcodes.php',
84
+
85
+			/**
86
+			 * WooCommerce
87
+			 */
88
+			'Sensei_WC' => 'class-sensei-wc.php',
89
+
90
+		);
91
+	}
92
+
93
+	/**
94
+	 * Autoload all sensei files as the class names are used.
95
+	 */
96
+	public function autoload( $class ){
97
+
98
+		// only handle classes with the word `sensei` in it
99
+		if( ! is_numeric( strpos ( strtolower( $class ), 'sensei') ) ){
100
+
101
+			return;
102
+
103
+		}
104
+
105
+		// exit if we didn't provide mapping for this class
106
+		if( isset( $this->class_file_map[ $class ] ) ){
107
+
108
+			$file_location = $this->include_path . $this->class_file_map[ $class ];
109
+			require_once( $file_location);
110
+			return;
111
+
112
+		}
113
+
114
+		// check for file in the main includes directory
115
+		$class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $class ) ) . '.php';
116
+		if( file_exists( $class_file_path ) ){
117
+
118
+			require_once( $class_file_path );
119
+			return;
120
+		}
121
+
122
+		// lastly check legacy types
123
+		$stripped_woothemes_from_class = str_replace( 'woothemes_','', strtolower( $class ) ); // remove woothemes
124
+		$legacy_class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $stripped_woothemes_from_class ) ) . '.php';
125
+		if( file_exists( $legacy_class_file_path ) ){
126
+
127
+			require_once( $legacy_class_file_path );
128
+			return;
129
+		}
130
+
131
+		return;
132
+
133
+	}// end autoload
134 134
 
135 135
 }
136 136
 new Sensei_Autoloader();
Please login to merge, or discard this patch.
includes/class-sensei-posttypes.php 1 patch
Indentation   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -17,25 +17,25 @@  discard block
 block discarded – undo
17 17
 	public $slider_labels;
18 18
 	public $role_caps;
19 19
 
20
-    /**
21
-     * @var Sensei_Course
22
-     */
23
-    public $course;
24
-
25
-    /**
26
-     * @var Sensei_Lesson
27
-     */
28
-    public $lesson;
29
-
30
-    /**
31
-     * @var Sensei_Question
32
-     */
33
-    public $question;
34
-
35
-    /**
36
-     * @var Sensei_Quiz
37
-     */
38
-    public $quiz;
20
+	/**
21
+	 * @var Sensei_Course
22
+	 */
23
+	public $course;
24
+
25
+	/**
26
+	 * @var Sensei_Lesson
27
+	 */
28
+	public $lesson;
29
+
30
+	/**
31
+	 * @var Sensei_Question
32
+	 */
33
+	public $question;
34
+
35
+	/**
36
+	 * @var Sensei_Quiz
37
+	 */
38
+	public $quiz;
39 39
 
40 40
 	/**
41 41
 	 * Constructor
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 
46 46
 		// Setup Post Types
47 47
 		$this->labels = array();
48
-        $this->token = 'woothemes-sensei-posttypes';
48
+		$this->token = 'woothemes-sensei-posttypes';
49 49
 
50 50
 		$this->setup_post_type_labels_base();
51 51
 		add_action( 'init', array( $this, 'setup_course_post_type' ), 100 );
@@ -104,94 +104,94 @@  discard block
 block discarded – undo
104 104
 	/**
105 105
 	 * Setup the "course" post type, it's admin menu item and the appropriate labels and permissions.
106 106
 	 * @since  1.0.0
107
-     * @uses  Sensei()
107
+	 * @uses  Sensei()
108 108
 	 * @return void
109 109
 	 */
110 110
 	public function setup_course_post_type () {
111 111
 
112 112
 		$args = array(
113
-		    'labels'              => $this->create_post_type_labels( $this->labels['course']['singular'], $this->labels['course']['plural'], $this->labels['course']['menu'] ),
114
-		    'public'              => true,
115
-		    'publicly_queryable'  => true,
116
-		    'show_ui'             => true,
117
-		    'show_in_menu'        => true,
118
-		    'show_in_admin_bar'   => true,
119
-		    'query_var'           => true,
120
-		    'rewrite'             => array(
121
-                'slug' => esc_attr( apply_filters( 'sensei_course_slug', _x( 'course', 'post type single url base', 'woothemes-sensei' ) ) ) ,
122
-                'with_front' => true,
123
-                'feeds' => true,
124
-                'pages' => true
125
-            ),
126
-		    'map_meta_cap'        => true,
127
-		    'capability_type'     => 'course',
128
-            'has_archive'         => $this->get_course_post_type_archive_slug(),
129
-		    'hierarchical'        => false,
130
-		    'menu_position'       => 51,
131
-		    'supports'            => array( 'title', 'editor', 'excerpt', 'thumbnail' )
113
+			'labels'              => $this->create_post_type_labels( $this->labels['course']['singular'], $this->labels['course']['plural'], $this->labels['course']['menu'] ),
114
+			'public'              => true,
115
+			'publicly_queryable'  => true,
116
+			'show_ui'             => true,
117
+			'show_in_menu'        => true,
118
+			'show_in_admin_bar'   => true,
119
+			'query_var'           => true,
120
+			'rewrite'             => array(
121
+				'slug' => esc_attr( apply_filters( 'sensei_course_slug', _x( 'course', 'post type single url base', 'woothemes-sensei' ) ) ) ,
122
+				'with_front' => true,
123
+				'feeds' => true,
124
+				'pages' => true
125
+			),
126
+			'map_meta_cap'        => true,
127
+			'capability_type'     => 'course',
128
+			'has_archive'         => $this->get_course_post_type_archive_slug(),
129
+			'hierarchical'        => false,
130
+			'menu_position'       => 51,
131
+			'supports'            => array( 'title', 'editor', 'excerpt', 'thumbnail' )
132 132
 		);
133 133
 
134
-        /**
135
-         * Filter the arguments passed in when registering the Sensei Course post type.
136
-         *
137
-         * @since 1.9.0
138
-         * @param array $args
139
-         */
134
+		/**
135
+		 * Filter the arguments passed in when registering the Sensei Course post type.
136
+		 *
137
+		 * @since 1.9.0
138
+		 * @param array $args
139
+		 */
140 140
 		register_post_type( 'course', apply_filters( 'sensei_register_post_type_course', $args ) );
141 141
 
142 142
 	} // End setup_course_post_type()
143 143
 
144
-    /**
145
-     * Figure out of the course post type has an archive and what it should be.
146
-     *
147
-     * This function should return 'courses' or the page_uri for the course page setting.
148
-     *
149
-     * For backward compatibility  sake ( pre 1.9 )If the course page set in settings
150
-     * still has any of the old shortcodes: [newcourses][featuredcourses][freecourses][paidcourses] the
151
-     * page slug will not be returned. For any other pages without it the page URI will be returned.
152
-     *
153
-     *
154
-     * @sine 1.9.0
155
-     *
156
-     *
157
-     * @return false|string
158
-     */
159
-    public function get_course_post_type_archive_slug(){
144
+	/**
145
+	 * Figure out of the course post type has an archive and what it should be.
146
+	 *
147
+	 * This function should return 'courses' or the page_uri for the course page setting.
148
+	 *
149
+	 * For backward compatibility  sake ( pre 1.9 )If the course page set in settings
150
+	 * still has any of the old shortcodes: [newcourses][featuredcourses][freecourses][paidcourses] the
151
+	 * page slug will not be returned. For any other pages without it the page URI will be returned.
152
+	 *
153
+	 *
154
+	 * @sine 1.9.0
155
+	 *
156
+	 *
157
+	 * @return false|string
158
+	 */
159
+	public function get_course_post_type_archive_slug(){
160 160
 
161
-        $settings_course_page = get_post( Sensei()->settings->get( 'course_page' ) );
161
+		$settings_course_page = get_post( Sensei()->settings->get( 'course_page' ) );
162 162
 
163
-        // for a valid post that doesn't have any of the old short codes set the archive the same
164
-        // as the page URI
165
-        if( is_a( $settings_course_page, 'WP_Post') && ! $this->has_old_shortcodes( $settings_course_page->post_content ) ){
163
+		// for a valid post that doesn't have any of the old short codes set the archive the same
164
+		// as the page URI
165
+		if( is_a( $settings_course_page, 'WP_Post') && ! $this->has_old_shortcodes( $settings_course_page->post_content ) ){
166 166
 
167
-             return get_page_uri( $settings_course_page->ID );
167
+			 return get_page_uri( $settings_course_page->ID );
168 168
 
169
-        }else{
169
+		}else{
170 170
 
171
-            return 'courses';
171
+			return 'courses';
172 172
 
173
-        }
173
+		}
174 174
 
175
-    }// end course_post_type_determine_archive
175
+	}// end course_post_type_determine_archive
176 176
 
177
-    /**
178
-     * Check if given content has any of these old shortcodes:
179
-     * [newcourses][featuredcourses][freecourses][paidcourses]
180
-     *
181
-     * @since 1.9.0
182
-     *
183
-     * @param string $content
184
-     *
185
-     * @return bool
186
-     */
187
-    public function has_old_shortcodes( $content ){
177
+	/**
178
+	 * Check if given content has any of these old shortcodes:
179
+	 * [newcourses][featuredcourses][freecourses][paidcourses]
180
+	 *
181
+	 * @since 1.9.0
182
+	 *
183
+	 * @param string $content
184
+	 *
185
+	 * @return bool
186
+	 */
187
+	public function has_old_shortcodes( $content ){
188 188
 
189
-        return  ( has_shortcode( $content, 'newcourses')
190
-        || has_shortcode( $content, 'featuredcourses')
191
-        || has_shortcode( $content, 'freecourses')
192
-        || has_shortcode( $content, 'paidcourses') );
189
+		return  ( has_shortcode( $content, 'newcourses')
190
+		|| has_shortcode( $content, 'featuredcourses')
191
+		|| has_shortcode( $content, 'freecourses')
192
+		|| has_shortcode( $content, 'paidcourses') );
193 193
 
194
-    }// end has old shortcodes
194
+	}// end has old shortcodes
195 195
 
196 196
 
197 197
 	/**
@@ -213,32 +213,32 @@  discard block
 block discarded – undo
213 213
 		} // End If Statement
214 214
 
215 215
 		$args = array(
216
-		    'labels' => $this->create_post_type_labels(  $this->labels['lesson']['singular'], $this->labels['lesson']['plural'], $this->labels['lesson']['menu'] ),
217
-		    'public' => true,
218
-		    'publicly_queryable' => true,
219
-		    'show_ui' => true,
220
-		    'show_in_menu' => true,
221
-		    'query_var' => true,
222
-		    'rewrite' => array(
223
-                'slug' => esc_attr( apply_filters( 'sensei_lesson_slug', _x( 'lesson', 'post type single slug', 'woothemes-sensei' ) ) ) ,
224
-                'with_front' =>  true,
225
-                'feeds' => true,
226
-                'pages' => true
227
-            ),
228
-		    'map_meta_cap' => true,
229
-		    'capability_type' => 'lesson',
230
-		    'has_archive' => true,
231
-		    'hierarchical' => false,
232
-		    'menu_position' => 52,
233
-		    'supports' => $supports_array
216
+			'labels' => $this->create_post_type_labels(  $this->labels['lesson']['singular'], $this->labels['lesson']['plural'], $this->labels['lesson']['menu'] ),
217
+			'public' => true,
218
+			'publicly_queryable' => true,
219
+			'show_ui' => true,
220
+			'show_in_menu' => true,
221
+			'query_var' => true,
222
+			'rewrite' => array(
223
+				'slug' => esc_attr( apply_filters( 'sensei_lesson_slug', _x( 'lesson', 'post type single slug', 'woothemes-sensei' ) ) ) ,
224
+				'with_front' =>  true,
225
+				'feeds' => true,
226
+				'pages' => true
227
+			),
228
+			'map_meta_cap' => true,
229
+			'capability_type' => 'lesson',
230
+			'has_archive' => true,
231
+			'hierarchical' => false,
232
+			'menu_position' => 52,
233
+			'supports' => $supports_array
234 234
 		);
235 235
 
236
-        /**
237
-         * Filter the arguments passed in when registering the Sensei Lesson post type.
238
-         *
239
-         * @since 1.9.0
240
-         * @param array $args
241
-         */
236
+		/**
237
+		 * Filter the arguments passed in when registering the Sensei Lesson post type.
238
+		 *
239
+		 * @since 1.9.0
240
+		 * @param array $args
241
+		 */
242 242
 		register_post_type( 'lesson', apply_filters( 'sensei_register_post_type_lesson', $args ) );
243 243
 
244 244
 	} // End setup_lesson_post_type()
@@ -246,45 +246,45 @@  discard block
 block discarded – undo
246 246
 	/**
247 247
 	 * Setup the "quiz" post type, it's admin menu item and the appropriate labels and permissions.
248 248
 	 * @since  1.0.0
249
-     * @uses  Sensei()
249
+	 * @uses  Sensei()
250 250
 	 * @return void
251 251
 	 */
252 252
 	public function setup_quiz_post_type () {
253 253
 
254 254
 
255 255
 		$args = array(
256
-		    'labels' => $this->create_post_type_labels(
257
-                $this->labels['quiz']['singular'],
258
-                $this->labels['quiz']['plural'],
259
-                $this->labels['quiz']['menu']
260
-            ),
261
-		    'public' => true,
262
-		    'publicly_queryable' => true,
263
-		    'show_ui' => true,
264
-		    'show_in_menu' => false,
265
-		    'show_in_nav_menus' => false,
266
-		    'query_var' => true,
267
-		    'exclude_from_search' => true,
268
-		    'rewrite' => array(
269
-                'slug' => esc_attr( apply_filters( 'sensei_quiz_slug', _x( 'quiz', 'post type single slug', 'woothemes-sensei' ) ) ) ,
270
-                'with_front' =>  true,
271
-                'feeds' => true,
272
-                'pages' => true
273
-            ),
274
-		    'map_meta_cap' => true,
275
-		    'capability_type' => 'quiz',
276
-		    'has_archive' => false,
277
-		    'hierarchical' => false,
278
-		    'menu_position' => 20, // Below "Pages"
279
-		    'supports' => array( '' )
256
+			'labels' => $this->create_post_type_labels(
257
+				$this->labels['quiz']['singular'],
258
+				$this->labels['quiz']['plural'],
259
+				$this->labels['quiz']['menu']
260
+			),
261
+			'public' => true,
262
+			'publicly_queryable' => true,
263
+			'show_ui' => true,
264
+			'show_in_menu' => false,
265
+			'show_in_nav_menus' => false,
266
+			'query_var' => true,
267
+			'exclude_from_search' => true,
268
+			'rewrite' => array(
269
+				'slug' => esc_attr( apply_filters( 'sensei_quiz_slug', _x( 'quiz', 'post type single slug', 'woothemes-sensei' ) ) ) ,
270
+				'with_front' =>  true,
271
+				'feeds' => true,
272
+				'pages' => true
273
+			),
274
+			'map_meta_cap' => true,
275
+			'capability_type' => 'quiz',
276
+			'has_archive' => false,
277
+			'hierarchical' => false,
278
+			'menu_position' => 20, // Below "Pages"
279
+			'supports' => array( '' )
280 280
 		);
281 281
 
282
-        /**
283
-         * Filter the arguments passed in when registering the Sensei Quiz post type.
284
-         *
285
-         * @since 1.9.0
286
-         * @param array $args
287
-         */
282
+		/**
283
+		 * Filter the arguments passed in when registering the Sensei Quiz post type.
284
+		 *
285
+		 * @since 1.9.0
286
+		 * @param array $args
287
+		 */
288 288
 		register_post_type( 'quiz', apply_filters( 'sensei_register_post_type_quiz', $args ) );
289 289
 
290 290
 	} // End setup_quiz_post_type()
@@ -298,34 +298,34 @@  discard block
 block discarded – undo
298 298
 	public function setup_question_post_type () {
299 299
 
300 300
 		$args = array(
301
-		    'labels' => $this->create_post_type_labels( $this->labels['question']['singular'], $this->labels['question']['plural'], $this->labels['question']['menu'] ),
302
-		    'public' => false,
303
-		    'publicly_queryable' => true,
304
-		    'show_ui' => true,
305
-		    'show_in_menu' => true,
306
-		    'show_in_nav_menus' => false,
307
-		    'query_var' => true,
308
-		    'exclude_from_search' => true,
309
-		    'rewrite' => array(
310
-                'slug' => esc_attr( apply_filters( 'sensei_question_slug', _x( 'question', 'post type single slug', 'woothemes-sensei' ) ) ) ,
311
-                'with_front' =>  true,
312
-                'feeds' => true,
313
-                'pages' => true
314
-            ),
315
-		    'map_meta_cap' => true,
316
-		    'capability_type' => 'question',
317
-		    'has_archive' => true,
318
-		    'hierarchical' => false,
319
-		    'menu_position' => 51,
320
-		    'supports' => array( 'title' )
301
+			'labels' => $this->create_post_type_labels( $this->labels['question']['singular'], $this->labels['question']['plural'], $this->labels['question']['menu'] ),
302
+			'public' => false,
303
+			'publicly_queryable' => true,
304
+			'show_ui' => true,
305
+			'show_in_menu' => true,
306
+			'show_in_nav_menus' => false,
307
+			'query_var' => true,
308
+			'exclude_from_search' => true,
309
+			'rewrite' => array(
310
+				'slug' => esc_attr( apply_filters( 'sensei_question_slug', _x( 'question', 'post type single slug', 'woothemes-sensei' ) ) ) ,
311
+				'with_front' =>  true,
312
+				'feeds' => true,
313
+				'pages' => true
314
+			),
315
+			'map_meta_cap' => true,
316
+			'capability_type' => 'question',
317
+			'has_archive' => true,
318
+			'hierarchical' => false,
319
+			'menu_position' => 51,
320
+			'supports' => array( 'title' )
321 321
 		);
322 322
 
323
-        /**
324
-         * Filter the arguments passed in when registering the Sensei Question post type.
325
-         *
326
-         * @since 1.9.0
327
-         * @param array $args
328
-         */
323
+		/**
324
+		 * Filter the arguments passed in when registering the Sensei Question post type.
325
+		 *
326
+		 * @since 1.9.0
327
+		 * @param array $args
328
+		 */
329 329
 		register_post_type( 'question', apply_filters('sensei_register_post_type_question', $args ) );
330 330
 
331 331
 	} // End setup_question_post_type()
@@ -338,26 +338,26 @@  discard block
 block discarded – undo
338 338
 	public function setup_multiple_question_post_type () {
339 339
 
340 340
 		$args = array(
341
-		    'labels' => $this->create_post_type_labels( $this->labels['multiple_question']['singular'], $this->labels['multiple_question']['plural'], $this->labels['multiple_question']['menu'] ),
342
-		    'public' => false,
343
-		    'publicly_queryable' => false,
344
-		    'show_ui' => false,
345
-		    'show_in_menu' => false,
346
-		    'show_in_nav_menus' => false,
347
-		    'query_var' => false,
348
-		    'exclude_from_search' => true,
349
-		    'rewrite' => array(
350
-                'slug' => esc_attr( apply_filters( 'sensei_multiple_question_slug', _x( 'multiple_question', 'post type single slug', 'woothemes-sensei' ) ) ) ,
351
-                'with_front' =>  false,
352
-                'feeds' => false,
353
-                'pages' => false
354
-            ),
355
-		    'map_meta_cap' => true,
356
-		    'capability_type' => 'question',
357
-		    'has_archive' => false,
358
-		    'hierarchical' => false,
359
-		    'menu_position' => 51,
360
-		    'supports' => array( 'title', 'custom-fields' )
341
+			'labels' => $this->create_post_type_labels( $this->labels['multiple_question']['singular'], $this->labels['multiple_question']['plural'], $this->labels['multiple_question']['menu'] ),
342
+			'public' => false,
343
+			'publicly_queryable' => false,
344
+			'show_ui' => false,
345
+			'show_in_menu' => false,
346
+			'show_in_nav_menus' => false,
347
+			'query_var' => false,
348
+			'exclude_from_search' => true,
349
+			'rewrite' => array(
350
+				'slug' => esc_attr( apply_filters( 'sensei_multiple_question_slug', _x( 'multiple_question', 'post type single slug', 'woothemes-sensei' ) ) ) ,
351
+				'with_front' =>  false,
352
+				'feeds' => false,
353
+				'pages' => false
354
+			),
355
+			'map_meta_cap' => true,
356
+			'capability_type' => 'question',
357
+			'has_archive' => false,
358
+			'hierarchical' => false,
359
+			'menu_position' => 51,
360
+			'supports' => array( 'title', 'custom-fields' )
361 361
 		);
362 362
 
363 363
 		register_post_type( 'multiple_question', $args );
@@ -374,34 +374,34 @@  discard block
 block discarded – undo
374 374
 		if( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) {
375 375
 
376 376
 			$args = array(
377
-			    'labels' => $this->create_post_type_labels( $this->labels['sensei_message']['singular'], $this->labels['sensei_message']['plural'], $this->labels['sensei_message']['menu'] ),
378
-			    'public' => true,
379
-			    'publicly_queryable' => true,
380
-			    'show_ui' => true,
381
-			    'show_in_menu' => 'sensei',
382
-			    'show_in_nav_menus' => true,
383
-			    'query_var' => true,
384
-			    'exclude_from_search' => true,
385
-			    'rewrite' => array(
386
-                    'slug' => esc_attr( apply_filters( 'sensei_messages_slug', _x( 'messages', 'post type single slug', 'woothemes-sensei' ) ) ) ,
387
-                    'with_front' =>  false,
388
-                    'feeds' => false,
389
-                    'pages' => true
390
-                ),
391
-			    'map_meta_cap' => true,
392
-			    'capability_type' => 'question',
393
-			    'has_archive' => true,
394
-			    'hierarchical' => false,
395
-			    'menu_position' => 50,
396
-			    'supports' => array( 'title', 'editor', 'comments' ),
377
+				'labels' => $this->create_post_type_labels( $this->labels['sensei_message']['singular'], $this->labels['sensei_message']['plural'], $this->labels['sensei_message']['menu'] ),
378
+				'public' => true,
379
+				'publicly_queryable' => true,
380
+				'show_ui' => true,
381
+				'show_in_menu' => 'sensei',
382
+				'show_in_nav_menus' => true,
383
+				'query_var' => true,
384
+				'exclude_from_search' => true,
385
+				'rewrite' => array(
386
+					'slug' => esc_attr( apply_filters( 'sensei_messages_slug', _x( 'messages', 'post type single slug', 'woothemes-sensei' ) ) ) ,
387
+					'with_front' =>  false,
388
+					'feeds' => false,
389
+					'pages' => true
390
+				),
391
+				'map_meta_cap' => true,
392
+				'capability_type' => 'question',
393
+				'has_archive' => true,
394
+				'hierarchical' => false,
395
+				'menu_position' => 50,
396
+				'supports' => array( 'title', 'editor', 'comments' ),
397 397
 			);
398 398
 
399
-            /**
400
-             * Filter the arguments passed in when registering the Sensei sensei_message post type.
401
-             *
402
-             * @since 1.9.0
403
-             * @param array $args
404
-             */
399
+			/**
400
+			 * Filter the arguments passed in when registering the Sensei sensei_message post type.
401
+			 *
402
+			 * @since 1.9.0
403
+			 * @param array $args
404
+			 */
405 405
 			register_post_type( 'sensei_message', apply_filters('sensei_register_post_type_sensei_message',  $args ) );
406 406
 		}
407 407
 	} // End setup_sensei_message_post_type()
@@ -434,11 +434,11 @@  discard block
 block discarded – undo
434 434
 			'show_ui' => true,
435 435
 			'query_var' => true,
436 436
 			'show_in_nav_menus' => true,
437
-            'capabilities' => array(
438
-                'manage_terms' => 'manage_categories',
439
-                'edit_terms'   => 'edit_courses',
440
-                'delete_terms' => 'manage_categories',
441
-                'assign_terms' => 'edit_courses',),
437
+			'capabilities' => array(
438
+				'manage_terms' => 'manage_categories',
439
+				'edit_terms'   => 'edit_courses',
440
+				'delete_terms' => 'manage_categories',
441
+				'assign_terms' => 'edit_courses',),
442 442
 			'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_course_category_slug', _x( 'course-category', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) )
443 443
 		);
444 444
 
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
 			'show_ui' => true, /* TO DO - future releases */
475 475
 			'query_var' => true,
476 476
 			'show_in_nav_menus' => false,
477
-            'public' => false,
477
+			'public' => false,
478 478
 			'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_quiz_type_slug', _x( 'quiz-type', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) )
479 479
 		);
480 480
 
@@ -546,11 +546,11 @@  discard block
 block discarded – undo
546 546
 			'query_var' => false,
547 547
 			'show_in_nav_menus' => false,
548 548
 			'show_admin_column' => true,
549
-            'capabilities' => array(
550
-                'manage_terms' => 'manage_categories',
551
-                'edit_terms'   => 'edit_questions',
552
-                'delete_terms' => 'manage_categories',
553
-                'assign_terms' => 'edit_questions',),
549
+			'capabilities' => array(
550
+				'manage_terms' => 'manage_categories',
551
+				'edit_terms'   => 'edit_questions',
552
+				'delete_terms' => 'manage_categories',
553
+				'assign_terms' => 'edit_questions',),
554 554
 			'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_question_category_slug', _x( 'question-category', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) )
555 555
 		);
556 556
 
@@ -584,11 +584,11 @@  discard block
 block discarded – undo
584 584
 			'show_ui' => true,
585 585
 			'query_var' => true,
586 586
 			'show_in_nav_menus' => true,
587
-            'capabilities' => array(
588
-                'manage_terms' => 'manage_categories',
589
-                'edit_terms'   => 'edit_lessons',
590
-                'delete_terms' => 'manage_categories',
591
-                'assign_terms' => 'edit_lessons',),
587
+			'capabilities' => array(
588
+				'manage_terms' => 'manage_categories',
589
+				'edit_terms'   => 'edit_lessons',
590
+				'delete_terms' => 'manage_categories',
591
+				'assign_terms' => 'edit_lessons',),
592 592
 			'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_lesson_tag_slug', _x( 'lesson-tag', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) )
593 593
 		);
594 594
 
@@ -622,19 +622,19 @@  discard block
 block discarded – undo
622 622
 	 */
623 623
 	private function create_post_type_labels ( $singular, $plural, $menu ) {
624 624
 		$labels = array(
625
-		    'name' => sprintf( _x( '%s', 'post type general name', 'woothemes-sensei' ), $plural ),
626
-		    'singular_name' => sprintf( _x( '%s', 'post type singular name', 'woothemes-sensei' ), $singular ),
627
-		    'add_new' => __( 'Add New', 'woothemes-sensei' ),
628
-		    'add_new_item' => sprintf( __( 'Add New %s', 'woothemes-sensei' ), $singular ),
629
-		    'edit_item' => sprintf( __( 'Edit %s', 'woothemes-sensei' ), $singular ),
630
-		    'new_item' => sprintf( __( 'New %s', 'woothemes-sensei' ), $singular ),
631
-		    'all_items' => sprintf( __( 'All %s', 'woothemes-sensei' ), $plural ),
632
-		    'view_item' => sprintf( __( 'View %s', 'woothemes-sensei' ), $singular ),
633
-		    'search_items' => sprintf( __( 'Search %s', 'woothemes-sensei' ), $plural ),
634
-		    'not_found' =>  sprintf( __( 'No %s found', 'woothemes-sensei' ), mb_strtolower( $plural, 'UTF-8') ),
635
-		    'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'woothemes-sensei' ), mb_strtolower( $plural, 'UTF-8') ),
636
-		    'parent_item_colon' => '',
637
-		    'menu_name' => sprintf( __( '%s', 'woothemes-sensei' ), $menu )
625
+			'name' => sprintf( _x( '%s', 'post type general name', 'woothemes-sensei' ), $plural ),
626
+			'singular_name' => sprintf( _x( '%s', 'post type singular name', 'woothemes-sensei' ), $singular ),
627
+			'add_new' => __( 'Add New', 'woothemes-sensei' ),
628
+			'add_new_item' => sprintf( __( 'Add New %s', 'woothemes-sensei' ), $singular ),
629
+			'edit_item' => sprintf( __( 'Edit %s', 'woothemes-sensei' ), $singular ),
630
+			'new_item' => sprintf( __( 'New %s', 'woothemes-sensei' ), $singular ),
631
+			'all_items' => sprintf( __( 'All %s', 'woothemes-sensei' ), $plural ),
632
+			'view_item' => sprintf( __( 'View %s', 'woothemes-sensei' ), $singular ),
633
+			'search_items' => sprintf( __( 'Search %s', 'woothemes-sensei' ), $plural ),
634
+			'not_found' =>  sprintf( __( 'No %s found', 'woothemes-sensei' ), mb_strtolower( $plural, 'UTF-8') ),
635
+			'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'woothemes-sensei' ), mb_strtolower( $plural, 'UTF-8') ),
636
+			'parent_item_colon' => '',
637
+			'menu_name' => sprintf( __( '%s', 'woothemes-sensei' ), $menu )
638 638
 		  );
639 639
 
640 640
 		return $labels;
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
 	 * Assigns the defaults for each user role capabilities.
708 708
 	 *
709 709
 	 * @since  1.1.0
710
-     *
710
+	 *
711 711
 	 * @param array $post_types
712 712
 	 * @return void
713 713
 	 */
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
 	 * Adds a 'Edit Quiz' link to the admin bar when viewing a Quiz linked to a corresponding Lesson
776 776
 	 * 
777 777
 	 * @since  1.7.0
778
-     * @param WP_Admin_Bar $bar
778
+	 * @param WP_Admin_Bar $bar
779 779
 	 * @return void
780 780
 	 */
781 781
 	public function quiz_admin_bar_menu( $bar ) {
Please login to merge, or discard this patch.
includes/class-sensei-student.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -13,46 +13,46 @@
 block discarded – undo
13 13
  */
14 14
 class Sensei_Student{
15 15
 
16
-    /**
17
-     * Get the students full name
18
-     *
19
-     * This function replaces Sensei_Learner_Managment->get_learner_full_name
20
-     * @since 1.9.0
21
-     *
22
-     * @param $user_id
23
-     * @return bool|mixed|void
24
-     */
25
-    public static function get_full_name( $user_id ){
16
+	/**
17
+	 * Get the students full name
18
+	 *
19
+	 * This function replaces Sensei_Learner_Managment->get_learner_full_name
20
+	 * @since 1.9.0
21
+	 *
22
+	 * @param $user_id
23
+	 * @return bool|mixed|void
24
+	 */
25
+	public static function get_full_name( $user_id ){
26 26
 
27
-        $full_name = '';
27
+		$full_name = '';
28 28
 
29
-        if( empty( $user_id ) || ! ( 0 < intval( $user_id ) )
30
-            || !( get_userdata( $user_id ) ) ){
31
-            return false;
32
-        }
29
+		if( empty( $user_id ) || ! ( 0 < intval( $user_id ) )
30
+			|| !( get_userdata( $user_id ) ) ){
31
+			return false;
32
+		}
33 33
 
34
-        // get the user details
35
-        $user = get_user_by( 'id', $user_id );
34
+		// get the user details
35
+		$user = get_user_by( 'id', $user_id );
36 36
 
37
-        if( ! empty( $user->first_name  ) && ! empty( $user->last_name  )  ){
37
+		if( ! empty( $user->first_name  ) && ! empty( $user->last_name  )  ){
38 38
 
39
-            $full_name = trim( $user->first_name   ) . ' ' . trim( $user->last_name  );
39
+			$full_name = trim( $user->first_name   ) . ' ' . trim( $user->last_name  );
40 40
 
41
-        }else{
41
+		}else{
42 42
 
43
-            $full_name =  $user->display_name;
43
+			$full_name =  $user->display_name;
44 44
 
45
-        }
45
+		}
46 46
 
47
-        /**
48
-         * Filter the user full name from the get_learner_full_name function.
49
-         *
50
-         * @since 1.8.0
51
-         * @param $full_name
52
-         * @param $user_id
53
-         */
54
-        return apply_filters( 'sensei_learner_full_name' , $full_name , $user_id );
47
+		/**
48
+		 * Filter the user full name from the get_learner_full_name function.
49
+		 *
50
+		 * @since 1.8.0
51
+		 * @param $full_name
52
+		 * @param $user_id
53
+		 */
54
+		return apply_filters( 'sensei_learner_full_name' , $full_name , $user_id );
55 55
 
56
-    }// end get_full_name
56
+	}// end get_full_name
57 57
 
58 58
 }
59 59
\ No newline at end of file
Please login to merge, or discard this patch.