@@ -1,32 +1,32 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) exit; |
3 | 3 | /** |
4 | - * List the Course Modules and Lesson in these modules |
|
5 | - * |
|
6 | - * Template is hooked into Single Course sensei_single_main_content. It will |
|
7 | - * only be shown if the course contains modules. |
|
8 | - * |
|
9 | - * All lessons shown here will not be included in the list of other lessons. |
|
10 | - * |
|
11 | - * @author Automattic |
|
12 | - * @package Sensei |
|
13 | - * @category Templates |
|
14 | - * @version 1.9.0 |
|
15 | - */ |
|
4 | + * List the Course Modules and Lesson in these modules |
|
5 | + * |
|
6 | + * Template is hooked into Single Course sensei_single_main_content. It will |
|
7 | + * only be shown if the course contains modules. |
|
8 | + * |
|
9 | + * All lessons shown here will not be included in the list of other lessons. |
|
10 | + * |
|
11 | + * @author Automattic |
|
12 | + * @package Sensei |
|
13 | + * @category Templates |
|
14 | + * @version 1.9.0 |
|
15 | + */ |
|
16 | 16 | ?> |
17 | 17 | |
18 | 18 | <?php |
19 | 19 | |
20 | - /** |
|
21 | - * Hook runs inside single-course/course-modules.php |
|
22 | - * |
|
23 | - * It runs before the modules are shown. This hook fires on the single course page. It will show |
|
24 | - * irrespective of irrespective the course has any modules or not. |
|
25 | - * |
|
26 | - * @since 1.8.0 |
|
27 | - * |
|
28 | - */ |
|
29 | - do_action('sensei_single_course_modules_before'); |
|
20 | + /** |
|
21 | + * Hook runs inside single-course/course-modules.php |
|
22 | + * |
|
23 | + * It runs before the modules are shown. This hook fires on the single course page. It will show |
|
24 | + * irrespective of irrespective the course has any modules or not. |
|
25 | + * |
|
26 | + * @since 1.8.0 |
|
27 | + * |
|
28 | + */ |
|
29 | + do_action('sensei_single_course_modules_before'); |
|
30 | 30 | |
31 | 31 | ?> |
32 | 32 | |
@@ -39,19 +39,19 @@ discard block |
||
39 | 39 | |
40 | 40 | <?php |
41 | 41 | |
42 | - /** |
|
43 | - * Hook runs inside single-course/course-modules.php |
|
44 | - * |
|
45 | - * It runs inside the if statement after the article tag opens just before the modules are shown. This hook will NOT fire if there |
|
46 | - * are no modules to show. |
|
47 | - * |
|
48 | - * @since 1.9.0 |
|
49 | - * |
|
50 | - * @hooked Sensei()->modules->course_modules_title - 20 |
|
51 | - */ |
|
52 | - do_action('sensei_single_course_modules_inside_before'); |
|
42 | + /** |
|
43 | + * Hook runs inside single-course/course-modules.php |
|
44 | + * |
|
45 | + * It runs inside the if statement after the article tag opens just before the modules are shown. This hook will NOT fire if there |
|
46 | + * are no modules to show. |
|
47 | + * |
|
48 | + * @since 1.9.0 |
|
49 | + * |
|
50 | + * @hooked Sensei()->modules->course_modules_title - 20 |
|
51 | + */ |
|
52 | + do_action('sensei_single_course_modules_inside_before'); |
|
53 | 53 | |
54 | - ?> |
|
54 | + ?> |
|
55 | 55 | |
56 | 56 | <header> |
57 | 57 | |
@@ -101,18 +101,18 @@ discard block |
||
101 | 101 | |
102 | 102 | <?php |
103 | 103 | |
104 | - /** |
|
105 | - * Hook runs inside single-course/course-modules.php |
|
106 | - * |
|
107 | - * It runs inside the if statement before the closing article tag directly after the modules were shown. |
|
108 | - * This hook will not trigger if there are no modules to show. |
|
109 | - * |
|
110 | - * @since 1.9.0 |
|
111 | - * |
|
112 | - */ |
|
113 | - do_action('sensei_single_course_modules_inside_after'); |
|
114 | - |
|
115 | - ?> |
|
104 | + /** |
|
105 | + * Hook runs inside single-course/course-modules.php |
|
106 | + * |
|
107 | + * It runs inside the if statement before the closing article tag directly after the modules were shown. |
|
108 | + * This hook will not trigger if there are no modules to show. |
|
109 | + * |
|
110 | + * @since 1.9.0 |
|
111 | + * |
|
112 | + */ |
|
113 | + do_action('sensei_single_course_modules_inside_after'); |
|
114 | + |
|
115 | + ?> |
|
116 | 116 | |
117 | 117 | </article> |
118 | 118 |
@@ -10,1343 +10,1343 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class Sensei_Main { |
12 | 12 | |
13 | - /** |
|
14 | - * @var string |
|
15 | - * Reference to the main plugin file |
|
16 | - */ |
|
17 | - private $file; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var Sensei_Main $_instance to the the main and only instance of the Sensei class. |
|
21 | - * @since 1.8.0 |
|
22 | - */ |
|
23 | - protected static $_instance = null; |
|
24 | - |
|
25 | - /** |
|
26 | - * Main reference to the plugins current version |
|
27 | - */ |
|
28 | - public $version; |
|
29 | - |
|
30 | - /** |
|
31 | - * Public token, referencing for the text domain. |
|
32 | - */ |
|
33 | - public $token = 'woothemes-sensei'; |
|
34 | - |
|
35 | - /** |
|
36 | - * Plugin url and path for use when access resources. |
|
37 | - */ |
|
38 | - public $plugin_url; |
|
39 | - public $plugin_path; |
|
40 | - public $template_url; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var Sensei_PostTypes |
|
44 | - * All Sensei sub classes. Currently used to access functionality contained within |
|
45 | - * within Sensei sub classes e.g. Sensei()->course->all_courses() |
|
46 | - */ |
|
47 | - public $post_types; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var WooThemes_Sensei_Settings |
|
51 | - */ |
|
52 | - public $settings; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var WooThemes_Sensei_Course_Results |
|
56 | - */ |
|
57 | - public $course_results; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var Sensei_Updates |
|
61 | - */ |
|
62 | - public $updates; |
|
63 | - /** |
|
64 | - * @var WooThemes_Sensei_Course |
|
65 | - */ |
|
66 | - public $course; |
|
67 | - |
|
68 | - /** |
|
69 | - * @var WooThemes_Sensei_Lesson |
|
70 | - */ |
|
71 | - public $lesson; |
|
72 | - |
|
73 | - /** |
|
74 | - * @var WooThemes_Sensei_Quiz |
|
75 | - */ |
|
76 | - public $quiz; |
|
77 | - |
|
78 | - /** |
|
79 | - * @var WooThemes_Sensei_Question |
|
80 | - */ |
|
81 | - public $question; |
|
82 | - |
|
83 | - /** |
|
84 | - * @var WooThemes_Sensei_Admin |
|
85 | - */ |
|
86 | - public $admin; |
|
87 | - |
|
88 | - /** |
|
89 | - * @var WooThemes_Sensei_Frontend |
|
90 | - */ |
|
91 | - public $frontend; |
|
92 | - |
|
93 | - /** |
|
94 | - * @var Sensei_Notices |
|
95 | - */ |
|
96 | - public $notices; |
|
97 | - |
|
98 | - /** |
|
99 | - * @var WooThemes_Sensei_Grading |
|
100 | - */ |
|
101 | - public $grading; |
|
102 | - |
|
103 | - /** |
|
104 | - * @var WooThemes_Sensei_Emails |
|
105 | - */ |
|
106 | - public $emails; |
|
107 | - |
|
108 | - /** |
|
109 | - * @var WooThemes_Sensei_Learner_Profiles |
|
110 | - */ |
|
111 | - public $learner_profiles; |
|
112 | - |
|
113 | - /** |
|
114 | - * @var Sensei_Teacher |
|
115 | - */ |
|
116 | - public $teacher; |
|
117 | - |
|
118 | - /** |
|
119 | - * @var WooThemes_Sensei_Learners |
|
120 | - */ |
|
121 | - public $learners; |
|
122 | - |
|
123 | - /** |
|
124 | - * @var array |
|
125 | - * Global instance for access to the permissions message shown |
|
126 | - * when users do not have the right privileges to access resources. |
|
127 | - */ |
|
128 | - public $permissions_message; |
|
129 | - |
|
130 | - /** |
|
131 | - * @var Sensei_Core_Modules Sensei Modules functionality |
|
132 | - */ |
|
133 | - public $modules; |
|
134 | - |
|
135 | - /** |
|
136 | - * @var Sensei_Analysis |
|
137 | - */ |
|
138 | - public $analysis; |
|
139 | - |
|
140 | - /** |
|
141 | - * Constructor method. |
|
142 | - * @param string $file The base file of the plugin. |
|
143 | - * @since 1.0.0 |
|
144 | - */ |
|
145 | - public function __construct ( $file ) { |
|
146 | - |
|
147 | - // Setup object data |
|
148 | - $this->file = $file; |
|
149 | - $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) ); |
|
150 | - $this->plugin_path = trailingslashit( dirname( $file ) ); |
|
151 | - $this->template_url = apply_filters( 'sensei_template_url', 'sensei/' ); |
|
152 | - $this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) ); |
|
153 | - |
|
154 | - // Initialize the core Sensei functionality |
|
155 | - $this->init(); |
|
156 | - |
|
157 | - // Installation |
|
158 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
159 | - |
|
160 | - // Run this on activation. |
|
161 | - register_activation_hook( $this->file, array( $this, 'activation' ) ); |
|
162 | - |
|
163 | - // Image Sizes |
|
164 | - $this->init_image_sizes(); |
|
165 | - |
|
166 | - // Force WooCommerce Required Settings |
|
167 | - $this->set_woocommerce_functionality(); |
|
168 | - |
|
169 | - // load all hooks |
|
170 | - $this->load_hooks(); |
|
171 | - |
|
172 | - } // End __construct() |
|
173 | - |
|
174 | - /** |
|
175 | - * Load the foundations of Sensei. |
|
176 | - * @since 1.9.0 |
|
177 | - */ |
|
178 | - protected function init(){ |
|
179 | - |
|
180 | - // Localisation |
|
181 | - $this->load_plugin_textdomain(); |
|
182 | - add_action( 'init', array( $this, 'load_localisation' ), 0 ); |
|
183 | - |
|
184 | - // load the shortcode loader into memory, so as to listen to all for |
|
185 | - // all shortcodes on the front end |
|
186 | - new Sensei_Shortcode_Loader(); |
|
187 | - |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Global Sensei Instance |
|
192 | - * |
|
193 | - * Ensure that only one instance of the main Sensei class can be loaded. |
|
194 | - * |
|
195 | - * @since 1.8.0 |
|
196 | - * @static |
|
197 | - * @see WC() |
|
198 | - * @return WooThemes_Sensei Instance. |
|
199 | - */ |
|
200 | - public static function instance() { |
|
13 | + /** |
|
14 | + * @var string |
|
15 | + * Reference to the main plugin file |
|
16 | + */ |
|
17 | + private $file; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var Sensei_Main $_instance to the the main and only instance of the Sensei class. |
|
21 | + * @since 1.8.0 |
|
22 | + */ |
|
23 | + protected static $_instance = null; |
|
24 | + |
|
25 | + /** |
|
26 | + * Main reference to the plugins current version |
|
27 | + */ |
|
28 | + public $version; |
|
29 | + |
|
30 | + /** |
|
31 | + * Public token, referencing for the text domain. |
|
32 | + */ |
|
33 | + public $token = 'woothemes-sensei'; |
|
34 | + |
|
35 | + /** |
|
36 | + * Plugin url and path for use when access resources. |
|
37 | + */ |
|
38 | + public $plugin_url; |
|
39 | + public $plugin_path; |
|
40 | + public $template_url; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var Sensei_PostTypes |
|
44 | + * All Sensei sub classes. Currently used to access functionality contained within |
|
45 | + * within Sensei sub classes e.g. Sensei()->course->all_courses() |
|
46 | + */ |
|
47 | + public $post_types; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var WooThemes_Sensei_Settings |
|
51 | + */ |
|
52 | + public $settings; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var WooThemes_Sensei_Course_Results |
|
56 | + */ |
|
57 | + public $course_results; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var Sensei_Updates |
|
61 | + */ |
|
62 | + public $updates; |
|
63 | + /** |
|
64 | + * @var WooThemes_Sensei_Course |
|
65 | + */ |
|
66 | + public $course; |
|
67 | + |
|
68 | + /** |
|
69 | + * @var WooThemes_Sensei_Lesson |
|
70 | + */ |
|
71 | + public $lesson; |
|
72 | + |
|
73 | + /** |
|
74 | + * @var WooThemes_Sensei_Quiz |
|
75 | + */ |
|
76 | + public $quiz; |
|
77 | + |
|
78 | + /** |
|
79 | + * @var WooThemes_Sensei_Question |
|
80 | + */ |
|
81 | + public $question; |
|
82 | + |
|
83 | + /** |
|
84 | + * @var WooThemes_Sensei_Admin |
|
85 | + */ |
|
86 | + public $admin; |
|
87 | + |
|
88 | + /** |
|
89 | + * @var WooThemes_Sensei_Frontend |
|
90 | + */ |
|
91 | + public $frontend; |
|
92 | + |
|
93 | + /** |
|
94 | + * @var Sensei_Notices |
|
95 | + */ |
|
96 | + public $notices; |
|
97 | + |
|
98 | + /** |
|
99 | + * @var WooThemes_Sensei_Grading |
|
100 | + */ |
|
101 | + public $grading; |
|
102 | + |
|
103 | + /** |
|
104 | + * @var WooThemes_Sensei_Emails |
|
105 | + */ |
|
106 | + public $emails; |
|
107 | + |
|
108 | + /** |
|
109 | + * @var WooThemes_Sensei_Learner_Profiles |
|
110 | + */ |
|
111 | + public $learner_profiles; |
|
112 | + |
|
113 | + /** |
|
114 | + * @var Sensei_Teacher |
|
115 | + */ |
|
116 | + public $teacher; |
|
117 | + |
|
118 | + /** |
|
119 | + * @var WooThemes_Sensei_Learners |
|
120 | + */ |
|
121 | + public $learners; |
|
122 | + |
|
123 | + /** |
|
124 | + * @var array |
|
125 | + * Global instance for access to the permissions message shown |
|
126 | + * when users do not have the right privileges to access resources. |
|
127 | + */ |
|
128 | + public $permissions_message; |
|
129 | + |
|
130 | + /** |
|
131 | + * @var Sensei_Core_Modules Sensei Modules functionality |
|
132 | + */ |
|
133 | + public $modules; |
|
134 | + |
|
135 | + /** |
|
136 | + * @var Sensei_Analysis |
|
137 | + */ |
|
138 | + public $analysis; |
|
139 | + |
|
140 | + /** |
|
141 | + * Constructor method. |
|
142 | + * @param string $file The base file of the plugin. |
|
143 | + * @since 1.0.0 |
|
144 | + */ |
|
145 | + public function __construct ( $file ) { |
|
146 | + |
|
147 | + // Setup object data |
|
148 | + $this->file = $file; |
|
149 | + $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) ); |
|
150 | + $this->plugin_path = trailingslashit( dirname( $file ) ); |
|
151 | + $this->template_url = apply_filters( 'sensei_template_url', 'sensei/' ); |
|
152 | + $this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) ); |
|
153 | + |
|
154 | + // Initialize the core Sensei functionality |
|
155 | + $this->init(); |
|
156 | + |
|
157 | + // Installation |
|
158 | + if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
159 | + |
|
160 | + // Run this on activation. |
|
161 | + register_activation_hook( $this->file, array( $this, 'activation' ) ); |
|
162 | + |
|
163 | + // Image Sizes |
|
164 | + $this->init_image_sizes(); |
|
165 | + |
|
166 | + // Force WooCommerce Required Settings |
|
167 | + $this->set_woocommerce_functionality(); |
|
168 | + |
|
169 | + // load all hooks |
|
170 | + $this->load_hooks(); |
|
171 | + |
|
172 | + } // End __construct() |
|
173 | + |
|
174 | + /** |
|
175 | + * Load the foundations of Sensei. |
|
176 | + * @since 1.9.0 |
|
177 | + */ |
|
178 | + protected function init(){ |
|
179 | + |
|
180 | + // Localisation |
|
181 | + $this->load_plugin_textdomain(); |
|
182 | + add_action( 'init', array( $this, 'load_localisation' ), 0 ); |
|
183 | + |
|
184 | + // load the shortcode loader into memory, so as to listen to all for |
|
185 | + // all shortcodes on the front end |
|
186 | + new Sensei_Shortcode_Loader(); |
|
187 | + |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Global Sensei Instance |
|
192 | + * |
|
193 | + * Ensure that only one instance of the main Sensei class can be loaded. |
|
194 | + * |
|
195 | + * @since 1.8.0 |
|
196 | + * @static |
|
197 | + * @see WC() |
|
198 | + * @return WooThemes_Sensei Instance. |
|
199 | + */ |
|
200 | + public static function instance() { |
|
201 | 201 | |
202 | - if ( is_null( self::$_instance ) ) { |
|
202 | + if ( is_null( self::$_instance ) ) { |
|
203 | 203 | |
204 | - //Sensei requires a reference to the main Sensei plugin file |
|
205 | - $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php'; |
|
204 | + //Sensei requires a reference to the main Sensei plugin file |
|
205 | + $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php'; |
|
206 | 206 | |
207 | - self::$_instance = new self( $sensei_main_plugin_file ); |
|
207 | + self::$_instance = new self( $sensei_main_plugin_file ); |
|
208 | 208 | |
209 | - // load the global class objects needed throughout Sensei |
|
210 | - self::$_instance->initialize_global_objects(); |
|
209 | + // load the global class objects needed throughout Sensei |
|
210 | + self::$_instance->initialize_global_objects(); |
|
211 | 211 | |
212 | - } |
|
212 | + } |
|
213 | 213 | |
214 | - return self::$_instance; |
|
214 | + return self::$_instance; |
|
215 | 215 | |
216 | - } // end instance() |
|
216 | + } // end instance() |
|
217 | 217 | |
218 | - /** |
|
219 | - * This function is linked into the activation |
|
220 | - * hook to reset flush the urls to ensure Sensei post types show up. |
|
221 | - * |
|
222 | - * @since 1.9.0 |
|
223 | - * |
|
224 | - * @param $plugin |
|
225 | - */ |
|
226 | - public static function activation_flush_rules( $plugin ){ |
|
218 | + /** |
|
219 | + * This function is linked into the activation |
|
220 | + * hook to reset flush the urls to ensure Sensei post types show up. |
|
221 | + * |
|
222 | + * @since 1.9.0 |
|
223 | + * |
|
224 | + * @param $plugin |
|
225 | + */ |
|
226 | + public static function activation_flush_rules( $plugin ){ |
|
227 | 227 | |
228 | - if( strpos( $plugin, '/woothemes-sensei.php' ) > 0 ){ |
|
228 | + if( strpos( $plugin, '/woothemes-sensei.php' ) > 0 ){ |
|
229 | 229 | |
230 | - flush_rewrite_rules(true); |
|
230 | + flush_rewrite_rules(true); |
|
231 | 231 | |
232 | - } |
|
232 | + } |
|
233 | 233 | |
234 | - } |
|
234 | + } |
|
235 | 235 | |
236 | - /** |
|
237 | - * Cloning is forbidden. |
|
238 | - * @since 1.8.0 |
|
239 | - */ |
|
240 | - public function __clone() { |
|
241 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '1.8' ); |
|
242 | - } |
|
236 | + /** |
|
237 | + * Cloning is forbidden. |
|
238 | + * @since 1.8.0 |
|
239 | + */ |
|
240 | + public function __clone() { |
|
241 | + _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '1.8' ); |
|
242 | + } |
|
243 | 243 | |
244 | - /** |
|
245 | - * Unserializing instances of this class is forbidden. |
|
246 | - * @since 1.8.0 |
|
247 | - */ |
|
248 | - public function __wakeup() { |
|
249 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '1.8' ); |
|
250 | - } |
|
244 | + /** |
|
245 | + * Unserializing instances of this class is forbidden. |
|
246 | + * @since 1.8.0 |
|
247 | + */ |
|
248 | + public function __wakeup() { |
|
249 | + _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '1.8' ); |
|
250 | + } |
|
251 | 251 | |
252 | - /** |
|
253 | - * Load the properties for the main Sensei object |
|
254 | - * |
|
255 | - * @since 1.9.0 |
|
256 | - */ |
|
257 | - public function initialize_global_objects(){ |
|
252 | + /** |
|
253 | + * Load the properties for the main Sensei object |
|
254 | + * |
|
255 | + * @since 1.9.0 |
|
256 | + */ |
|
257 | + public function initialize_global_objects(){ |
|
258 | 258 | |
259 | - // Setup post types. |
|
260 | - $this->post_types = new Sensei_PostTypes(); |
|
259 | + // Setup post types. |
|
260 | + $this->post_types = new Sensei_PostTypes(); |
|
261 | 261 | |
262 | - // Lad the updates class |
|
263 | - $this->updates = new Sensei_Updates( $this ); |
|
262 | + // Lad the updates class |
|
263 | + $this->updates = new Sensei_Updates( $this ); |
|
264 | 264 | |
265 | - // Setup settings |
|
266 | - $this->settings = new Sensei_Settings(); |
|
265 | + // Setup settings |
|
266 | + $this->settings = new Sensei_Settings(); |
|
267 | 267 | |
268 | - // Load Course Results Class |
|
269 | - $this->course_results = new Sensei_Course_Results(); |
|
268 | + // Load Course Results Class |
|
269 | + $this->course_results = new Sensei_Course_Results(); |
|
270 | 270 | |
271 | - // Load the teacher role |
|
272 | - $this->teacher = new Sensei_Teacher(); |
|
271 | + // Load the teacher role |
|
272 | + $this->teacher = new Sensei_Teacher(); |
|
273 | 273 | |
274 | - // Add the Course class |
|
275 | - $this->course = $this->post_types->course; |
|
274 | + // Add the Course class |
|
275 | + $this->course = $this->post_types->course; |
|
276 | 276 | |
277 | - // Add the lesson class |
|
278 | - $this->lesson = $this->post_types->lesson; |
|
277 | + // Add the lesson class |
|
278 | + $this->lesson = $this->post_types->lesson; |
|
279 | 279 | |
280 | - // Add the question class |
|
281 | - $this->question = $this->post_types->question; |
|
280 | + // Add the question class |
|
281 | + $this->question = $this->post_types->question; |
|
282 | 282 | |
283 | - //Add the quiz class |
|
284 | - $this->quiz = $this->post_types->quiz; |
|
283 | + //Add the quiz class |
|
284 | + $this->quiz = $this->post_types->quiz; |
|
285 | 285 | |
286 | - // load the modules class after all plugsin are loaded |
|
287 | - add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) ); |
|
286 | + // load the modules class after all plugsin are loaded |
|
287 | + add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) ); |
|
288 | 288 | |
289 | - // Load Learner Management Functionality |
|
290 | - $this->learners = new Sensei_Learner_Management( $this->file ); |
|
289 | + // Load Learner Management Functionality |
|
290 | + $this->learners = new Sensei_Learner_Management( $this->file ); |
|
291 | 291 | |
292 | - // Differentiate between administration and frontend logic. |
|
293 | - if ( is_admin() ) { |
|
292 | + // Differentiate between administration and frontend logic. |
|
293 | + if ( is_admin() ) { |
|
294 | 294 | |
295 | - // Load Admin Welcome class |
|
296 | - new Sensei_Welcome(); |
|
295 | + // Load Admin Welcome class |
|
296 | + new Sensei_Welcome(); |
|
297 | 297 | |
298 | - // Load Admin Class |
|
299 | - $this->admin = new Sensei_Admin( $this->file ); |
|
298 | + // Load Admin Class |
|
299 | + $this->admin = new Sensei_Admin( $this->file ); |
|
300 | 300 | |
301 | - // Load Analysis Reports |
|
302 | - $this->analysis = new Sensei_Analysis( $this->file ); |
|
301 | + // Load Analysis Reports |
|
302 | + $this->analysis = new Sensei_Analysis( $this->file ); |
|
303 | 303 | |
304 | - } else { |
|
304 | + } else { |
|
305 | 305 | |
306 | - // Load Frontend Class |
|
307 | - $this->frontend = new Sensei_Frontend(); |
|
306 | + // Load Frontend Class |
|
307 | + $this->frontend = new Sensei_Frontend(); |
|
308 | 308 | |
309 | - // Load notice Class |
|
310 | - $this->notices = new Sensei_Notices(); |
|
309 | + // Load notice Class |
|
310 | + $this->notices = new Sensei_Notices(); |
|
311 | 311 | |
312 | - // Load built in themes support integration |
|
313 | - new Sensei_Theme_Integration_Loader(); |
|
312 | + // Load built in themes support integration |
|
313 | + new Sensei_Theme_Integration_Loader(); |
|
314 | 314 | |
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 | - // skipped for single lesson |
|
713 | - if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission') |
|
714 | - && 'lesson-single' != $page ){ |
|
715 | - $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' ); |
|
716 | - $this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() ); |
|
717 | - return false; |
|
718 | - } |
|
719 | - |
|
720 | - $user_allowed = false; |
|
721 | - |
|
722 | - switch ( $page ) { |
|
723 | - case 'course-single': |
|
724 | - // check for prerequisite course or lesson, |
|
725 | - $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true); |
|
726 | - $update_course = $this->woocommerce_course_update( $post->ID ); |
|
727 | - // Count completed lessons |
|
728 | - if ( 0 < absint( $course_prerequisite_id ) ) { |
|
729 | - |
|
730 | - $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
|
731 | - |
|
732 | - } |
|
733 | - else { |
|
734 | - $prerequisite_complete = true; |
|
735 | - } // End If Statement |
|
736 | - // Handles restrictions |
|
737 | - if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) { |
|
738 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
739 | - $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
740 | - $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link ); |
|
741 | - } else { |
|
742 | - $user_allowed = true; |
|
743 | - } // End If Statement |
|
744 | - break; |
|
745 | - case 'lesson-single': |
|
746 | - // Check for WC purchase |
|
747 | - $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true ); |
|
748 | - |
|
749 | - $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
750 | - $is_preview = Sensei_Utils::is_preview_lesson( $post->ID ); |
|
751 | - |
|
752 | - if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
753 | - $user_allowed = true; |
|
754 | - } elseif( $this->access_settings() && false == $is_preview ) { |
|
755 | - |
|
756 | - $user_allowed = true; |
|
757 | - |
|
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 | - $course_details_html = '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>'; |
|
1116 | - $order_contains_courses = false; |
|
1117 | - |
|
1118 | - |
|
1119 | - foreach ( $order_items as $item ) { |
|
1120 | - |
|
1121 | - $product_type = ''; |
|
1122 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
1123 | - // If item has variation_id then its from variation |
|
1124 | - $item_id = $item['variation_id']; |
|
1125 | - $product_type = 'variation'; |
|
1126 | - } else { |
|
1127 | - // If not its real product set its id to item_id |
|
1128 | - $item_id = $item['product_id']; |
|
1129 | - } // End If Statement |
|
1130 | - |
|
1131 | - $user_id = get_post_meta( $order_id, '_customer_user', true ); |
|
1132 | - |
|
1133 | - if( $user_id ) { |
|
1134 | - |
|
1135 | - // Get all courses for product |
|
1136 | - $args = array( |
|
1137 | - 'posts_per_page' => -1, |
|
1138 | - 'post_type' => 'course', |
|
1139 | - 'meta_query' => array( |
|
1140 | - array( |
|
1141 | - 'key' => '_course_woocommerce_product', |
|
1142 | - 'value' => $item_id |
|
1143 | - ) |
|
1144 | - ), |
|
1145 | - 'orderby' => 'menu_order date', |
|
1146 | - 'order' => 'ASC', |
|
1147 | - ); |
|
1148 | - $courses = get_posts( $args ); |
|
1149 | - |
|
1150 | - if( $courses && count( $courses ) > 0 ) { |
|
1151 | - |
|
1152 | - foreach( $courses as $course ) { |
|
1153 | - |
|
1154 | - $title = $course->post_title; |
|
1155 | - $permalink = get_permalink( $course->ID ); |
|
1156 | - $order_contains_courses = true; |
|
1157 | - $course_details_html .= '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>'; |
|
1158 | - } |
|
1159 | - |
|
1160 | - |
|
1161 | - } // end if has courses |
|
1162 | - |
|
1163 | - } // end if $userPid |
|
1164 | - |
|
1165 | - } // end for each order item |
|
1166 | - |
|
1167 | - // Output Course details |
|
1168 | - if( $order_contains_courses ){ |
|
1169 | - |
|
1170 | - echo $course_details_html; |
|
1171 | - |
|
1172 | - } |
|
1173 | - |
|
1174 | - |
|
1175 | - } // end if order items not empty |
|
1176 | - |
|
1177 | - } // end func email course details |
|
1178 | - |
|
1179 | - /** |
|
1180 | - * Filtering wp_count_comments to ensure that Sensei comments are ignored |
|
1181 | - * @since 1.4.0 |
|
1182 | - * @access public |
|
1183 | - * @param array $comments |
|
1184 | - * @param integer $post_id |
|
1185 | - * @return array |
|
1186 | - */ |
|
1187 | - public function sensei_count_comments( $comments, $post_id ) { |
|
1188 | - global $wpdb; |
|
1189 | - |
|
1190 | - $post_id = (int) $post_id; |
|
1191 | - |
|
1192 | - $count = wp_cache_get("comments-{$post_id}", 'counts'); |
|
1193 | - |
|
1194 | - if ( false !== $count ) { |
|
1195 | - return $count; |
|
1196 | - } |
|
1197 | - |
|
1198 | - $statuses = array( '' ); // Default to the WP normal comments |
|
1199 | - $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A ); |
|
1200 | - foreach ( (array) $stati AS $status ) { |
|
1201 | - if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) { |
|
1202 | - $statuses[] = $status['comment_type']; |
|
1203 | - } |
|
1204 | - } |
|
1205 | - $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
|
1206 | - |
|
1207 | - if ( $post_id > 0 ) |
|
1208 | - $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
1209 | - |
|
1210 | - $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
1211 | - |
|
1212 | - $total = 0; |
|
1213 | - $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
|
1214 | - foreach ( (array) $count as $row ) { |
|
1215 | - // Don't count post-trashed toward totals |
|
1216 | - if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
1217 | - $total += $row['num_comments']; |
|
1218 | - if ( isset( $approved[$row['comment_approved']] ) ) |
|
1219 | - $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
1220 | - } |
|
1221 | - |
|
1222 | - $stats['total_comments'] = $total; |
|
1223 | - foreach ( $approved as $key ) { |
|
1224 | - if ( empty($stats[$key]) ) |
|
1225 | - $stats[$key] = 0; |
|
1226 | - } |
|
1227 | - |
|
1228 | - $stats = (object) $stats; |
|
1229 | - wp_cache_set("comments-{$post_id}", $stats, 'counts'); |
|
1230 | - |
|
1231 | - return $stats; |
|
1232 | - } |
|
1233 | - |
|
1234 | - /** |
|
1235 | - * Init images. |
|
1236 | - * |
|
1237 | - * @since 1.4.5 |
|
1238 | - * @access public |
|
1239 | - * @return void |
|
1240 | - */ |
|
1241 | - public function init_image_sizes() { |
|
1242 | - $course_archive_thumbnail = $this->get_image_size( 'course_archive_image' ); |
|
1243 | - $course_single_thumbnail = $this->get_image_size( 'course_single_image' ); |
|
1244 | - $lesson_archive_thumbnail = $this->get_image_size( 'lesson_archive_image' ); |
|
1245 | - $lesson_single_thumbnail = $this->get_image_size( 'lesson_single_image' ); |
|
1246 | - |
|
1247 | - add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] ); |
|
1248 | - add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] ); |
|
1249 | - add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] ); |
|
1250 | - add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] ); |
|
1251 | - } |
|
1252 | - |
|
1253 | - /** |
|
1254 | - * Get an image size. |
|
1255 | - * |
|
1256 | - * Variable is filtered by sensei_get_image_size_{image_size} |
|
1257 | - * |
|
1258 | - * @since 1.4.5 |
|
1259 | - * @access public |
|
1260 | - * @param mixed $image_size |
|
1261 | - * @return string |
|
1262 | - */ |
|
1263 | - public function get_image_size( $image_size ) { |
|
1264 | - |
|
1265 | - // Only return sizes we define in settings |
|
1266 | - if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
1267 | - return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
1268 | - |
|
1269 | - if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
|
1270 | - $this->settings->settings[ $image_size . '_width' ] = false; |
|
1271 | - } |
|
1272 | - if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) { |
|
1273 | - $this->settings->settings[ $image_size . '_height' ] = false; |
|
1274 | - } |
|
1275 | - if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) { |
|
1276 | - $this->settings->settings[ $image_size . '_hard_crop' ] = false; |
|
1277 | - } |
|
1278 | - |
|
1279 | - $size = array_filter( array( |
|
1280 | - 'width' => $this->settings->settings[ $image_size . '_width' ], |
|
1281 | - 'height' => $this->settings->settings[ $image_size . '_height' ], |
|
1282 | - 'crop' => $this->settings->settings[ $image_size . '_hard_crop' ] |
|
1283 | - ) ); |
|
1284 | - |
|
1285 | - $size['width'] = isset( $size['width'] ) ? $size['width'] : '100'; |
|
1286 | - $size['height'] = isset( $size['height'] ) ? $size['height'] : '100'; |
|
1287 | - $size['crop'] = isset( $size['crop'] ) ? $size['crop'] : 0; |
|
1288 | - |
|
1289 | - return apply_filters( 'sensei_get_image_size_' . $image_size, $size ); |
|
1290 | - } |
|
1291 | - |
|
1292 | - public function body_class( $classes ) { |
|
1293 | - if( is_sensei() ) { |
|
1294 | - $classes[] = 'sensei'; |
|
1295 | - } |
|
1296 | - return $classes; |
|
1297 | - } |
|
1298 | - |
|
1299 | - /** |
|
1300 | - * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers |
|
1301 | - * |
|
1302 | - * @return null |
|
1303 | - * @since 1.7.0 |
|
1304 | - */ |
|
1305 | - public function jetpack_latex_support() { |
|
1306 | - if ( function_exists( 'latex_markup') ) { |
|
1307 | - add_filter( 'sensei_question_title', 'latex_markup' ); |
|
1308 | - add_filter( 'sensei_answer_text', 'latex_markup' ); |
|
1309 | - } |
|
1310 | - } |
|
1311 | - |
|
1312 | - /** |
|
1313 | - * Load the module functionality. |
|
1314 | - * |
|
1315 | - * This function is hooked into plugins_loaded to avoid conflicts with |
|
1316 | - * the retired modules extension. |
|
1317 | - * |
|
1318 | - * @since 1.8.0 |
|
1319 | - */ |
|
1320 | - public function load_modules_class(){ |
|
1321 | - global $sensei_modules; |
|
1322 | - |
|
1323 | - if( !class_exists( 'Sensei_Modules' ) |
|
1324 | - && 'Sensei_Modules' != get_class( $sensei_modules ) ) { |
|
1325 | - |
|
1326 | - //Load the modules class |
|
1327 | - require_once( 'class-sensei-modules.php'); |
|
1328 | - Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
|
1329 | - |
|
1330 | - }else{ |
|
1331 | - // fallback for people still using the modules extension. |
|
1332 | - global $sensei_modules; |
|
1333 | - Sensei()->modules = $sensei_modules; |
|
1334 | - add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 ); |
|
1335 | - } |
|
1336 | - } |
|
1337 | - |
|
1338 | - /** |
|
1339 | - * Tell the user to that the modules extension is no longer needed. |
|
1340 | - * |
|
1341 | - * @since 1.8.0 |
|
1342 | - */ |
|
1343 | - 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 | + // skipped for single lesson |
|
713 | + if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission') |
|
714 | + && 'lesson-single' != $page ){ |
|
715 | + $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' ); |
|
716 | + $this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() ); |
|
717 | + return false; |
|
718 | + } |
|
719 | + |
|
720 | + $user_allowed = false; |
|
721 | + |
|
722 | + switch ( $page ) { |
|
723 | + case 'course-single': |
|
724 | + // check for prerequisite course or lesson, |
|
725 | + $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true); |
|
726 | + $update_course = $this->woocommerce_course_update( $post->ID ); |
|
727 | + // Count completed lessons |
|
728 | + if ( 0 < absint( $course_prerequisite_id ) ) { |
|
729 | + |
|
730 | + $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
|
731 | + |
|
732 | + } |
|
733 | + else { |
|
734 | + $prerequisite_complete = true; |
|
735 | + } // End If Statement |
|
736 | + // Handles restrictions |
|
737 | + if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) { |
|
738 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
739 | + $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
740 | + $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link ); |
|
741 | + } else { |
|
742 | + $user_allowed = true; |
|
743 | + } // End If Statement |
|
744 | + break; |
|
745 | + case 'lesson-single': |
|
746 | + // Check for WC purchase |
|
747 | + $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true ); |
|
748 | + |
|
749 | + $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
750 | + $is_preview = Sensei_Utils::is_preview_lesson( $post->ID ); |
|
751 | + |
|
752 | + if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
753 | + $user_allowed = true; |
|
754 | + } elseif( $this->access_settings() && false == $is_preview ) { |
|
755 | + |
|
756 | + $user_allowed = true; |
|
757 | + |
|
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 | + $course_details_html = '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>'; |
|
1116 | + $order_contains_courses = false; |
|
1117 | + |
|
1118 | + |
|
1119 | + foreach ( $order_items as $item ) { |
|
1120 | + |
|
1121 | + $product_type = ''; |
|
1122 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
1123 | + // If item has variation_id then its from variation |
|
1124 | + $item_id = $item['variation_id']; |
|
1125 | + $product_type = 'variation'; |
|
1126 | + } else { |
|
1127 | + // If not its real product set its id to item_id |
|
1128 | + $item_id = $item['product_id']; |
|
1129 | + } // End If Statement |
|
1130 | + |
|
1131 | + $user_id = get_post_meta( $order_id, '_customer_user', true ); |
|
1132 | + |
|
1133 | + if( $user_id ) { |
|
1134 | + |
|
1135 | + // Get all courses for product |
|
1136 | + $args = array( |
|
1137 | + 'posts_per_page' => -1, |
|
1138 | + 'post_type' => 'course', |
|
1139 | + 'meta_query' => array( |
|
1140 | + array( |
|
1141 | + 'key' => '_course_woocommerce_product', |
|
1142 | + 'value' => $item_id |
|
1143 | + ) |
|
1144 | + ), |
|
1145 | + 'orderby' => 'menu_order date', |
|
1146 | + 'order' => 'ASC', |
|
1147 | + ); |
|
1148 | + $courses = get_posts( $args ); |
|
1149 | + |
|
1150 | + if( $courses && count( $courses ) > 0 ) { |
|
1151 | + |
|
1152 | + foreach( $courses as $course ) { |
|
1153 | + |
|
1154 | + $title = $course->post_title; |
|
1155 | + $permalink = get_permalink( $course->ID ); |
|
1156 | + $order_contains_courses = true; |
|
1157 | + $course_details_html .= '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>'; |
|
1158 | + } |
|
1159 | + |
|
1160 | + |
|
1161 | + } // end if has courses |
|
1162 | + |
|
1163 | + } // end if $userPid |
|
1164 | + |
|
1165 | + } // end for each order item |
|
1166 | + |
|
1167 | + // Output Course details |
|
1168 | + if( $order_contains_courses ){ |
|
1169 | + |
|
1170 | + echo $course_details_html; |
|
1171 | + |
|
1172 | + } |
|
1173 | + |
|
1174 | + |
|
1175 | + } // end if order items not empty |
|
1176 | + |
|
1177 | + } // end func email course details |
|
1178 | + |
|
1179 | + /** |
|
1180 | + * Filtering wp_count_comments to ensure that Sensei comments are ignored |
|
1181 | + * @since 1.4.0 |
|
1182 | + * @access public |
|
1183 | + * @param array $comments |
|
1184 | + * @param integer $post_id |
|
1185 | + * @return array |
|
1186 | + */ |
|
1187 | + public function sensei_count_comments( $comments, $post_id ) { |
|
1188 | + global $wpdb; |
|
1189 | + |
|
1190 | + $post_id = (int) $post_id; |
|
1191 | + |
|
1192 | + $count = wp_cache_get("comments-{$post_id}", 'counts'); |
|
1193 | + |
|
1194 | + if ( false !== $count ) { |
|
1195 | + return $count; |
|
1196 | + } |
|
1197 | + |
|
1198 | + $statuses = array( '' ); // Default to the WP normal comments |
|
1199 | + $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A ); |
|
1200 | + foreach ( (array) $stati AS $status ) { |
|
1201 | + if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) { |
|
1202 | + $statuses[] = $status['comment_type']; |
|
1203 | + } |
|
1204 | + } |
|
1205 | + $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
|
1206 | + |
|
1207 | + if ( $post_id > 0 ) |
|
1208 | + $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
1209 | + |
|
1210 | + $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
1211 | + |
|
1212 | + $total = 0; |
|
1213 | + $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
|
1214 | + foreach ( (array) $count as $row ) { |
|
1215 | + // Don't count post-trashed toward totals |
|
1216 | + if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
1217 | + $total += $row['num_comments']; |
|
1218 | + if ( isset( $approved[$row['comment_approved']] ) ) |
|
1219 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
1220 | + } |
|
1221 | + |
|
1222 | + $stats['total_comments'] = $total; |
|
1223 | + foreach ( $approved as $key ) { |
|
1224 | + if ( empty($stats[$key]) ) |
|
1225 | + $stats[$key] = 0; |
|
1226 | + } |
|
1227 | + |
|
1228 | + $stats = (object) $stats; |
|
1229 | + wp_cache_set("comments-{$post_id}", $stats, 'counts'); |
|
1230 | + |
|
1231 | + return $stats; |
|
1232 | + } |
|
1233 | + |
|
1234 | + /** |
|
1235 | + * Init images. |
|
1236 | + * |
|
1237 | + * @since 1.4.5 |
|
1238 | + * @access public |
|
1239 | + * @return void |
|
1240 | + */ |
|
1241 | + public function init_image_sizes() { |
|
1242 | + $course_archive_thumbnail = $this->get_image_size( 'course_archive_image' ); |
|
1243 | + $course_single_thumbnail = $this->get_image_size( 'course_single_image' ); |
|
1244 | + $lesson_archive_thumbnail = $this->get_image_size( 'lesson_archive_image' ); |
|
1245 | + $lesson_single_thumbnail = $this->get_image_size( 'lesson_single_image' ); |
|
1246 | + |
|
1247 | + add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] ); |
|
1248 | + add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] ); |
|
1249 | + add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] ); |
|
1250 | + add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] ); |
|
1251 | + } |
|
1252 | + |
|
1253 | + /** |
|
1254 | + * Get an image size. |
|
1255 | + * |
|
1256 | + * Variable is filtered by sensei_get_image_size_{image_size} |
|
1257 | + * |
|
1258 | + * @since 1.4.5 |
|
1259 | + * @access public |
|
1260 | + * @param mixed $image_size |
|
1261 | + * @return string |
|
1262 | + */ |
|
1263 | + public function get_image_size( $image_size ) { |
|
1264 | + |
|
1265 | + // Only return sizes we define in settings |
|
1266 | + if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
1267 | + return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
1268 | + |
|
1269 | + if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
|
1270 | + $this->settings->settings[ $image_size . '_width' ] = false; |
|
1271 | + } |
|
1272 | + if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) { |
|
1273 | + $this->settings->settings[ $image_size . '_height' ] = false; |
|
1274 | + } |
|
1275 | + if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) { |
|
1276 | + $this->settings->settings[ $image_size . '_hard_crop' ] = false; |
|
1277 | + } |
|
1278 | + |
|
1279 | + $size = array_filter( array( |
|
1280 | + 'width' => $this->settings->settings[ $image_size . '_width' ], |
|
1281 | + 'height' => $this->settings->settings[ $image_size . '_height' ], |
|
1282 | + 'crop' => $this->settings->settings[ $image_size . '_hard_crop' ] |
|
1283 | + ) ); |
|
1284 | + |
|
1285 | + $size['width'] = isset( $size['width'] ) ? $size['width'] : '100'; |
|
1286 | + $size['height'] = isset( $size['height'] ) ? $size['height'] : '100'; |
|
1287 | + $size['crop'] = isset( $size['crop'] ) ? $size['crop'] : 0; |
|
1288 | + |
|
1289 | + return apply_filters( 'sensei_get_image_size_' . $image_size, $size ); |
|
1290 | + } |
|
1291 | + |
|
1292 | + public function body_class( $classes ) { |
|
1293 | + if( is_sensei() ) { |
|
1294 | + $classes[] = 'sensei'; |
|
1295 | + } |
|
1296 | + return $classes; |
|
1297 | + } |
|
1298 | + |
|
1299 | + /** |
|
1300 | + * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers |
|
1301 | + * |
|
1302 | + * @return null |
|
1303 | + * @since 1.7.0 |
|
1304 | + */ |
|
1305 | + public function jetpack_latex_support() { |
|
1306 | + if ( function_exists( 'latex_markup') ) { |
|
1307 | + add_filter( 'sensei_question_title', 'latex_markup' ); |
|
1308 | + add_filter( 'sensei_answer_text', 'latex_markup' ); |
|
1309 | + } |
|
1310 | + } |
|
1311 | + |
|
1312 | + /** |
|
1313 | + * Load the module functionality. |
|
1314 | + * |
|
1315 | + * This function is hooked into plugins_loaded to avoid conflicts with |
|
1316 | + * the retired modules extension. |
|
1317 | + * |
|
1318 | + * @since 1.8.0 |
|
1319 | + */ |
|
1320 | + public function load_modules_class(){ |
|
1321 | + global $sensei_modules; |
|
1322 | + |
|
1323 | + if( !class_exists( 'Sensei_Modules' ) |
|
1324 | + && 'Sensei_Modules' != get_class( $sensei_modules ) ) { |
|
1325 | + |
|
1326 | + //Load the modules class |
|
1327 | + require_once( 'class-sensei-modules.php'); |
|
1328 | + Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
|
1329 | + |
|
1330 | + }else{ |
|
1331 | + // fallback for people still using the modules extension. |
|
1332 | + global $sensei_modules; |
|
1333 | + Sensei()->modules = $sensei_modules; |
|
1334 | + add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 ); |
|
1335 | + } |
|
1336 | + } |
|
1337 | + |
|
1338 | + /** |
|
1339 | + * Tell the user to that the modules extension is no longer needed. |
|
1340 | + * |
|
1341 | + * @since 1.8.0 |
|
1342 | + */ |
|
1343 | + public function disable_sensei_modules_extension(){ ?> |
|
1344 | 1344 | <div class="notice updated fade"> |
1345 | 1345 | <p> |
1346 | 1346 | <?php |
1347 | - $plugin_manage_url = admin_url().'plugins.php#sensei-modules'; |
|
1348 | - $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> '; |
|
1349 | - ?> |
|
1347 | + $plugin_manage_url = admin_url().'plugins.php#sensei-modules'; |
|
1348 | + $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> '; |
|
1349 | + ?> |
|
1350 | 1350 | <strong> Modules are now included in Sensei,</strong> so you no longer need the Sensei Modules extension. |
1351 | 1351 | Please deactivate and delete it from your <?php echo $plugin_link_element; ?>. (This will not affect your existing modules). |
1352 | 1352 | </p> |
@@ -1354,46 +1354,46 @@ discard block |
||
1354 | 1354 | |
1355 | 1355 | <?php }// end function |
1356 | 1356 | |
1357 | - /** |
|
1358 | - * Sensei wide rewrite flush call. |
|
1359 | - * |
|
1360 | - * To use this simply update the option 'sensei_flush_rewrite_rules' to 1 |
|
1361 | - * |
|
1362 | - * After the option is one the Rules will be flushed. |
|
1363 | - * |
|
1364 | - * @since 1.9.0 |
|
1365 | - */ |
|
1366 | - public function flush_rewrite_rules(){ |
|
1357 | + /** |
|
1358 | + * Sensei wide rewrite flush call. |
|
1359 | + * |
|
1360 | + * To use this simply update the option 'sensei_flush_rewrite_rules' to 1 |
|
1361 | + * |
|
1362 | + * After the option is one the Rules will be flushed. |
|
1363 | + * |
|
1364 | + * @since 1.9.0 |
|
1365 | + */ |
|
1366 | + public function flush_rewrite_rules(){ |
|
1367 | 1367 | |
1368 | - // ensures that the rewrite rules are flushed on the second |
|
1369 | - // attempt. This ensure that the settings for any other process |
|
1370 | - // have been completed and saved to the database before we refresh the |
|
1371 | - // rewrite rules. |
|
1372 | - $option = get_option('sensei_flush_rewrite_rules'); |
|
1373 | - if( '1' == $option ) { |
|
1368 | + // ensures that the rewrite rules are flushed on the second |
|
1369 | + // attempt. This ensure that the settings for any other process |
|
1370 | + // have been completed and saved to the database before we refresh the |
|
1371 | + // rewrite rules. |
|
1372 | + $option = get_option('sensei_flush_rewrite_rules'); |
|
1373 | + if( '1' == $option ) { |
|
1374 | 1374 | |
1375 | - update_option('sensei_flush_rewrite_rules', '2'); |
|
1375 | + update_option('sensei_flush_rewrite_rules', '2'); |
|
1376 | 1376 | |
1377 | - }elseif( '2' == $option ) { |
|
1377 | + }elseif( '2' == $option ) { |
|
1378 | 1378 | |
1379 | - flush_rewrite_rules(); |
|
1380 | - update_option('sensei_flush_rewrite_rules', '0'); |
|
1379 | + flush_rewrite_rules(); |
|
1380 | + update_option('sensei_flush_rewrite_rules', '0'); |
|
1381 | 1381 | |
1382 | - } |
|
1382 | + } |
|
1383 | 1383 | |
1384 | - } // end flush_rewrite_rules |
|
1384 | + } // end flush_rewrite_rules |
|
1385 | 1385 | |
1386 | - /** |
|
1387 | - * Calling this function will tell Sensei to flush rewrite |
|
1388 | - * rules on the next load. |
|
1389 | - * |
|
1390 | - * @since 1.9.0 |
|
1391 | - */ |
|
1392 | - public function initiate_rewrite_rules_flush(){ |
|
1386 | + /** |
|
1387 | + * Calling this function will tell Sensei to flush rewrite |
|
1388 | + * rules on the next load. |
|
1389 | + * |
|
1390 | + * @since 1.9.0 |
|
1391 | + */ |
|
1392 | + public function initiate_rewrite_rules_flush(){ |
|
1393 | 1393 | |
1394 | - update_option('sensei_flush_rewrite_rules', '1'); |
|
1394 | + update_option('sensei_flush_rewrite_rules', '1'); |
|
1395 | 1395 | |
1396 | - } |
|
1396 | + } |
|
1397 | 1397 | |
1398 | 1398 | } // End Class |
1399 | 1399 |
@@ -19,63 +19,63 @@ discard block |
||
19 | 19 | * @since 1.0.0 |
20 | 20 | */ |
21 | 21 | public function __construct () { |
22 | - parent::__construct(); // Required in extended classes. |
|
22 | + parent::__construct(); // Required in extended classes. |
|
23 | 23 | |
24 | - $this->token = 'woothemes-sensei-settings'; |
|
25 | - add_action('init', array( __CLASS__, 'flush_rewrite_rules' ) ); |
|
24 | + $this->token = 'woothemes-sensei-settings'; |
|
25 | + add_action('init', array( __CLASS__, 'flush_rewrite_rules' ) ); |
|
26 | 26 | |
27 | - // Setup Admin Settings data |
|
28 | - if ( is_admin() ) { |
|
27 | + // Setup Admin Settings data |
|
28 | + if ( is_admin() ) { |
|
29 | 29 | |
30 | - $this->has_tabs = true; |
|
31 | - $this->name = __( 'Sensei Settings', 'woothemes-sensei' ); |
|
32 | - $this->menu_label = __( 'Settings', 'woothemes-sensei' ); |
|
33 | - $this->page_slug = 'woothemes-sensei-settings'; |
|
30 | + $this->has_tabs = true; |
|
31 | + $this->name = __( 'Sensei Settings', 'woothemes-sensei' ); |
|
32 | + $this->menu_label = __( 'Settings', 'woothemes-sensei' ); |
|
33 | + $this->page_slug = 'woothemes-sensei-settings'; |
|
34 | 34 | |
35 | - } // End If Statement |
|
35 | + } // End If Statement |
|
36 | 36 | |
37 | - $this->register_hook_listener(); |
|
38 | - $this->get_settings(); |
|
37 | + $this->register_hook_listener(); |
|
38 | + $this->get_settings(); |
|
39 | 39 | |
40 | 40 | } // End __construct() |
41 | 41 | |
42 | - /** |
|
43 | - * Get settings value |
|
44 | - * |
|
45 | - * @since 1.9.0 |
|
46 | - * @param string $setting_name |
|
47 | - * @return mixed |
|
48 | - */ |
|
49 | - public function get( $setting_name ){ |
|
42 | + /** |
|
43 | + * Get settings value |
|
44 | + * |
|
45 | + * @since 1.9.0 |
|
46 | + * @param string $setting_name |
|
47 | + * @return mixed |
|
48 | + */ |
|
49 | + public function get( $setting_name ){ |
|
50 | 50 | |
51 | - if( isset( $this->settings[ $setting_name ] ) ){ |
|
51 | + if( isset( $this->settings[ $setting_name ] ) ){ |
|
52 | 52 | |
53 | - return $this->settings[ $setting_name ]; |
|
53 | + return $this->settings[ $setting_name ]; |
|
54 | 54 | |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | - return false; |
|
58 | - } |
|
57 | + return false; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @since 1.9.0 |
|
62 | - * |
|
63 | - * @param $setting |
|
64 | - * @param $new_value |
|
65 | - */ |
|
66 | - public function set( $setting, $new_value ){ |
|
60 | + /** |
|
61 | + * @since 1.9.0 |
|
62 | + * |
|
63 | + * @param $setting |
|
64 | + * @param $new_value |
|
65 | + */ |
|
66 | + public function set( $setting, $new_value ){ |
|
67 | 67 | |
68 | - $settings = get_option( $this->token, array() ); |
|
68 | + $settings = get_option( $this->token, array() ); |
|
69 | 69 | |
70 | - if( isset( $settings[ $setting ] ) ){ |
|
70 | + if( isset( $settings[ $setting ] ) ){ |
|
71 | 71 | |
72 | - $settings[ $setting ] = $new_value; |
|
73 | - return update_option( $this->token,$settings ); |
|
72 | + $settings[ $setting ] = $new_value; |
|
73 | + return update_option( $this->token,$settings ); |
|
74 | 74 | |
75 | - } |
|
76 | - return false; |
|
75 | + } |
|
76 | + return false; |
|
77 | 77 | |
78 | - } |
|
78 | + } |
|
79 | 79 | |
80 | 80 | /** |
81 | 81 | * Register the settings screen within the WordPress admin. |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | $complete_settings = array( 'passed' => __( 'Once all the course lessons have been completed', 'woothemes-sensei' ), 'complete' => __( 'At any time (by clicking the \'Complete Course\' button)', 'woothemes-sensei' ) ); |
164 | 164 | $course_display_settings = array( 'excerpt' => __( 'Course Excerpt', 'woothemes-sensei' ), 'full' => __( 'Full Course Content', 'woothemes-sensei' ) ); |
165 | 165 | |
166 | - $fields = array(); |
|
166 | + $fields = array(); |
|
167 | 167 | |
168 | 168 | $fields['access_permission'] = array( |
169 | 169 | 'name' => __( 'Access Permissions', 'woothemes-sensei' ), |
@@ -225,9 +225,9 @@ discard block |
||
225 | 225 | 'section' => 'default-settings' |
226 | 226 | ); |
227 | 227 | |
228 | - // Course Settings |
|
228 | + // Course Settings |
|
229 | 229 | |
230 | - $fields['course_completion'] = array( |
|
230 | + $fields['course_completion'] = array( |
|
231 | 231 | 'name' => __( 'Courses are complete:', 'woothemes-sensei' ), |
232 | 232 | 'description' => __( 'This will determine when courses are marked as complete.', 'woothemes-sensei' ), |
233 | 233 | 'type' => 'select', |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | 'options' => $complete_settings |
238 | 238 | ); |
239 | 239 | |
240 | - $fields['course_author'] = array( |
|
240 | + $fields['course_author'] = array( |
|
241 | 241 | 'name' => __( 'Display Course Author', 'woothemes-sensei' ), |
242 | 242 | 'description' => __( 'Output the Course Author on Course archive and My Courses page.', 'woothemes-sensei' ), |
243 | 243 | 'type' => 'checkbox', |
@@ -465,10 +465,10 @@ discard block |
||
465 | 465 | ); |
466 | 466 | |
467 | 467 | $teacher_email_options = array( |
468 | - 'teacher-started-course' => __( 'A learner starts their course', 'woothemes-sensei' ), |
|
469 | - 'teacher-completed-course' => __( 'A learner completes their course', 'woothemes-sensei' ), |
|
470 | - 'teacher-completed-lesson' => __( 'A learner completes a lesson', 'woothemes-sensei' ), |
|
471 | - 'teacher-quiz-submitted' => __( 'A learner submits a quiz for grading', 'woothemes-sensei' ), |
|
468 | + 'teacher-started-course' => __( 'A learner starts their course', 'woothemes-sensei' ), |
|
469 | + 'teacher-completed-course' => __( 'A learner completes their course', 'woothemes-sensei' ), |
|
470 | + 'teacher-completed-lesson' => __( 'A learner completes a lesson', 'woothemes-sensei' ), |
|
471 | + 'teacher-quiz-submitted' => __( 'A learner submits a quiz for grading', 'woothemes-sensei' ), |
|
472 | 472 | 'teacher-new-message' => __( 'A learner sends a private message to a teacher', 'woothemes-sensei' ), |
473 | 473 | ); |
474 | 474 | |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | |
578 | 578 | if ( Sensei_WC::is_woocommerce_present() ) { |
579 | 579 | // WooCommerce Settings |
580 | - $fields['woocommerce_enabled'] = array( |
|
580 | + $fields['woocommerce_enabled'] = array( |
|
581 | 581 | 'name' => __( 'Enable WooCommerce Courses', 'woothemes-sensei' ), |
582 | 582 | 'description' => __( 'Use WooCommerce to sell Courses by linking a Product to a Course.', 'woothemes-sensei' ), |
583 | 583 | 'type' => 'checkbox', |
@@ -665,14 +665,14 @@ discard block |
||
665 | 665 | $page_items[] = __( 'Select a Page:', 'woothemes-sensei' ); |
666 | 666 | |
667 | 667 | foreach ( $pages_split as $k => $v ) { |
668 | - $id = ''; |
|
669 | - // Get the ID value. |
|
670 | - preg_match( '/value="(.*?)"/i', $v, $matches ); |
|
671 | - |
|
672 | - if ( isset( $matches[1] ) ) { |
|
673 | - $id = $matches[1]; |
|
674 | - $page_items[$id] = trim( strip_tags( $v ) ); |
|
675 | - } // End If Statement |
|
668 | + $id = ''; |
|
669 | + // Get the ID value. |
|
670 | + preg_match( '/value="(.*?)"/i', $v, $matches ); |
|
671 | + |
|
672 | + if ( isset( $matches[1] ) ) { |
|
673 | + $id = $matches[1]; |
|
674 | + $page_items[$id] = trim( strip_tags( $v ) ); |
|
675 | + } // End If Statement |
|
676 | 676 | } // End For Loop |
677 | 677 | |
678 | 678 | $pages_array = $page_items; |
@@ -689,22 +689,22 @@ discard block |
||
689 | 689 | Sensei_Language_Pack_Manager::messages(); |
690 | 690 | } |
691 | 691 | |
692 | - /** |
|
693 | - * Flush the rewrite rules after the settings have been updated. |
|
694 | - * This is to ensure that the |
|
695 | - * |
|
696 | - * @since 1.9.0 |
|
697 | - */ |
|
698 | - public static function flush_rewrite_rules(){ |
|
692 | + /** |
|
693 | + * Flush the rewrite rules after the settings have been updated. |
|
694 | + * This is to ensure that the |
|
695 | + * |
|
696 | + * @since 1.9.0 |
|
697 | + */ |
|
698 | + public static function flush_rewrite_rules(){ |
|
699 | 699 | |
700 | - if ( isset( $_POST[ 'option_page' ] ) && 'woothemes-sensei-settings' == $_POST[ 'option_page' ] |
|
701 | - && isset( $_POST[ 'action' ] ) && 'update' == $_POST[ 'action' ] ) { |
|
700 | + if ( isset( $_POST[ 'option_page' ] ) && 'woothemes-sensei-settings' == $_POST[ 'option_page' ] |
|
701 | + && isset( $_POST[ 'action' ] ) && 'update' == $_POST[ 'action' ] ) { |
|
702 | 702 | |
703 | - Sensei()->initiate_rewrite_rules_flush(); |
|
703 | + Sensei()->initiate_rewrite_rules_flush(); |
|
704 | 704 | |
705 | - } |
|
705 | + } |
|
706 | 706 | |
707 | - }//end flush_cache |
|
707 | + }//end flush_cache |
|
708 | 708 | } // End Class |
709 | 709 | |
710 | 710 | /** |
@@ -25,8 +25,8 @@ discard block |
||
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Check if WooCommerce is present. |
28 | - * |
|
29 | - * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_present() |
|
28 | + * |
|
29 | + * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_present() |
|
30 | 30 | * @access public |
31 | 31 | * @since 1.0.2 |
32 | 32 | * @static |
@@ -34,14 +34,14 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public static function sensei_is_woocommerce_present () { |
36 | 36 | |
37 | - return Sensei_WC::is_woocommerce_present(); |
|
37 | + return Sensei_WC::is_woocommerce_present(); |
|
38 | 38 | |
39 | 39 | } // End sensei_is_woocommerce_present() |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Check if WooCommerce is active. |
43 | - * |
|
44 | - * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_active |
|
43 | + * |
|
44 | + * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_active |
|
45 | 45 | * @access public |
46 | 46 | * @since 1.0.2 |
47 | 47 | * @static |
@@ -186,15 +186,15 @@ discard block |
||
186 | 186 | add_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
187 | 187 | } |
188 | 188 | |
189 | - //Get the comments |
|
190 | - /** |
|
191 | - * This filter runs inside Sensei_Utils::sensei_check_for_activity |
|
192 | - * |
|
193 | - * It runs while getting the comments for the given request. |
|
194 | - * |
|
195 | - * @param int|array $comments |
|
196 | - */ |
|
197 | - $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) ); |
|
189 | + //Get the comments |
|
190 | + /** |
|
191 | + * This filter runs inside Sensei_Utils::sensei_check_for_activity |
|
192 | + * |
|
193 | + * It runs while getting the comments for the given request. |
|
194 | + * |
|
195 | + * @param int|array $comments |
|
196 | + */ |
|
197 | + $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) ); |
|
198 | 198 | |
199 | 199 | remove_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) ); |
200 | 200 | remove_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) ); |
@@ -279,18 +279,18 @@ discard block |
||
279 | 279 | return $dataset_changes; |
280 | 280 | } // End sensei_delete_activities() |
281 | 281 | |
282 | - /** |
|
283 | - * Delete all activity for specified user |
|
284 | - * @access public |
|
282 | + /** |
|
283 | + * Delete all activity for specified user |
|
284 | + * @access public |
|
285 | 285 | * @since 1.5.0 |
286 | - * @param integer $user_id User ID |
|
287 | - * @return boolean |
|
288 | - */ |
|
289 | - public static function delete_all_user_activity( $user_id = 0 ) { |
|
286 | + * @param integer $user_id User ID |
|
287 | + * @return boolean |
|
288 | + */ |
|
289 | + public static function delete_all_user_activity( $user_id = 0 ) { |
|
290 | 290 | |
291 | - $dataset_changes = false; |
|
291 | + $dataset_changes = false; |
|
292 | 292 | |
293 | - if( $user_id ) { |
|
293 | + if( $user_id ) { |
|
294 | 294 | |
295 | 295 | $activities = Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $user_id ), true ); |
296 | 296 | |
@@ -335,35 +335,35 @@ discard block |
||
335 | 335 | return $activity_value; |
336 | 336 | } // End sensei_get_activity_value() |
337 | 337 | |
338 | - /** |
|
339 | - * Checks if a user (by email) has bought an item. |
|
340 | - * |
|
341 | - * @deprecated since 1.9.0 use Sensei_WC::has_customer_bought_product($user_id, $product_id) |
|
342 | - * @access public |
|
343 | - * @since 1.0.0 |
|
344 | - * @param string $customer_email |
|
345 | - * @param int $user_id |
|
346 | - * @param int $product_id |
|
347 | - * @return bool |
|
348 | - */ |
|
349 | - public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) { |
|
338 | + /** |
|
339 | + * Checks if a user (by email) has bought an item. |
|
340 | + * |
|
341 | + * @deprecated since 1.9.0 use Sensei_WC::has_customer_bought_product($user_id, $product_id) |
|
342 | + * @access public |
|
343 | + * @since 1.0.0 |
|
344 | + * @param string $customer_email |
|
345 | + * @param int $user_id |
|
346 | + * @param int $product_id |
|
347 | + * @return bool |
|
348 | + */ |
|
349 | + public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) { |
|
350 | 350 | |
351 | - $emails = array(); |
|
351 | + $emails = array(); |
|
352 | 352 | |
353 | - if ( $user_id ) { |
|
354 | - $user = get_user_by( 'id', intval( $user_id ) ); |
|
355 | - $emails[] = $user->user_email; |
|
356 | - } |
|
353 | + if ( $user_id ) { |
|
354 | + $user = get_user_by( 'id', intval( $user_id ) ); |
|
355 | + $emails[] = $user->user_email; |
|
356 | + } |
|
357 | 357 | |
358 | - if ( is_email( $customer_email ) ) |
|
359 | - $emails[] = $customer_email; |
|
358 | + if ( is_email( $customer_email ) ) |
|
359 | + $emails[] = $customer_email; |
|
360 | 360 | |
361 | - if ( sizeof( $emails ) == 0 ) |
|
362 | - return false; |
|
361 | + if ( sizeof( $emails ) == 0 ) |
|
362 | + return false; |
|
363 | 363 | |
364 | - return Sensei_WC::has_customer_bought_product( $user_id, $product_id ); |
|
364 | + return Sensei_WC::has_customer_bought_product( $user_id, $product_id ); |
|
365 | 365 | |
366 | - } // End sensei_customer_bought_product() |
|
366 | + } // End sensei_customer_bought_product() |
|
367 | 367 | |
368 | 368 | /** |
369 | 369 | * Load the WordPress rich text editor |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | /** |
400 | 400 | * Save quiz answers submitted by users |
401 | 401 | * @param array $submitted User's quiz answers |
402 | - * @param int $user_id |
|
402 | + * @param int $user_id |
|
403 | 403 | * @return boolean Whether the answers were saved or not |
404 | 404 | */ |
405 | 405 | public static function sensei_save_quiz_answers( $submitted = array(), $user_id = 0 ) { |
@@ -468,72 +468,72 @@ discard block |
||
468 | 468 | |
469 | 469 | require_once( ABSPATH . 'wp-admin/includes/admin.php' ); |
470 | 470 | |
471 | - /** |
|
472 | - * Filter the data array for the Sensei wp_handle_upload function call |
|
473 | - * |
|
474 | - * This filter was mainly added for Unit Testing purposes. |
|
475 | - * |
|
476 | - * @since 1.7.4 |
|
477 | - * |
|
478 | - * @param array $file_upload_args { |
|
479 | - * array of current values |
|
480 | - * |
|
481 | - * @type string test_form set to false by default |
|
482 | - * } |
|
483 | - */ |
|
484 | - $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) ); |
|
485 | - |
|
486 | - $file_return = wp_handle_upload( $file, $file_upload_args ); |
|
487 | - |
|
488 | - if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) { |
|
489 | - return false; |
|
490 | - } else { |
|
471 | + /** |
|
472 | + * Filter the data array for the Sensei wp_handle_upload function call |
|
473 | + * |
|
474 | + * This filter was mainly added for Unit Testing purposes. |
|
475 | + * |
|
476 | + * @since 1.7.4 |
|
477 | + * |
|
478 | + * @param array $file_upload_args { |
|
479 | + * array of current values |
|
480 | + * |
|
481 | + * @type string test_form set to false by default |
|
482 | + * } |
|
483 | + */ |
|
484 | + $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) ); |
|
485 | + |
|
486 | + $file_return = wp_handle_upload( $file, $file_upload_args ); |
|
487 | + |
|
488 | + if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) { |
|
489 | + return false; |
|
490 | + } else { |
|
491 | 491 | |
492 | - $filename = $file_return['file']; |
|
492 | + $filename = $file_return['file']; |
|
493 | 493 | |
494 | - $attachment = array( |
|
495 | - 'post_mime_type' => $file_return['type'], |
|
496 | - 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
497 | - 'post_content' => '', |
|
498 | - 'post_status' => 'inherit', |
|
499 | - 'guid' => $file_return['url'] |
|
500 | - ); |
|
494 | + $attachment = array( |
|
495 | + 'post_mime_type' => $file_return['type'], |
|
496 | + 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ), |
|
497 | + 'post_content' => '', |
|
498 | + 'post_status' => 'inherit', |
|
499 | + 'guid' => $file_return['url'] |
|
500 | + ); |
|
501 | 501 | |
502 | - $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
502 | + $attachment_id = wp_insert_attachment( $attachment, $filename ); |
|
503 | 503 | |
504 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
505 | - $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
506 | - wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
504 | + require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
505 | + $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename ); |
|
506 | + wp_update_attachment_metadata( $attachment_id, $attachment_data ); |
|
507 | 507 | |
508 | - if( 0 < intval( $attachment_id ) ) { |
|
509 | - return $attachment_id; |
|
510 | - } |
|
511 | - } |
|
508 | + if( 0 < intval( $attachment_id ) ) { |
|
509 | + return $attachment_id; |
|
510 | + } |
|
511 | + } |
|
512 | 512 | |
513 | - return false; |
|
513 | + return false; |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | /** |
517 | 517 | * Grade quiz automatically |
518 | - * |
|
519 | - * This function grades each question automatically if the are auto gradable. |
|
520 | - * It store all question grades. |
|
521 | - * |
|
522 | - * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_quiz_auto instead |
|
523 | - * |
|
518 | + * |
|
519 | + * This function grades each question automatically if the are auto gradable. |
|
520 | + * It store all question grades. |
|
521 | + * |
|
522 | + * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_quiz_auto instead |
|
523 | + * |
|
524 | 524 | * @param integer $quiz_id ID of quiz |
525 | 525 | * @param array $submitted questions id ans answers { |
526 | - * @type int $question_id |
|
527 | - * @type mixed $answer |
|
528 | - * } |
|
526 | + * @type int $question_id |
|
527 | + * @type mixed $answer |
|
528 | + * } |
|
529 | 529 | * @param integer $total_questions Total questions in quiz (not used) |
530 | - * @param string $quiz_grade_type Optional defaults to auto |
|
531 | - * |
|
530 | + * @param string $quiz_grade_type Optional defaults to auto |
|
531 | + * |
|
532 | 532 | * @return int $quiz_grade total sum of all question grades |
533 | 533 | */ |
534 | 534 | public static function sensei_grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) { |
535 | 535 | |
536 | - return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type ); |
|
536 | + return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type ); |
|
537 | 537 | |
538 | 538 | } // End sensei_grade_quiz_auto() |
539 | 539 | |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | * @param integer $quiz_id ID of quiz |
543 | 543 | * @param integer $grade Grade received |
544 | 544 | * @param integer $user_id ID of user being graded |
545 | - * @param string $quiz_grade_type default 'auto' |
|
545 | + * @param string $quiz_grade_type default 'auto' |
|
546 | 546 | * @return boolean |
547 | 547 | */ |
548 | 548 | public static function sensei_grade_quiz( $quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto' ) { |
@@ -566,21 +566,21 @@ discard block |
||
566 | 566 | |
567 | 567 | /** |
568 | 568 | * Grade question automatically |
569 | - * |
|
570 | - * This function checks the question typ and then grades it accordingly. |
|
571 | - * |
|
572 | - * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_question_auto instead |
|
573 | - * |
|
569 | + * |
|
570 | + * This function checks the question typ and then grades it accordingly. |
|
571 | + * |
|
572 | + * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_question_auto instead |
|
573 | + * |
|
574 | 574 | * @param integer $question_id |
575 | - * @param string $question_type of the standard Sensei question types |
|
575 | + * @param string $question_type of the standard Sensei question types |
|
576 | 576 | * @param string $answer |
577 | - * @param int $user_id |
|
578 | - * |
|
577 | + * @param int $user_id |
|
578 | + * |
|
579 | 579 | * @return int $question_grade |
580 | 580 | */ |
581 | 581 | public static function sensei_grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) { |
582 | 582 | |
583 | - return WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
583 | + return WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id ); |
|
584 | 584 | |
585 | 585 | } // end sensei_grade_question_auto |
586 | 586 | |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | * Grade question |
589 | 589 | * @param integer $question_id ID of question |
590 | 590 | * @param integer $grade Grade received |
591 | - * @param int $user_id |
|
591 | + * @param int $user_id |
|
592 | 592 | * @return boolean |
593 | 593 | */ |
594 | 594 | public static function sensei_grade_question( $question_id = 0, $grade = 0, $user_id = 0 ) { |
@@ -627,35 +627,35 @@ discard block |
||
627 | 627 | } |
628 | 628 | |
629 | 629 | |
630 | - /** |
|
631 | - * Alias to Woothemes_Sensei_Utils::sensei_start_lesson |
|
632 | - * |
|
633 | - * @since 1.7.4 |
|
634 | - * |
|
635 | - * @param integer $user_id |
|
636 | - * @param integer $lesson_id |
|
637 | - * @param bool $complete |
|
638 | - * |
|
639 | - * @return mixed boolean or comment_ID |
|
640 | - */ |
|
641 | - public static function user_start_lesson( $user_id = 0, $lesson_id = 0, $complete = false ) { |
|
630 | + /** |
|
631 | + * Alias to Woothemes_Sensei_Utils::sensei_start_lesson |
|
632 | + * |
|
633 | + * @since 1.7.4 |
|
634 | + * |
|
635 | + * @param integer $user_id |
|
636 | + * @param integer $lesson_id |
|
637 | + * @param bool $complete |
|
638 | + * |
|
639 | + * @return mixed boolean or comment_ID |
|
640 | + */ |
|
641 | + public static function user_start_lesson( $user_id = 0, $lesson_id = 0, $complete = false ) { |
|
642 | 642 | |
643 | - return self::sensei_start_lesson( $lesson_id, $user_id, $complete ); |
|
643 | + return self::sensei_start_lesson( $lesson_id, $user_id, $complete ); |
|
644 | 644 | |
645 | - }// end user_start_lesson() |
|
645 | + }// end user_start_lesson() |
|
646 | 646 | |
647 | 647 | /** |
648 | 648 | * Mark a lesson as started for user |
649 | - * |
|
650 | - * Will also start the lesson course for the user if the user hans't started taking it already. |
|
651 | - * |
|
652 | - * @since 1.6.0 |
|
653 | - * |
|
649 | + * |
|
650 | + * Will also start the lesson course for the user if the user hans't started taking it already. |
|
651 | + * |
|
652 | + * @since 1.6.0 |
|
653 | + * |
|
654 | 654 | * @param integer $lesson_id ID of lesson |
655 | 655 | * @param int| string $user_id default 0 |
656 | - * @param bool $complete default false |
|
657 | - * |
|
658 | - * @return mixed boolean or comment_ID |
|
656 | + * @param bool $complete default false |
|
657 | + * |
|
658 | + * @return mixed boolean or comment_ID |
|
659 | 659 | */ |
660 | 660 | public static function sensei_start_lesson( $lesson_id = 0, $user_id = 0, $complete = false ) { |
661 | 661 | |
@@ -701,21 +701,21 @@ discard block |
||
701 | 701 | $metadata['start'] = current_time('mysql'); |
702 | 702 | $activity_logged = Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $status, $metadata ); |
703 | 703 | |
704 | - } else { |
|
704 | + } else { |
|
705 | 705 | |
706 | - // if users is already taking the lesson and the status changes to complete update it |
|
707 | - $current_user_activity = get_comment($activity_logged); |
|
708 | - if( $status=='complete' && |
|
709 | - $status != $current_user_activity->comment_approved ){ |
|
706 | + // if users is already taking the lesson and the status changes to complete update it |
|
707 | + $current_user_activity = get_comment($activity_logged); |
|
708 | + if( $status=='complete' && |
|
709 | + $status != $current_user_activity->comment_approved ){ |
|
710 | 710 | |
711 | - $comment = array(); |
|
712 | - $comment['comment_ID'] = $activity_logged; |
|
713 | - $comment['comment_approved'] = $status; |
|
714 | - wp_update_comment( $comment ); |
|
711 | + $comment = array(); |
|
712 | + $comment['comment_ID'] = $activity_logged; |
|
713 | + $comment['comment_approved'] = $status; |
|
714 | + wp_update_comment( $comment ); |
|
715 | 715 | |
716 | - } |
|
716 | + } |
|
717 | 717 | |
718 | - } |
|
718 | + } |
|
719 | 719 | |
720 | 720 | if ( $complete ) { |
721 | 721 | // Run this *after* the lesson status has been created/updated |
@@ -861,7 +861,7 @@ discard block |
||
861 | 861 | /** |
862 | 862 | * Returns the answer_notes for a specific question and user, or sensei_user_answer entry |
863 | 863 | * |
864 | - * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead |
|
864 | + * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead |
|
865 | 865 | * @param mixed $question |
866 | 866 | * @param int $user_id |
867 | 867 | * @return string |
@@ -921,7 +921,7 @@ discard block |
||
921 | 921 | * Add answer notes to question |
922 | 922 | * @param integer $question_id ID of question |
923 | 923 | * @param integer $user_id ID of user |
924 | - * @param string $notes |
|
924 | + * @param string $notes |
|
925 | 925 | * @return boolean |
926 | 926 | */ |
927 | 927 | public static function sensei_add_answer_notes( $question_id = 0, $user_id = 0, $notes = '' ) { |
@@ -979,17 +979,17 @@ discard block |
||
979 | 979 | * @return void |
980 | 980 | */ |
981 | 981 | public static function sort_array_by_key( $array, $key ) { |
982 | - $sorter = array(); |
|
983 | - $ret = array(); |
|
984 | - reset( $array ); |
|
985 | - foreach ( $array as $ii => $va ) { |
|
986 | - $sorter[$ii] = $va[$key]; |
|
987 | - } // End For Loop |
|
988 | - asort( $sorter ); |
|
989 | - foreach ( $sorter as $ii => $va ) { |
|
990 | - $ret[$ii] = $array[$ii]; |
|
991 | - } // End For Loop |
|
992 | - $array = $ret; |
|
982 | + $sorter = array(); |
|
983 | + $ret = array(); |
|
984 | + reset( $array ); |
|
985 | + foreach ( $array as $ii => $va ) { |
|
986 | + $sorter[$ii] = $va[$key]; |
|
987 | + } // End For Loop |
|
988 | + asort( $sorter ); |
|
989 | + foreach ( $sorter as $ii => $va ) { |
|
990 | + $ret[$ii] = $array[$ii]; |
|
991 | + } // End For Loop |
|
992 | + $array = $ret; |
|
993 | 993 | } // End sort_array_by_key() |
994 | 994 | |
995 | 995 | /** |
@@ -1002,21 +1002,21 @@ discard block |
||
1002 | 1002 | $questions_array = array(); |
1003 | 1003 | if ( 0 < $quiz_id ) { |
1004 | 1004 | $question_args = array( 'post_type' => 'question', |
1005 | - 'posts_per_page' => -1, |
|
1006 | - 'orderby' => 'ID', |
|
1007 | - 'order' => 'ASC', |
|
1008 | - 'meta_query' => array( |
|
1005 | + 'posts_per_page' => -1, |
|
1006 | + 'orderby' => 'ID', |
|
1007 | + 'order' => 'ASC', |
|
1008 | + 'meta_query' => array( |
|
1009 | 1009 | array( |
1010 | 1010 | 'key' => '_quiz_id', |
1011 | 1011 | 'value' => $quiz_id, |
1012 | 1012 | ) |
1013 | 1013 | ), |
1014 | - 'post_status' => 'any', |
|
1015 | - 'suppress_filters' => 0 |
|
1016 | - ); |
|
1017 | - $questions_array = get_posts( $question_args ); |
|
1018 | - } // End If Statement |
|
1019 | - return $questions_array; |
|
1014 | + 'post_status' => 'any', |
|
1015 | + 'suppress_filters' => 0 |
|
1016 | + ); |
|
1017 | + $questions_array = get_posts( $question_args ); |
|
1018 | + } // End If Statement |
|
1019 | + return $questions_array; |
|
1020 | 1020 | } // End lesson_quiz_questions() |
1021 | 1021 | |
1022 | 1022 | /** |
@@ -1174,7 +1174,7 @@ discard block |
||
1174 | 1174 | * Set the status message displayed to the user for a quiz |
1175 | 1175 | * @param integer $lesson_id ID of quiz lesson |
1176 | 1176 | * @param integer $user_id ID of user |
1177 | - * @param bool $is_lesson |
|
1177 | + * @param bool $is_lesson |
|
1178 | 1178 | * @return array Status code and message |
1179 | 1179 | */ |
1180 | 1180 | public static function sensei_user_quiz_status_message( $lesson_id = 0, $user_id = 0, $is_lesson = false ) { |
@@ -1257,20 +1257,20 @@ discard block |
||
1257 | 1257 | } |
1258 | 1258 | } |
1259 | 1259 | |
1260 | - // add next lesson button |
|
1261 | - $nav_id_array = sensei_get_prev_next_lessons( $lesson_id ); |
|
1262 | - $next_lesson_id = absint( $nav_id_array['next_lesson'] ); |
|
1260 | + // add next lesson button |
|
1261 | + $nav_id_array = sensei_get_prev_next_lessons( $lesson_id ); |
|
1262 | + $next_lesson_id = absint( $nav_id_array['next_lesson'] ); |
|
1263 | 1263 | |
1264 | - // Output HTML |
|
1265 | - if ( ( 0 < $next_lesson_id ) ) { |
|
1266 | - $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) ) |
|
1267 | - . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei') |
|
1268 | - .'</a>'; |
|
1264 | + // Output HTML |
|
1265 | + if ( ( 0 < $next_lesson_id ) ) { |
|
1266 | + $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) ) |
|
1267 | + . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei') |
|
1268 | + .'</a>'; |
|
1269 | 1269 | |
1270 | - } |
|
1270 | + } |
|
1271 | 1271 | |
1272 | 1272 | } |
1273 | - // Lesson/Quiz not complete |
|
1273 | + // Lesson/Quiz not complete |
|
1274 | 1274 | else { |
1275 | 1275 | // Lesson/Quiz isn't "complete" instead it's ungraded (previously this "state" meant that it *was* complete) |
1276 | 1276 | if ( isset( $user_lesson_status->comment_approved ) && 'ungraded' == $user_lesson_status->comment_approved ) { |
@@ -1310,7 +1310,7 @@ discard block |
||
1310 | 1310 | $message = apply_filters( 'sensei_user_quiz_status_' . $status, $message ); |
1311 | 1311 | |
1312 | 1312 | if( $is_lesson && ! in_array( $status, array( 'login_required', 'not_started_course' ) ) ) { |
1313 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
1313 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id ); |
|
1314 | 1314 | $extra = '<p><a class="button" href="' . esc_url( get_permalink( $quiz_id ) ) . '" title="' . __( 'View the lesson quiz', 'woothemes-sensei' ) . '">' . __( 'View the lesson quiz', 'woothemes-sensei' ) . '</a></p>'; |
1315 | 1315 | } |
1316 | 1316 | |
@@ -1368,9 +1368,9 @@ discard block |
||
1368 | 1368 | $user_id = get_current_user_id(); |
1369 | 1369 | } |
1370 | 1370 | |
1371 | - if( ! $user_id > 0 ){ |
|
1372 | - return false; |
|
1373 | - } |
|
1371 | + if( ! $user_id > 0 ){ |
|
1372 | + return false; |
|
1373 | + } |
|
1374 | 1374 | |
1375 | 1375 | $user_course_status_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status', 'field' => 'comment_ID' ) ); |
1376 | 1376 | if( $user_course_status_id ) { |
@@ -1494,7 +1494,7 @@ discard block |
||
1494 | 1494 | * Check if a user has completed a course or not |
1495 | 1495 | * |
1496 | 1496 | * @param int | WP_Post | WP_Comment $course course_id or sensei_course_status entry |
1497 | - * |
|
1497 | + * |
|
1498 | 1498 | * @param int $user_id |
1499 | 1499 | * @return boolean |
1500 | 1500 | */ |
@@ -1512,14 +1512,14 @@ discard block |
||
1512 | 1512 | $user_id = get_current_user_id(); |
1513 | 1513 | } |
1514 | 1514 | |
1515 | - if( is_a( $course, 'WP_Post' ) ){ |
|
1516 | - $course = $course->ID; |
|
1517 | - } |
|
1515 | + if( is_a( $course, 'WP_Post' ) ){ |
|
1516 | + $course = $course->ID; |
|
1517 | + } |
|
1518 | 1518 | |
1519 | 1519 | $user_course_status = Sensei_Utils::user_course_status( $course , $user_id ); |
1520 | 1520 | if( isset( $user_course_status->comment_approved ) ){ |
1521 | - $user_course_status = $user_course_status->comment_approved; |
|
1522 | - } |
|
1521 | + $user_course_status = $user_course_status->comment_approved; |
|
1522 | + } |
|
1523 | 1523 | |
1524 | 1524 | } |
1525 | 1525 | if( $user_course_status && 'complete' == $user_course_status ) { |
@@ -1544,11 +1544,11 @@ discard block |
||
1544 | 1544 | $user_id = get_current_user_id(); |
1545 | 1545 | } |
1546 | 1546 | |
1547 | - $activity_args = array( |
|
1548 | - 'post_id' => $lesson_id, |
|
1549 | - 'user_id' => $user_id, |
|
1550 | - 'type' => 'sensei_lesson_status', |
|
1551 | - 'field' => 'comment_ID' ); |
|
1547 | + $activity_args = array( |
|
1548 | + 'post_id' => $lesson_id, |
|
1549 | + 'user_id' => $user_id, |
|
1550 | + 'type' => 'sensei_lesson_status', |
|
1551 | + 'field' => 'comment_ID' ); |
|
1552 | 1552 | |
1553 | 1553 | $user_lesson_status_id = Sensei_Utils::sensei_get_activity_value( $activity_args ); |
1554 | 1554 | if( $user_lesson_status_id ) { |
@@ -1561,7 +1561,7 @@ discard block |
||
1561 | 1561 | /** |
1562 | 1562 | * Check if a user has completed a lesson or not |
1563 | 1563 | * |
1564 | - * @uses Sensei() |
|
1564 | + * @uses Sensei() |
|
1565 | 1565 | * @param mixed $lesson lesson_id or sensei_lesson_status entry |
1566 | 1566 | * @param int $user_id |
1567 | 1567 | * @return boolean |
@@ -1582,10 +1582,10 @@ discard block |
||
1582 | 1582 | $user_id = get_current_user_id(); |
1583 | 1583 | } |
1584 | 1584 | |
1585 | - // the user is not logged in |
|
1586 | - if( ! $user_id > 0 ){ |
|
1587 | - return false; |
|
1588 | - } |
|
1585 | + // the user is not logged in |
|
1586 | + if( ! $user_id > 0 ){ |
|
1587 | + return false; |
|
1588 | + } |
|
1589 | 1589 | $_user_lesson_status = Sensei_Utils::user_lesson_status( $lesson, $user_id ); |
1590 | 1590 | |
1591 | 1591 | if ( $_user_lesson_status ) { |
@@ -1664,9 +1664,9 @@ discard block |
||
1664 | 1664 | */ |
1665 | 1665 | public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) { |
1666 | 1666 | |
1667 | - if( ! $user_id ) { |
|
1668 | - $user_id = get_current_user_id(); |
|
1669 | - } |
|
1667 | + if( ! $user_id ) { |
|
1668 | + $user_id = get_current_user_id(); |
|
1669 | + } |
|
1670 | 1670 | |
1671 | 1671 | if( $lesson_id > 0 && $user_id > 0 ) { |
1672 | 1672 | |
@@ -1717,12 +1717,12 @@ discard block |
||
1717 | 1717 | * Sets the status for the lesson |
1718 | 1718 | * |
1719 | 1719 | * @since 1.7.0 |
1720 | - * |
|
1720 | + * |
|
1721 | 1721 | * @param int|string $user_id |
1722 | 1722 | * @param int|string $lesson_id |
1723 | 1723 | * @param string $status |
1724 | 1724 | * @param array $metadata |
1725 | - * |
|
1725 | + * |
|
1726 | 1726 | * @return mixed false or comment_ID |
1727 | 1727 | */ |
1728 | 1728 | public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) { |
@@ -1838,7 +1838,7 @@ discard block |
||
1838 | 1838 | /** |
1839 | 1839 | * Adjust the comment query to be faster on the database, used by Analysis admin |
1840 | 1840 | * @since 1.7.0 |
1841 | - * @param array $pieces |
|
1841 | + * @param array $pieces |
|
1842 | 1842 | * @return array $pieces |
1843 | 1843 | */ |
1844 | 1844 | public static function comment_total_sum_meta_value_filter( $pieces ) { |
@@ -1873,360 +1873,360 @@ discard block |
||
1873 | 1873 | return $pieces; |
1874 | 1874 | } |
1875 | 1875 | |
1876 | - /** |
|
1877 | - * |
|
1878 | - * Alias to Woothemes_Sensei_Utils::update_user_data |
|
1879 | - * @since 1.7.4 |
|
1880 | - * |
|
1881 | - * @param string $data_key maximum 39 characters allowed |
|
1882 | - * @param int $post_id |
|
1883 | - * @param mixed $value |
|
1884 | - * @param int $user_id |
|
1885 | - * |
|
1886 | - * @return bool $success |
|
1887 | - */ |
|
1888 | - public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0 ){ |
|
1889 | - |
|
1890 | - return self::update_user_data( $data_key, $post_id, $value , $user_id ); |
|
1891 | - |
|
1892 | - }// end add_user_data |
|
1893 | - |
|
1894 | - /** |
|
1895 | - * add user specific data to the passed in sensei post type id |
|
1896 | - * |
|
1897 | - * This function saves comment meta on the users current status. If no status is available |
|
1898 | - * status will be created. It only operates on the available sensei Post types: course, lesson, quiz. |
|
1899 | - * |
|
1900 | - * @since 1.7.4 |
|
1901 | - * |
|
1902 | - * @param string $data_key maximum 39 characters allowed |
|
1903 | - * @param int $post_id |
|
1904 | - * @param mixed $value |
|
1905 | - * @param int $user_id |
|
1906 | - * |
|
1907 | - * @return bool $success |
|
1908 | - */ |
|
1909 | - public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0 ){ |
|
1910 | - |
|
1911 | - if( ! ( $user_id > 0 ) ){ |
|
1912 | - $user_id = get_current_user_id(); |
|
1913 | - } |
|
1914 | - |
|
1915 | - $supported_post_types = array( 'course', 'lesson' ); |
|
1916 | - $post_type = get_post_type( $post_id ); |
|
1917 | - if( empty( $post_id ) || empty( $data_key ) |
|
1918 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
1919 | - || !get_userdata( $user_id ) |
|
1920 | - || ! in_array( $post_type, $supported_post_types ) ){ |
|
1921 | - |
|
1922 | - return false; |
|
1923 | - } |
|
1924 | - |
|
1925 | - // check if there and existing Sensei status on this post type if not create it |
|
1926 | - // and get the activity ID |
|
1927 | - $status_function = 'user_'.$post_type.'_status'; |
|
1928 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
1929 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
1930 | - |
|
1931 | - $start_function = 'user_start_'.$post_type; |
|
1932 | - $sensei_user_activity_id = self::$start_function( $user_id, $post_id ); |
|
1933 | - |
|
1934 | - }else{ |
|
1935 | - |
|
1936 | - $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
1937 | - |
|
1938 | - } |
|
1939 | - |
|
1940 | - // store the data |
|
1941 | - $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value ); |
|
1942 | - |
|
1943 | - return $success; |
|
1944 | - |
|
1945 | - }//update_user_data |
|
1946 | - |
|
1947 | - /** |
|
1948 | - * Get the user data stored on the passed in post type |
|
1949 | - * |
|
1950 | - * This function gets the comment meta on the lesson or course status |
|
1951 | - * |
|
1952 | - * @since 1.7.4 |
|
1953 | - * |
|
1954 | - * @param $data_key |
|
1955 | - * @param $post_id |
|
1956 | - * @param int $user_id |
|
1957 | - * |
|
1958 | - * @return mixed $user_data_value |
|
1959 | - */ |
|
1960 | - public static function get_user_data( $data_key, $post_id, $user_id = 0 ){ |
|
1961 | - |
|
1962 | - $user_data_value = true; |
|
1963 | - |
|
1964 | - if( ! ( $user_id > 0 ) ){ |
|
1965 | - $user_id = get_current_user_id(); |
|
1966 | - } |
|
1967 | - |
|
1968 | - $supported_post_types = array( 'course', 'lesson' ); |
|
1969 | - $post_type = get_post_type( $post_id ); |
|
1970 | - if( empty( $post_id ) || empty( $data_key ) |
|
1971 | - || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
1972 | - || ! get_userdata( $user_id ) |
|
1973 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
1974 | - |
|
1975 | - return false; |
|
1976 | - } |
|
1977 | - |
|
1978 | - // check if there and existing Sensei status on this post type if not create it |
|
1979 | - // and get the activity ID |
|
1980 | - $status_function = 'user_'.$post_type.'_status'; |
|
1981 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
1982 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
1983 | - return false; |
|
1984 | - } |
|
1985 | - |
|
1986 | - $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
1987 | - $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true ); |
|
1988 | - |
|
1989 | - return $user_data_value; |
|
1990 | - |
|
1991 | - }// end get_user_data |
|
1992 | - |
|
1993 | - /** |
|
1994 | - * Delete the Sensei user data for the given key, Sensei post type and user combination. |
|
1995 | - * |
|
1996 | - * @param int $data_key |
|
1997 | - * @param int $post_id |
|
1998 | - * @param int $user_id |
|
1999 | - * |
|
2000 | - * @return bool $deleted |
|
2001 | - */ |
|
2002 | - public static function delete_user_data( $data_key, $post_id , $user_id ){ |
|
2003 | - $deleted = true; |
|
1876 | + /** |
|
1877 | + * |
|
1878 | + * Alias to Woothemes_Sensei_Utils::update_user_data |
|
1879 | + * @since 1.7.4 |
|
1880 | + * |
|
1881 | + * @param string $data_key maximum 39 characters allowed |
|
1882 | + * @param int $post_id |
|
1883 | + * @param mixed $value |
|
1884 | + * @param int $user_id |
|
1885 | + * |
|
1886 | + * @return bool $success |
|
1887 | + */ |
|
1888 | + public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0 ){ |
|
1889 | + |
|
1890 | + return self::update_user_data( $data_key, $post_id, $value , $user_id ); |
|
1891 | + |
|
1892 | + }// end add_user_data |
|
1893 | + |
|
1894 | + /** |
|
1895 | + * add user specific data to the passed in sensei post type id |
|
1896 | + * |
|
1897 | + * This function saves comment meta on the users current status. If no status is available |
|
1898 | + * status will be created. It only operates on the available sensei Post types: course, lesson, quiz. |
|
1899 | + * |
|
1900 | + * @since 1.7.4 |
|
1901 | + * |
|
1902 | + * @param string $data_key maximum 39 characters allowed |
|
1903 | + * @param int $post_id |
|
1904 | + * @param mixed $value |
|
1905 | + * @param int $user_id |
|
1906 | + * |
|
1907 | + * @return bool $success |
|
1908 | + */ |
|
1909 | + public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0 ){ |
|
1910 | + |
|
1911 | + if( ! ( $user_id > 0 ) ){ |
|
1912 | + $user_id = get_current_user_id(); |
|
1913 | + } |
|
1914 | + |
|
1915 | + $supported_post_types = array( 'course', 'lesson' ); |
|
1916 | + $post_type = get_post_type( $post_id ); |
|
1917 | + if( empty( $post_id ) || empty( $data_key ) |
|
1918 | + || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
1919 | + || !get_userdata( $user_id ) |
|
1920 | + || ! in_array( $post_type, $supported_post_types ) ){ |
|
1921 | + |
|
1922 | + return false; |
|
1923 | + } |
|
1924 | + |
|
1925 | + // check if there and existing Sensei status on this post type if not create it |
|
1926 | + // and get the activity ID |
|
1927 | + $status_function = 'user_'.$post_type.'_status'; |
|
1928 | + $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
1929 | + if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
1930 | + |
|
1931 | + $start_function = 'user_start_'.$post_type; |
|
1932 | + $sensei_user_activity_id = self::$start_function( $user_id, $post_id ); |
|
1933 | + |
|
1934 | + }else{ |
|
1935 | + |
|
1936 | + $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
1937 | + |
|
1938 | + } |
|
1939 | + |
|
1940 | + // store the data |
|
1941 | + $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value ); |
|
1942 | + |
|
1943 | + return $success; |
|
1944 | + |
|
1945 | + }//update_user_data |
|
1946 | + |
|
1947 | + /** |
|
1948 | + * Get the user data stored on the passed in post type |
|
1949 | + * |
|
1950 | + * This function gets the comment meta on the lesson or course status |
|
1951 | + * |
|
1952 | + * @since 1.7.4 |
|
1953 | + * |
|
1954 | + * @param $data_key |
|
1955 | + * @param $post_id |
|
1956 | + * @param int $user_id |
|
1957 | + * |
|
1958 | + * @return mixed $user_data_value |
|
1959 | + */ |
|
1960 | + public static function get_user_data( $data_key, $post_id, $user_id = 0 ){ |
|
1961 | + |
|
1962 | + $user_data_value = true; |
|
1963 | + |
|
1964 | + if( ! ( $user_id > 0 ) ){ |
|
1965 | + $user_id = get_current_user_id(); |
|
1966 | + } |
|
1967 | + |
|
1968 | + $supported_post_types = array( 'course', 'lesson' ); |
|
1969 | + $post_type = get_post_type( $post_id ); |
|
1970 | + if( empty( $post_id ) || empty( $data_key ) |
|
1971 | + || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
1972 | + || ! get_userdata( $user_id ) |
|
1973 | + || !in_array( $post_type, $supported_post_types ) ){ |
|
2004 | 1974 | |
2005 | - if( ! ( $user_id > 0 ) ){ |
|
2006 | - $user_id = get_current_user_id(); |
|
2007 | - } |
|
1975 | + return false; |
|
1976 | + } |
|
2008 | 1977 | |
2009 | - $supported_post_types = array( 'course', 'lesson' ); |
|
2010 | - $post_type = get_post_type( $post_id ); |
|
2011 | - if( empty( $post_id ) || empty( $data_key ) |
|
2012 | - || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
2013 | - || ! get_userdata( $user_id ) |
|
2014 | - || !in_array( $post_type, $supported_post_types ) ){ |
|
1978 | + // check if there and existing Sensei status on this post type if not create it |
|
1979 | + // and get the activity ID |
|
1980 | + $status_function = 'user_'.$post_type.'_status'; |
|
1981 | + $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
1982 | + if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
1983 | + return false; |
|
1984 | + } |
|
2015 | 1985 | |
2016 | - return false; |
|
2017 | - } |
|
1986 | + $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
1987 | + $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true ); |
|
1988 | + |
|
1989 | + return $user_data_value; |
|
1990 | + |
|
1991 | + }// end get_user_data |
|
1992 | + |
|
1993 | + /** |
|
1994 | + * Delete the Sensei user data for the given key, Sensei post type and user combination. |
|
1995 | + * |
|
1996 | + * @param int $data_key |
|
1997 | + * @param int $post_id |
|
1998 | + * @param int $user_id |
|
1999 | + * |
|
2000 | + * @return bool $deleted |
|
2001 | + */ |
|
2002 | + public static function delete_user_data( $data_key, $post_id , $user_id ){ |
|
2003 | + $deleted = true; |
|
2004 | + |
|
2005 | + if( ! ( $user_id > 0 ) ){ |
|
2006 | + $user_id = get_current_user_id(); |
|
2007 | + } |
|
2008 | + |
|
2009 | + $supported_post_types = array( 'course', 'lesson' ); |
|
2010 | + $post_type = get_post_type( $post_id ); |
|
2011 | + if( empty( $post_id ) || empty( $data_key ) |
|
2012 | + || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 ) |
|
2013 | + || ! get_userdata( $user_id ) |
|
2014 | + || !in_array( $post_type, $supported_post_types ) ){ |
|
2015 | + |
|
2016 | + return false; |
|
2017 | + } |
|
2018 | 2018 | |
2019 | - // check if there and existing Sensei status on this post type if not create it |
|
2020 | - // and get the activity ID |
|
2021 | - $status_function = 'user_'.$post_type.'_status'; |
|
2022 | - $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
2023 | - if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
2024 | - return false; |
|
2025 | - } |
|
2019 | + // check if there and existing Sensei status on this post type if not create it |
|
2020 | + // and get the activity ID |
|
2021 | + $status_function = 'user_'.$post_type.'_status'; |
|
2022 | + $sensei_user_status = self::$status_function( $post_id ,$user_id ); |
|
2023 | + if( ! isset( $sensei_user_status->comment_ID ) ){ |
|
2024 | + return false; |
|
2025 | + } |
|
2026 | 2026 | |
2027 | - $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
2028 | - $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key ); |
|
2027 | + $sensei_user_activity_id = $sensei_user_status->comment_ID; |
|
2028 | + $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key ); |
|
2029 | 2029 | |
2030 | - return $deleted; |
|
2030 | + return $deleted; |
|
2031 | 2031 | |
2032 | - }// end delete_user_data |
|
2032 | + }// end delete_user_data |
|
2033 | 2033 | |
2034 | 2034 | |
2035 | - /** |
|
2036 | - * The function creates a drop down. Never write up a Sensei select statement again. |
|
2037 | - * |
|
2038 | - * @since 1.8.0 |
|
2039 | - * |
|
2040 | - * @param string $selected_value |
|
2041 | - * @param $options{ |
|
2042 | - * @type string $value the value saved in the database |
|
2043 | - * @type string $option what the user will see in the list of items |
|
2044 | - * } |
|
2045 | - * @param array $attributes{ |
|
2046 | - * @type string $attribute type such name or id etc. |
|
2047 | - * @type string $value |
|
2048 | - * } |
|
2049 | - * @param bool $enable_none_option |
|
2050 | - * |
|
2051 | - * @return string $drop_down_element |
|
2052 | - */ |
|
2053 | - public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) { |
|
2035 | + /** |
|
2036 | + * The function creates a drop down. Never write up a Sensei select statement again. |
|
2037 | + * |
|
2038 | + * @since 1.8.0 |
|
2039 | + * |
|
2040 | + * @param string $selected_value |
|
2041 | + * @param $options{ |
|
2042 | + * @type string $value the value saved in the database |
|
2043 | + * @type string $option what the user will see in the list of items |
|
2044 | + * } |
|
2045 | + * @param array $attributes{ |
|
2046 | + * @type string $attribute type such name or id etc. |
|
2047 | + * @type string $value |
|
2048 | + * } |
|
2049 | + * @param bool $enable_none_option |
|
2050 | + * |
|
2051 | + * @return string $drop_down_element |
|
2052 | + */ |
|
2053 | + public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) { |
|
2054 | 2054 | |
2055 | - $drop_down_element = ''; |
|
2055 | + $drop_down_element = ''; |
|
2056 | 2056 | |
2057 | - // setup the basic attributes |
|
2058 | - if( !isset( $attributes['name'] ) || empty( $attributes['name'] ) ) { |
|
2057 | + // setup the basic attributes |
|
2058 | + if( !isset( $attributes['name'] ) || empty( $attributes['name'] ) ) { |
|
2059 | 2059 | |
2060 | - $attributes['name'] = 'sensei-options'; |
|
2060 | + $attributes['name'] = 'sensei-options'; |
|
2061 | 2061 | |
2062 | - } |
|
2062 | + } |
|
2063 | 2063 | |
2064 | - if( !isset( $attributes['id'] ) || empty( $attributes['id'] ) ) { |
|
2064 | + if( !isset( $attributes['id'] ) || empty( $attributes['id'] ) ) { |
|
2065 | 2065 | |
2066 | - $attributes['id'] = 'sensei-options'; |
|
2066 | + $attributes['id'] = 'sensei-options'; |
|
2067 | 2067 | |
2068 | - } |
|
2068 | + } |
|
2069 | 2069 | |
2070 | - if( !isset( $attributes['class'] ) || empty( $attributes['class'] ) ) { |
|
2070 | + if( !isset( $attributes['class'] ) || empty( $attributes['class'] ) ) { |
|
2071 | 2071 | |
2072 | - $attributes['class'] ='chosen_select widefat'; |
|
2072 | + $attributes['class'] ='chosen_select widefat'; |
|
2073 | 2073 | |
2074 | - } |
|
2074 | + } |
|
2075 | 2075 | |
2076 | - // create element attributes |
|
2077 | - $combined_attributes = ''; |
|
2078 | - foreach( $attributes as $attribute => $value ){ |
|
2076 | + // create element attributes |
|
2077 | + $combined_attributes = ''; |
|
2078 | + foreach( $attributes as $attribute => $value ){ |
|
2079 | 2079 | |
2080 | - $combined_attributes .= $attribute . '="'.$value.'"' . ' '; |
|
2080 | + $combined_attributes .= $attribute . '="'.$value.'"' . ' '; |
|
2081 | 2081 | |
2082 | - }// end for each |
|
2082 | + }// end for each |
|
2083 | 2083 | |
2084 | 2084 | |
2085 | - // create the select element |
|
2086 | - $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n"; |
|
2085 | + // create the select element |
|
2086 | + $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n"; |
|
2087 | 2087 | |
2088 | - // show the none option if the client requested |
|
2089 | - if( $enable_none_option ) { |
|
2090 | - $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
2091 | - } |
|
2088 | + // show the none option if the client requested |
|
2089 | + if( $enable_none_option ) { |
|
2090 | + $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>'; |
|
2091 | + } |
|
2092 | 2092 | |
2093 | - if ( count( $options ) > 0 ) { |
|
2093 | + if ( count( $options ) > 0 ) { |
|
2094 | 2094 | |
2095 | - foreach ($options as $value => $option ){ |
|
2095 | + foreach ($options as $value => $option ){ |
|
2096 | 2096 | |
2097 | - $element = ''; |
|
2098 | - $element.= '<option value="' . esc_attr( $value ) . '"'; |
|
2099 | - $element .= selected( $value, $selected_value, false ) . '>'; |
|
2100 | - $element .= esc_html( $option ) . '</option>' . "\n"; |
|
2097 | + $element = ''; |
|
2098 | + $element.= '<option value="' . esc_attr( $value ) . '"'; |
|
2099 | + $element .= selected( $value, $selected_value, false ) . '>'; |
|
2100 | + $element .= esc_html( $option ) . '</option>' . "\n"; |
|
2101 | 2101 | |
2102 | - // add the element to the select html |
|
2103 | - $drop_down_element.= $element; |
|
2104 | - } // End For Loop |
|
2102 | + // add the element to the select html |
|
2103 | + $drop_down_element.= $element; |
|
2104 | + } // End For Loop |
|
2105 | 2105 | |
2106 | - } // End If Statement |
|
2106 | + } // End If Statement |
|
2107 | 2107 | |
2108 | - $drop_down_element .= '</select>' . "\n"; |
|
2108 | + $drop_down_element .= '</select>' . "\n"; |
|
2109 | 2109 | |
2110 | - return $drop_down_element; |
|
2110 | + return $drop_down_element; |
|
2111 | 2111 | |
2112 | - }// generate_drop_down |
|
2112 | + }// generate_drop_down |
|
2113 | 2113 | |
2114 | - /** |
|
2115 | - * Wrapper for the default php round() function. |
|
2116 | - * This allows us to give more control to a user on how they can round Sensei |
|
2117 | - * decimals passed through this function. |
|
2118 | - * |
|
2119 | - * @since 1.8.5 |
|
2120 | - * |
|
2121 | - * @param double $val |
|
2122 | - * @param int $precision |
|
2123 | - * @param $mode |
|
2124 | - * @param string $context |
|
2125 | - * |
|
2126 | - * @return double $val |
|
2127 | - */ |
|
2128 | - public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '' ){ |
|
2114 | + /** |
|
2115 | + * Wrapper for the default php round() function. |
|
2116 | + * This allows us to give more control to a user on how they can round Sensei |
|
2117 | + * decimals passed through this function. |
|
2118 | + * |
|
2119 | + * @since 1.8.5 |
|
2120 | + * |
|
2121 | + * @param double $val |
|
2122 | + * @param int $precision |
|
2123 | + * @param $mode |
|
2124 | + * @param string $context |
|
2125 | + * |
|
2126 | + * @return double $val |
|
2127 | + */ |
|
2128 | + public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '' ){ |
|
2129 | 2129 | |
2130 | - /**å |
|
2130 | + /**å |
|
2131 | 2131 | * Change the precision for the Sensei_Utils::round function. |
2132 | 2132 | * the precision given will be passed into the php round function |
2133 | 2133 | * @since 1.8.5 |
2134 | 2134 | */ |
2135 | - $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode ); |
|
2136 | - |
|
2137 | - /** |
|
2138 | - * Change the mode for the Sensei_Utils::round function. |
|
2139 | - * the mode given will be passed into the php round function |
|
2140 | - * |
|
2141 | - * This applies only to PHP version 5.3.0 and greater |
|
2142 | - * |
|
2143 | - * @since 1.8.5 |
|
2144 | - */ |
|
2145 | - $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision ); |
|
2135 | + $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode ); |
|
2136 | + |
|
2137 | + /** |
|
2138 | + * Change the mode for the Sensei_Utils::round function. |
|
2139 | + * the mode given will be passed into the php round function |
|
2140 | + * |
|
2141 | + * This applies only to PHP version 5.3.0 and greater |
|
2142 | + * |
|
2143 | + * @since 1.8.5 |
|
2144 | + */ |
|
2145 | + $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision ); |
|
2146 | 2146 | |
2147 | - if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) { |
|
2147 | + if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) { |
|
2148 | 2148 | |
2149 | - return round( $val, $precision, $mode ); |
|
2149 | + return round( $val, $precision, $mode ); |
|
2150 | 2150 | |
2151 | - }else{ |
|
2151 | + }else{ |
|
2152 | 2152 | |
2153 | - return round( $val, $precision ); |
|
2153 | + return round( $val, $precision ); |
|
2154 | 2154 | |
2155 | - } |
|
2155 | + } |
|
2156 | 2156 | |
2157 | - } |
|
2157 | + } |
|
2158 | 2158 | |
2159 | - /** |
|
2160 | - * Returns the current url with all the query vars |
|
2161 | - * |
|
2162 | - * @since 1.9.0 |
|
2163 | - * @return string $url |
|
2164 | - */ |
|
2165 | - public static function get_current_url(){ |
|
2159 | + /** |
|
2160 | + * Returns the current url with all the query vars |
|
2161 | + * |
|
2162 | + * @since 1.9.0 |
|
2163 | + * @return string $url |
|
2164 | + */ |
|
2165 | + public static function get_current_url(){ |
|
2166 | 2166 | |
2167 | - global $wp; |
|
2168 | - $current_url = trailingslashit( home_url( $wp->request ) ); |
|
2169 | - if ( isset( $_GET ) ) { |
|
2167 | + global $wp; |
|
2168 | + $current_url = trailingslashit( home_url( $wp->request ) ); |
|
2169 | + if ( isset( $_GET ) ) { |
|
2170 | 2170 | |
2171 | - foreach ($_GET as $param => $val ) { |
|
2171 | + foreach ($_GET as $param => $val ) { |
|
2172 | 2172 | |
2173 | - $current_url = add_query_arg( $param, $val , $current_url ); |
|
2173 | + $current_url = add_query_arg( $param, $val , $current_url ); |
|
2174 | 2174 | |
2175 | - } |
|
2176 | - } |
|
2175 | + } |
|
2176 | + } |
|
2177 | 2177 | |
2178 | - return $current_url; |
|
2179 | - } |
|
2178 | + return $current_url; |
|
2179 | + } |
|
2180 | 2180 | |
2181 | - /** |
|
2182 | - * Restore the global WP_Query |
|
2183 | - * |
|
2184 | - * @since 1.9.0 |
|
2185 | - */ |
|
2186 | - public static function restore_wp_query() { |
|
2181 | + /** |
|
2182 | + * Restore the global WP_Query |
|
2183 | + * |
|
2184 | + * @since 1.9.0 |
|
2185 | + */ |
|
2186 | + public static function restore_wp_query() { |
|
2187 | 2187 | |
2188 | - wp_reset_query(); |
|
2188 | + wp_reset_query(); |
|
2189 | 2189 | |
2190 | - } |
|
2190 | + } |
|
2191 | 2191 | |
2192 | - /** |
|
2193 | - * Merge two arrays in a zip like fashion. |
|
2194 | - * If one array is longer than the other the elements will be apended |
|
2195 | - * to the end of the resulting array. |
|
2196 | - * |
|
2197 | - * @since 1.9.0 |
|
2198 | - * |
|
2199 | - * @param array $array_a |
|
2200 | - * @param array $array_b |
|
2201 | - * @return array $merged_array |
|
2202 | - */ |
|
2203 | - public static function array_zip_merge( $array_a, $array_b ){ |
|
2192 | + /** |
|
2193 | + * Merge two arrays in a zip like fashion. |
|
2194 | + * If one array is longer than the other the elements will be apended |
|
2195 | + * to the end of the resulting array. |
|
2196 | + * |
|
2197 | + * @since 1.9.0 |
|
2198 | + * |
|
2199 | + * @param array $array_a |
|
2200 | + * @param array $array_b |
|
2201 | + * @return array $merged_array |
|
2202 | + */ |
|
2203 | + public static function array_zip_merge( $array_a, $array_b ){ |
|
2204 | 2204 | |
2205 | - if( ! is_array( $array_a ) || ! is_array( $array_b ) ){ |
|
2206 | - trigger_error('array_zip_merge requires both arrays to be indexed arrays '); |
|
2207 | - } |
|
2205 | + if( ! is_array( $array_a ) || ! is_array( $array_b ) ){ |
|
2206 | + trigger_error('array_zip_merge requires both arrays to be indexed arrays '); |
|
2207 | + } |
|
2208 | 2208 | |
2209 | - $merged_array = array(); |
|
2210 | - $total_elements = count( $array_a ) + count( $array_b ); |
|
2209 | + $merged_array = array(); |
|
2210 | + $total_elements = count( $array_a ) + count( $array_b ); |
|
2211 | 2211 | |
2212 | - // Zip arrays |
|
2213 | - for ( $i = 0; $i < $total_elements; $i++) { |
|
2212 | + // Zip arrays |
|
2213 | + for ( $i = 0; $i < $total_elements; $i++) { |
|
2214 | 2214 | |
2215 | - // if has an element at current index push a on top |
|
2216 | - if( isset( $array_a[ $i ] ) ){ |
|
2217 | - $merged_array[] = $array_a[ $i ] ; |
|
2218 | - } |
|
2215 | + // if has an element at current index push a on top |
|
2216 | + if( isset( $array_a[ $i ] ) ){ |
|
2217 | + $merged_array[] = $array_a[ $i ] ; |
|
2218 | + } |
|
2219 | 2219 | |
2220 | - // next if $array_b has an element at current index push a on top of the element |
|
2221 | - // from a if there was one, if not the element before that. |
|
2222 | - if( isset( $array_b[ $i ] ) ){ |
|
2223 | - $merged_array[] = $array_b[ $i ] ; |
|
2224 | - } |
|
2220 | + // next if $array_b has an element at current index push a on top of the element |
|
2221 | + // from a if there was one, if not the element before that. |
|
2222 | + if( isset( $array_b[ $i ] ) ){ |
|
2223 | + $merged_array[] = $array_b[ $i ] ; |
|
2224 | + } |
|
2225 | 2225 | |
2226 | - } |
|
2226 | + } |
|
2227 | 2227 | |
2228 | - return $merged_array; |
|
2229 | - } |
|
2228 | + return $merged_array; |
|
2229 | + } |
|
2230 | 2230 | |
2231 | 2231 | } // End Class |
2232 | 2232 |
@@ -5,18 +5,18 @@ discard block |
||
5 | 5 | * Output tags. |
6 | 6 | ***************************************************************************************************/ |
7 | 7 | |
8 | - /** |
|
9 | - * sensei_course_archive_next_link function. |
|
10 | - * |
|
11 | - * @access public |
|
12 | - * @param string $type (default: 'newcourses') |
|
13 | - * @return void |
|
14 | - */ |
|
15 | - function sensei_course_archive_next_link( $type = 'newcourses' ) { |
|
8 | + /** |
|
9 | + * sensei_course_archive_next_link function. |
|
10 | + * |
|
11 | + * @access public |
|
12 | + * @param string $type (default: 'newcourses') |
|
13 | + * @return void |
|
14 | + */ |
|
15 | + function sensei_course_archive_next_link( $type = 'newcourses' ) { |
|
16 | 16 | |
17 | - _deprecated_function('sensei_course_archive_next_link', '1.9.0','This is no longer used or required in Sensei.'); |
|
17 | + _deprecated_function('sensei_course_archive_next_link', '1.9.0','This is no longer used or required in Sensei.'); |
|
18 | 18 | |
19 | - } // End sensei_course_archive_next_link() |
|
19 | + } // End sensei_course_archive_next_link() |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * course_single_lessons function. |
@@ -26,14 +26,14 @@ discard block |
||
26 | 26 | */ |
27 | 27 | function course_single_lessons() { |
28 | 28 | |
29 | - // load backwards compatible template name if it exists in the users theme |
|
30 | - $located_template= locate_template( Sensei()->template_url . 'single-course/course-lessons.php' ); |
|
31 | - if( $located_template ){ |
|
29 | + // load backwards compatible template name if it exists in the users theme |
|
30 | + $located_template= locate_template( Sensei()->template_url . 'single-course/course-lessons.php' ); |
|
31 | + if( $located_template ){ |
|
32 | 32 | |
33 | - Sensei_Templates::get_template( 'single-course/course-lessons.php' ); |
|
34 | - return; |
|
33 | + Sensei_Templates::get_template( 'single-course/course-lessons.php' ); |
|
34 | + return; |
|
35 | 35 | |
36 | - } |
|
36 | + } |
|
37 | 37 | |
38 | 38 | Sensei_Templates::get_template( 'single-course/lessons.php' ); |
39 | 39 | |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | */ |
49 | 49 | function lesson_single_meta() { |
50 | 50 | |
51 | - _deprecated_function('lesson_single_meta','1.9;0', 'WooThemes_Sensei_Lesson::the_lesson_meta' ); |
|
52 | - sensei_the_single_lesson_meta(); |
|
51 | + _deprecated_function('lesson_single_meta','1.9;0', 'WooThemes_Sensei_Lesson::the_lesson_meta' ); |
|
52 | + sensei_the_single_lesson_meta(); |
|
53 | 53 | |
54 | 54 | } // End lesson_single_meta() |
55 | 55 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @access public |
61 | 61 | * @param bool $return (default: false) |
62 | 62 | * @return void |
63 | - * @deprecated since 1.9.0 |
|
63 | + * @deprecated since 1.9.0 |
|
64 | 64 | */ |
65 | 65 | function quiz_questions( $return = false ) { |
66 | 66 | |
@@ -74,11 +74,11 @@ discard block |
||
74 | 74 | * @access public |
75 | 75 | * @since 1.3.0 |
76 | 76 | * @return void |
77 | - * @deprecated |
|
77 | + * @deprecated |
|
78 | 78 | */ |
79 | 79 | function quiz_question_type( $question_type = 'multiple-choice' ) { |
80 | 80 | |
81 | - Sensei_Templates::get_template( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
81 | + Sensei_Templates::get_template( 'single-quiz/question_type-' . $question_type . '.php' ); |
|
82 | 82 | |
83 | 83 | } // End lesson_single_meta() |
84 | 84 | |
@@ -89,14 +89,14 @@ discard block |
||
89 | 89 | /** |
90 | 90 | * sensei_check_prerequisite_course function. |
91 | 91 | * |
92 | - * @deprecated since 1.9.0 use Sensei_Course::is_prerequisite_complete( $course_id ); |
|
92 | + * @deprecated since 1.9.0 use Sensei_Course::is_prerequisite_complete( $course_id ); |
|
93 | 93 | * @access public |
94 | 94 | * @param mixed $course_id |
95 | 95 | * @return bool |
96 | 96 | */ |
97 | 97 | function sensei_check_prerequisite_course( $course_id ) { |
98 | 98 | |
99 | - return Sensei_Course::is_prerequisite_complete( $course_id ); |
|
99 | + return Sensei_Course::is_prerequisite_complete( $course_id ); |
|
100 | 100 | |
101 | 101 | } // End sensei_check_prerequisite_course() |
102 | 102 | |
@@ -120,14 +120,14 @@ discard block |
||
120 | 120 | <span><input name="course_start" type="submit" class="course-start" value="<?php _e( 'Start taking this Course', 'woothemes-sensei' ); ?>"/></span> |
121 | 121 | |
122 | 122 | </form><?php |
123 | - } // End If Statement |
|
123 | + } // End If Statement |
|
124 | 124 | } // End sensei_start_course_form() |
125 | 125 | |
126 | 126 | |
127 | 127 | /** |
128 | 128 | * sensei_wc_add_to_cart function. |
129 | 129 | * |
130 | - * @deprecated since Sensei_WC::the_add_to_cart_button_html( $course_id ); |
|
130 | + * @deprecated since Sensei_WC::the_add_to_cart_button_html( $course_id ); |
|
131 | 131 | * @access public |
132 | 132 | * @param mixed $course_id |
133 | 133 | * @return void |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | * @return bool |
148 | 148 | */ |
149 | 149 | function sensei_check_if_product_is_in_cart( $wc_product_id = 0 ) { |
150 | - return Sensei_WC::is_product_in_cart( $wc_product_id ); |
|
150 | + return Sensei_WC::is_product_in_cart( $wc_product_id ); |
|
151 | 151 | } // End sensei_check_if_product_is_in_cart() |
152 | 152 | |
153 | 153 | /** |
@@ -160,17 +160,17 @@ discard block |
||
160 | 160 | function sensei_simple_course_price( $post_id ) { |
161 | 161 | |
162 | 162 | //WooCommerce Pricing |
163 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
164 | - $wc_post_id = get_post_meta( $post_id, '_course_woocommerce_product', true ); |
|
165 | - if ( 0 < $wc_post_id ) { |
|
166 | - // Get the product |
|
167 | - $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
163 | + if ( Sensei_WC::is_woocommerce_active() ) { |
|
164 | + $wc_post_id = get_post_meta( $post_id, '_course_woocommerce_product', true ); |
|
165 | + if ( 0 < $wc_post_id ) { |
|
166 | + // Get the product |
|
167 | + $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
168 | 168 | |
169 | - if ( isset( $product ) && !empty( $product ) && $product->is_purchasable() && $product->is_in_stock() && !sensei_check_if_product_is_in_cart( $wc_post_id ) ) { ?> |
|
169 | + if ( isset( $product ) && !empty( $product ) && $product->is_purchasable() && $product->is_in_stock() && !sensei_check_if_product_is_in_cart( $wc_post_id ) ) { ?> |
|
170 | 170 | <span class="course-price"><?php echo $product->get_price_html(); ?></span> |
171 | 171 | <?php } // End If Statement |
172 | - } // End If Statement |
|
173 | - } // End If Statement |
|
172 | + } // End If Statement |
|
173 | + } // End If Statement |
|
174 | 174 | } // End sensei_simple_course_price() |
175 | 175 | |
176 | 176 | /** |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | |
198 | 198 | |
199 | 199 | if ( ! $query->is_main_query() ) |
200 | - return; |
|
200 | + return; |
|
201 | 201 | |
202 | 202 | // Apply Filter only if on frontend and when course archive is running |
203 | 203 | $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] ); |
@@ -205,11 +205,11 @@ discard block |
||
205 | 205 | if ( ! is_admin() && 0 < $course_page_id && 0 < intval( $query->get( 'page_id' ) ) && $query->get( 'page_id' ) == $course_page_id ) { |
206 | 206 | // Check for pagination settings |
207 | 207 | if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) { |
208 | - $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
209 | - } else { |
|
210 | - $amount = $query->get( 'posts_per_page' ); |
|
211 | - } // End If Statement |
|
212 | - $query->set( 'posts_per_page', $amount ); |
|
208 | + $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
209 | + } else { |
|
210 | + $amount = $query->get( 'posts_per_page' ); |
|
211 | + } // End If Statement |
|
212 | + $query->set( 'posts_per_page', $amount ); |
|
213 | 213 | } // End If Statement |
214 | 214 | } // End sensei_course_archive_filter() |
215 | 215 | add_filter( 'pre_get_posts', 'sensei_course_archive_filter', 10, 1 ); |
@@ -248,66 +248,66 @@ discard block |
||
248 | 248 | $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
249 | 249 | $all_lessons = array(); |
250 | 250 | |
251 | - $modules = Sensei()->modules->get_course_modules( intval( $lesson_course_id ) ); |
|
252 | - |
|
253 | - foreach( (array) $modules as $module ) { |
|
254 | - |
|
255 | - $args = array( |
|
256 | - 'post_type' => 'lesson', |
|
257 | - 'post_status' => 'publish', |
|
258 | - 'posts_per_page' => -1, |
|
259 | - 'meta_query' => array( |
|
260 | - array( |
|
261 | - 'key' => '_lesson_course', |
|
262 | - 'value' => intval( $lesson_course_id ), |
|
263 | - 'compare' => '=' |
|
264 | - ) |
|
265 | - ), |
|
266 | - 'tax_query' => array( |
|
267 | - array( |
|
268 | - 'taxonomy' => Sensei()->modules->taxonomy, |
|
269 | - 'field' => 'id', |
|
270 | - 'terms' => intval( $module->term_id ) |
|
271 | - ) |
|
272 | - ), |
|
273 | - 'meta_key' => '_order_module_' . $module->term_id, |
|
274 | - 'orderby' => 'meta_value_num date', |
|
275 | - 'order' => 'ASC', |
|
276 | - 'suppress_filters' => 0 |
|
277 | - ); |
|
278 | - |
|
279 | - $lessons = get_posts( $args ); |
|
280 | - if ( 0 < count( $lessons ) ) { |
|
281 | - foreach ($lessons as $lesson_item){ |
|
282 | - $all_lessons[] = $lesson_item->ID; |
|
283 | - } // End For Loop |
|
284 | - } // End If Statement |
|
285 | - } |
|
286 | - |
|
287 | - $args = array( |
|
288 | - 'post_type' => 'lesson', |
|
289 | - 'posts_per_page' => -1, |
|
290 | - 'suppress_filters' => 0, |
|
291 | - 'meta_key' => '_order_' . $lesson_course_id, |
|
292 | - 'orderby' => 'meta_value_num date', |
|
293 | - 'order' => 'ASC', |
|
294 | - 'meta_query' => array( |
|
295 | - array( |
|
296 | - 'key' => '_lesson_course', |
|
297 | - 'value' => intval( $lesson_course_id ), |
|
298 | - ), |
|
299 | - ), |
|
300 | - 'post__not_in' => $all_lessons, |
|
301 | - ); |
|
302 | - |
|
303 | - $other_lessons = get_posts( $args ); |
|
304 | - if ( 0 < count( $other_lessons ) ) { |
|
251 | + $modules = Sensei()->modules->get_course_modules( intval( $lesson_course_id ) ); |
|
252 | + |
|
253 | + foreach( (array) $modules as $module ) { |
|
254 | + |
|
255 | + $args = array( |
|
256 | + 'post_type' => 'lesson', |
|
257 | + 'post_status' => 'publish', |
|
258 | + 'posts_per_page' => -1, |
|
259 | + 'meta_query' => array( |
|
260 | + array( |
|
261 | + 'key' => '_lesson_course', |
|
262 | + 'value' => intval( $lesson_course_id ), |
|
263 | + 'compare' => '=' |
|
264 | + ) |
|
265 | + ), |
|
266 | + 'tax_query' => array( |
|
267 | + array( |
|
268 | + 'taxonomy' => Sensei()->modules->taxonomy, |
|
269 | + 'field' => 'id', |
|
270 | + 'terms' => intval( $module->term_id ) |
|
271 | + ) |
|
272 | + ), |
|
273 | + 'meta_key' => '_order_module_' . $module->term_id, |
|
274 | + 'orderby' => 'meta_value_num date', |
|
275 | + 'order' => 'ASC', |
|
276 | + 'suppress_filters' => 0 |
|
277 | + ); |
|
278 | + |
|
279 | + $lessons = get_posts( $args ); |
|
280 | + if ( 0 < count( $lessons ) ) { |
|
281 | + foreach ($lessons as $lesson_item){ |
|
282 | + $all_lessons[] = $lesson_item->ID; |
|
283 | + } // End For Loop |
|
284 | + } // End If Statement |
|
285 | + } |
|
286 | + |
|
287 | + $args = array( |
|
288 | + 'post_type' => 'lesson', |
|
289 | + 'posts_per_page' => -1, |
|
290 | + 'suppress_filters' => 0, |
|
291 | + 'meta_key' => '_order_' . $lesson_course_id, |
|
292 | + 'orderby' => 'meta_value_num date', |
|
293 | + 'order' => 'ASC', |
|
294 | + 'meta_query' => array( |
|
295 | + array( |
|
296 | + 'key' => '_lesson_course', |
|
297 | + 'value' => intval( $lesson_course_id ), |
|
298 | + ), |
|
299 | + ), |
|
300 | + 'post__not_in' => $all_lessons, |
|
301 | + ); |
|
302 | + |
|
303 | + $other_lessons = get_posts( $args ); |
|
304 | + if ( 0 < count( $other_lessons ) ) { |
|
305 | 305 | foreach ($other_lessons as $lesson_item){ |
306 | 306 | $all_lessons[] = $lesson_item->ID; |
307 | 307 | } // End For Loop |
308 | 308 | } // End If Statement |
309 | 309 | |
310 | - if ( 0 < count( $all_lessons ) ) { |
|
310 | + if ( 0 < count( $all_lessons ) ) { |
|
311 | 311 | $found_index = false; |
312 | 312 | foreach ( $all_lessons as $lesson ){ |
313 | 313 | if ( $found_index && $return_values['next_lesson'] == 0 ) { |
@@ -338,9 +338,9 @@ discard block |
||
338 | 338 | */ |
339 | 339 | function sensei_get_excerpt( $post_id = '' ) { |
340 | 340 | |
341 | - global $post; |
|
342 | - _deprecated_function('sensei_get_excerpt', 'use the wordpress excerpt functionality.'); |
|
343 | - return get_the_excerpt(); |
|
341 | + global $post; |
|
342 | + _deprecated_function('sensei_get_excerpt', 'use the wordpress excerpt functionality.'); |
|
343 | + return get_the_excerpt(); |
|
344 | 344 | |
345 | 345 | } |
346 | 346 | |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | */ |
366 | 366 | function sensei_has_user_completed_prerequisite_lesson( $current_lesson_id, $user_id ) { |
367 | 367 | |
368 | - return WooThemes_Sensei_Lesson::is_pre_requisite_complete( $current_lesson_id, $user_id ); |
|
368 | + return WooThemes_Sensei_Lesson::is_pre_requisite_complete( $current_lesson_id, $user_id ); |
|
369 | 369 | |
370 | 370 | } // End sensei_has_user_completed_prerequisite_lesson() |
371 | 371 | |
@@ -480,27 +480,27 @@ discard block |
||
480 | 480 | |
481 | 481 | }else{ |
482 | 482 | |
483 | - // if the loop has not been initiated check the first module has lessons |
|
484 | - if( -1 == $sensei_modules_loop[ 'current' ] ){ |
|
483 | + // if the loop has not been initiated check the first module has lessons |
|
484 | + if( -1 == $sensei_modules_loop[ 'current' ] ){ |
|
485 | 485 | |
486 | - $index = 0; |
|
486 | + $index = 0; |
|
487 | 487 | |
488 | - if( isset( $sensei_modules_loop['modules'][ $index ] ) ) { |
|
489 | - // setup the query for the module lessons |
|
490 | - $course_id = $sensei_modules_loop['course_id']; |
|
488 | + if( isset( $sensei_modules_loop['modules'][ $index ] ) ) { |
|
489 | + // setup the query for the module lessons |
|
490 | + $course_id = $sensei_modules_loop['course_id']; |
|
491 | 491 | |
492 | - $module_term_id = $sensei_modules_loop['modules'][ $index ] ->term_id; |
|
493 | - $modules_query = Sensei()->modules->get_lessons_query( $course_id , $module_term_id ); |
|
492 | + $module_term_id = $sensei_modules_loop['modules'][ $index ] ->term_id; |
|
493 | + $modules_query = Sensei()->modules->get_lessons_query( $course_id , $module_term_id ); |
|
494 | 494 | |
495 | - // setup the global wp-query only if the lessons |
|
496 | - if( $modules_query->have_posts() ){ |
|
495 | + // setup the global wp-query only if the lessons |
|
496 | + if( $modules_query->have_posts() ){ |
|
497 | 497 | |
498 | - return true; |
|
498 | + return true; |
|
499 | 499 | |
500 | - } |
|
501 | - } |
|
502 | - } |
|
503 | - // default to false if the first module doesn't have posts |
|
500 | + } |
|
501 | + } |
|
502 | + } |
|
503 | + // default to false if the first module doesn't have posts |
|
504 | 504 | return false; |
505 | 505 | |
506 | 506 | } |
@@ -604,41 +604,41 @@ discard block |
||
604 | 604 | */ |
605 | 605 | function sensei_get_the_module_status(){ |
606 | 606 | |
607 | - global $sensei_modules_loop; |
|
608 | - $module_title = $sensei_modules_loop['current_module']->name; |
|
609 | - $module_term_id = $sensei_modules_loop['current_module']->term_id; |
|
610 | - $course_id = $sensei_modules_loop['course_id']; |
|
611 | - $module_progress = Sensei()->modules->get_user_module_progress( $module_term_id, $course_id, get_current_user_id() ); |
|
607 | + global $sensei_modules_loop; |
|
608 | + $module_title = $sensei_modules_loop['current_module']->name; |
|
609 | + $module_term_id = $sensei_modules_loop['current_module']->term_id; |
|
610 | + $course_id = $sensei_modules_loop['course_id']; |
|
611 | + $module_progress = Sensei()->modules->get_user_module_progress( $module_term_id, $course_id, get_current_user_id() ); |
|
612 | 612 | |
613 | - $module_status = ''; |
|
614 | - if ( $module_progress && $module_progress > 0) { |
|
613 | + $module_status = ''; |
|
614 | + if ( $module_progress && $module_progress > 0) { |
|
615 | 615 | |
616 | - $module_status = __('Completed', 'woothemes-sensei'); |
|
616 | + $module_status = __('Completed', 'woothemes-sensei'); |
|
617 | 617 | |
618 | - if ($module_progress < 100) { |
|
618 | + if ($module_progress < 100) { |
|
619 | 619 | |
620 | - $module_status = __('In progress', 'woothemes-sensei'); |
|
620 | + $module_status = __('In progress', 'woothemes-sensei'); |
|
621 | 621 | |
622 | - } |
|
622 | + } |
|
623 | 623 | |
624 | - } |
|
624 | + } |
|
625 | 625 | |
626 | - $module_status_html = '<p class="status module-status completed">' |
|
627 | - . strtolower( str_replace( ' ', '-', $module_status ) ) |
|
628 | - . '</p>'; |
|
626 | + $module_status_html = '<p class="status module-status completed">' |
|
627 | + . strtolower( str_replace( ' ', '-', $module_status ) ) |
|
628 | + . '</p>'; |
|
629 | 629 | |
630 | - /** |
|
631 | - * Filter the module status. |
|
632 | - * |
|
633 | - * This fires within the sensei_get_the_module_status function. |
|
634 | - * |
|
635 | - * @since 1.9.0 |
|
636 | - * |
|
637 | - * @param $module_status_html |
|
638 | - * @param $module_term_id |
|
639 | - * @param $course_id |
|
640 | - */ |
|
641 | - return apply_filters( 'sensei_the_module_status_html', $module_status_html , $module_term_id, $course_id ); |
|
630 | + /** |
|
631 | + * Filter the module status. |
|
632 | + * |
|
633 | + * This fires within the sensei_get_the_module_status function. |
|
634 | + * |
|
635 | + * @since 1.9.0 |
|
636 | + * |
|
637 | + * @param $module_status_html |
|
638 | + * @param $module_term_id |
|
639 | + * @param $course_id |
|
640 | + */ |
|
641 | + return apply_filters( 'sensei_the_module_status_html', $module_status_html , $module_term_id, $course_id ); |
|
642 | 642 | |
643 | 643 | } |
644 | 644 | |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | */ |
649 | 649 | function sensei_the_module_status(){ |
650 | 650 | |
651 | - echo sensei_get_the_module_status(); |
|
651 | + echo sensei_get_the_module_status(); |
|
652 | 652 | |
653 | 653 | } |
654 | 654 | |
@@ -669,21 +669,21 @@ discard block |
||
669 | 669 | */ |
670 | 670 | function sensei_quiz_has_questions(){ |
671 | 671 | |
672 | - global $sensei_question_loop; |
|
672 | + global $sensei_question_loop; |
|
673 | 673 | |
674 | - if( !isset( $sensei_question_loop['total'] ) ){ |
|
675 | - return false; |
|
676 | - } |
|
674 | + if( !isset( $sensei_question_loop['total'] ) ){ |
|
675 | + return false; |
|
676 | + } |
|
677 | 677 | |
678 | - if( $sensei_question_loop['current'] + 1 < $sensei_question_loop['total'] ){ |
|
678 | + if( $sensei_question_loop['current'] + 1 < $sensei_question_loop['total'] ){ |
|
679 | 679 | |
680 | - return true; |
|
680 | + return true; |
|
681 | 681 | |
682 | - }else{ |
|
682 | + }else{ |
|
683 | 683 | |
684 | - return false; |
|
684 | + return false; |
|
685 | 685 | |
686 | - } |
|
686 | + } |
|
687 | 687 | |
688 | 688 | }// end sensei_quiz_has_questions |
689 | 689 | |
@@ -694,15 +694,14 @@ discard block |
||
694 | 694 | * execution. |
695 | 695 | * |
696 | 696 | * @since 1.9.0 |
697 | - |
|
698 | 697 | */ |
699 | 698 | function sensei_setup_the_question(){ |
700 | 699 | |
701 | - global $sensei_question_loop; |
|
700 | + global $sensei_question_loop; |
|
702 | 701 | |
703 | - $sensei_question_loop['current']++; |
|
704 | - $index = $sensei_question_loop['current']; |
|
705 | - $sensei_question_loop['current_question'] = $sensei_question_loop['questions'][ $index ] ; |
|
702 | + $sensei_question_loop['current']++; |
|
703 | + $index = $sensei_question_loop['current']; |
|
704 | + $sensei_question_loop['current_question'] = $sensei_question_loop['questions'][ $index ] ; |
|
706 | 705 | |
707 | 706 | |
708 | 707 | }// end sensei_setup_the_question |
@@ -715,12 +714,12 @@ discard block |
||
715 | 714 | */ |
716 | 715 | function sensei_the_question_content(){ |
717 | 716 | |
718 | - global $sensei_question_loop; |
|
717 | + global $sensei_question_loop; |
|
719 | 718 | |
720 | - $question_type = Sensei()->question->get_question_type( $sensei_question_loop['current_question']->ID ); |
|
719 | + $question_type = Sensei()->question->get_question_type( $sensei_question_loop['current_question']->ID ); |
|
721 | 720 | |
722 | - // load the template that displays the question information. |
|
723 | - WooThemes_Sensei_Question::load_question_template( $question_type ); |
|
721 | + // load the template that displays the question information. |
|
722 | + WooThemes_Sensei_Question::load_question_template( $question_type ); |
|
724 | 723 | |
725 | 724 | }// end sensei_the_question_content |
726 | 725 | |
@@ -731,26 +730,26 @@ discard block |
||
731 | 730 | */ |
732 | 731 | function sensei_the_question_class(){ |
733 | 732 | |
734 | - global $sensei_question_loop; |
|
733 | + global $sensei_question_loop; |
|
735 | 734 | |
736 | - $question_type = Sensei()->question->get_question_type( $sensei_question_loop['current_question']->ID ); |
|
735 | + $question_type = Sensei()->question->get_question_type( $sensei_question_loop['current_question']->ID ); |
|
737 | 736 | |
738 | - /** |
|
739 | - * filter the sensei question class within |
|
740 | - * the quiz question loop. |
|
741 | - * |
|
742 | - * @since 1.9.0 |
|
743 | - */ |
|
744 | - $classes = apply_filters( 'sensei_question_classes', array( $question_type ) ); |
|
737 | + /** |
|
738 | + * filter the sensei question class within |
|
739 | + * the quiz question loop. |
|
740 | + * |
|
741 | + * @since 1.9.0 |
|
742 | + */ |
|
743 | + $classes = apply_filters( 'sensei_question_classes', array( $question_type ) ); |
|
745 | 744 | |
746 | - $html_classes = ''; |
|
747 | - foreach( $classes as $class ){ |
|
745 | + $html_classes = ''; |
|
746 | + foreach( $classes as $class ){ |
|
748 | 747 | |
749 | - $html_classes .= $class . ' '; |
|
748 | + $html_classes .= $class . ' '; |
|
750 | 749 | |
751 | - }// end foreach |
|
750 | + }// end foreach |
|
752 | 751 | |
753 | - esc_attr_e( trim( $html_classes ) ); |
|
752 | + esc_attr_e( trim( $html_classes ) ); |
|
754 | 753 | |
755 | 754 | } |
756 | 755 | |
@@ -761,12 +760,12 @@ discard block |
||
761 | 760 | */ |
762 | 761 | function sensei_get_the_question_id( ){ |
763 | 762 | |
764 | - global $sensei_question_loop; |
|
765 | - if( isset( $sensei_question_loop['current_question']->ID ) ){ |
|
763 | + global $sensei_question_loop; |
|
764 | + if( isset( $sensei_question_loop['current_question']->ID ) ){ |
|
766 | 765 | |
767 | - return $sensei_question_loop['current_question']->ID; |
|
766 | + return $sensei_question_loop['current_question']->ID; |
|
768 | 767 | |
769 | - } |
|
768 | + } |
|
770 | 769 | |
771 | 770 | }// end sensei_the_question_id |
772 | 771 | |
@@ -793,63 +792,63 @@ discard block |
||
793 | 792 | */ |
794 | 793 | function sensei_can_user_view_lesson( $lesson_id = '', $user_id = '' ){ |
795 | 794 | |
796 | - if( empty( $lesson_id ) ){ |
|
795 | + if( empty( $lesson_id ) ){ |
|
797 | 796 | |
798 | - $lesson_id = get_the_ID(); |
|
797 | + $lesson_id = get_the_ID(); |
|
799 | 798 | |
800 | - } |
|
799 | + } |
|
801 | 800 | |
802 | - if( empty( $user_id ) ){ |
|
801 | + if( empty( $user_id ) ){ |
|
803 | 802 | |
804 | - $user_id = get_current_user_id(); |
|
803 | + $user_id = get_current_user_id(); |
|
805 | 804 | |
806 | - } |
|
805 | + } |
|
807 | 806 | |
808 | - // Check for prerequisite lesson completions |
|
809 | - $pre_requisite_complete = WooThemes_Sensei_Lesson::is_prerequisite_complete( $lesson_id, $user_id ); |
|
810 | - $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
|
811 | - $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, $user_id ); |
|
807 | + // Check for prerequisite lesson completions |
|
808 | + $pre_requisite_complete = WooThemes_Sensei_Lesson::is_prerequisite_complete( $lesson_id, $user_id ); |
|
809 | + $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true ); |
|
810 | + $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, $user_id ); |
|
812 | 811 | |
813 | - $is_preview = false; |
|
814 | - if( Sensei_Utils::is_preview_lesson( $lesson_id ) ) { |
|
812 | + $is_preview = false; |
|
813 | + if( Sensei_Utils::is_preview_lesson( $lesson_id ) ) { |
|
815 | 814 | |
816 | - $is_preview = true; |
|
817 | - $pre_requisite_complete = true; |
|
815 | + $is_preview = true; |
|
816 | + $pre_requisite_complete = true; |
|
818 | 817 | |
819 | - }; |
|
818 | + }; |
|
820 | 819 | |
821 | 820 | |
822 | - $user_can_access_lesson = false; |
|
821 | + $user_can_access_lesson = false; |
|
823 | 822 | |
824 | - if( is_user_logged_in() && $user_taking_course ){ |
|
823 | + if( is_user_logged_in() && $user_taking_course ){ |
|
825 | 824 | |
826 | - $user_can_access_lesson = true; |
|
825 | + $user_can_access_lesson = true; |
|
827 | 826 | |
828 | - } |
|
827 | + } |
|
829 | 828 | |
830 | 829 | |
831 | - $access_permission = false; |
|
830 | + $access_permission = false; |
|
832 | 831 | |
833 | - if ( ! Sensei()->settings->get('access_permission') || sensei_all_access() ) { |
|
832 | + if ( ! Sensei()->settings->get('access_permission') || sensei_all_access() ) { |
|
834 | 833 | |
835 | - $access_permission = true; |
|
834 | + $access_permission = true; |
|
836 | 835 | |
837 | - } |
|
836 | + } |
|
838 | 837 | |
839 | - $can_user_view_lesson = $access_permission || ( $user_can_access_lesson && $pre_requisite_complete ) || $is_preview; |
|
838 | + $can_user_view_lesson = $access_permission || ( $user_can_access_lesson && $pre_requisite_complete ) || $is_preview; |
|
840 | 839 | |
841 | - /** |
|
842 | - * Filter the can user view lesson function |
|
843 | - * |
|
844 | - * @since 1.9.0 |
|
845 | - * |
|
846 | - * @hooked Sensei_WC::alter_can_user_view_lesson |
|
847 | - * |
|
848 | - * @param bool $can_user_view_lesson |
|
849 | - * @param string $lesson_id |
|
850 | - * @param string $user_id |
|
851 | - */ |
|
852 | - return apply_filters( 'sensei_can_user_view_lesson', $can_user_view_lesson, $lesson_id, $user_id ); |
|
840 | + /** |
|
841 | + * Filter the can user view lesson function |
|
842 | + * |
|
843 | + * @since 1.9.0 |
|
844 | + * |
|
845 | + * @hooked Sensei_WC::alter_can_user_view_lesson |
|
846 | + * |
|
847 | + * @param bool $can_user_view_lesson |
|
848 | + * @param string $lesson_id |
|
849 | + * @param string $user_id |
|
850 | + */ |
|
851 | + return apply_filters( 'sensei_can_user_view_lesson', $can_user_view_lesson, $lesson_id, $user_id ); |
|
853 | 852 | |
854 | 853 | } // end sensei_can_current_user_view_lesson |
855 | 854 | |
@@ -861,49 +860,49 @@ discard block |
||
861 | 860 | */ |
862 | 861 | function sensei_the_single_lesson_meta(){ |
863 | 862 | |
864 | - // if the lesson meta is included within theme load that instead of the function content |
|
865 | - $template = Sensei_Templates::locate_template( 'single-lesson/lesson-meta.php' ); |
|
866 | - if( ! empty( $template ) ){ |
|
867 | - |
|
868 | - Sensei_Templates::get_template( 'single-lesson/lesson-meta.php' ); |
|
869 | - return; |
|
863 | + // if the lesson meta is included within theme load that instead of the function content |
|
864 | + $template = Sensei_Templates::locate_template( 'single-lesson/lesson-meta.php' ); |
|
865 | + if( ! empty( $template ) ){ |
|
870 | 866 | |
871 | - } |
|
867 | + Sensei_Templates::get_template( 'single-lesson/lesson-meta.php' ); |
|
868 | + return; |
|
872 | 869 | |
873 | - // Get the meta info |
|
874 | - $lesson_course_id = absint( get_post_meta( get_the_ID(), '_lesson_course', true ) ); |
|
875 | - $is_preview = Sensei_Utils::is_preview_lesson( get_the_ID() ); |
|
870 | + } |
|
876 | 871 | |
877 | - // Complete Lesson Logic |
|
878 | - do_action( 'sensei_complete_lesson' ); |
|
879 | - // Check that the course has been started |
|
880 | - if ( Sensei()->access_settings() |
|
881 | - || Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id()) |
|
882 | - || $is_preview ) { |
|
883 | - ?> |
|
872 | + // Get the meta info |
|
873 | + $lesson_course_id = absint( get_post_meta( get_the_ID(), '_lesson_course', true ) ); |
|
874 | + $is_preview = Sensei_Utils::is_preview_lesson( get_the_ID() ); |
|
875 | + |
|
876 | + // Complete Lesson Logic |
|
877 | + do_action( 'sensei_complete_lesson' ); |
|
878 | + // Check that the course has been started |
|
879 | + if ( Sensei()->access_settings() |
|
880 | + || Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id()) |
|
881 | + || $is_preview ) { |
|
882 | + ?> |
|
884 | 883 | <section class="lesson-meta"> |
885 | 884 | <?php |
886 | - if( apply_filters( 'sensei_video_position', 'top', get_the_ID() ) == 'bottom' ) { |
|
885 | + if( apply_filters( 'sensei_video_position', 'top', get_the_ID() ) == 'bottom' ) { |
|
887 | 886 | |
888 | - do_action( 'sensei_lesson_video', get_the_ID() ); |
|
887 | + do_action( 'sensei_lesson_video', get_the_ID() ); |
|
889 | 888 | |
890 | - } |
|
891 | - ?> |
|
889 | + } |
|
890 | + ?> |
|
892 | 891 | <?php do_action( 'sensei_frontend_messages' ); ?> |
893 | 892 | |
894 | 893 | <?php if ( ! $is_preview |
895 | - || Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id()) ) { |
|
894 | + || Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id()) ) { |
|
896 | 895 | |
897 | - sensei_do_deprecated_action( 'sensei_lesson_quiz_meta','1.9.0', 'sensei_single_lesson_content_inside_before' ,array( get_the_ID(), get_current_user_id() ) ); |
|
896 | + sensei_do_deprecated_action( 'sensei_lesson_quiz_meta','1.9.0', 'sensei_single_lesson_content_inside_before' ,array( get_the_ID(), get_current_user_id() ) ); |
|
898 | 897 | |
899 | - } ?> |
|
898 | + } ?> |
|
900 | 899 | </section> |
901 | 900 | |
902 | 901 | <?php do_action( 'sensei_lesson_back_link', $lesson_course_id ); ?> |
903 | 902 | |
904 | 903 | <?php } |
905 | 904 | |
906 | - do_action( 'sensei_lesson_meta_extra', get_the_ID() ); |
|
905 | + do_action( 'sensei_lesson_meta_extra', get_the_ID() ); |
|
907 | 906 | |
908 | 907 | } // end the_single_lesson_meta |
909 | 908 | |
@@ -919,16 +918,16 @@ discard block |
||
919 | 918 | */ |
920 | 919 | function get_sensei_header(){ |
921 | 920 | |
922 | - if ( ! defined( 'ABSPATH' ) ) exit; |
|
921 | + if ( ! defined( 'ABSPATH' ) ) exit; |
|
923 | 922 | |
924 | - get_header(); |
|
923 | + get_header(); |
|
925 | 924 | |
926 | - /** |
|
927 | - * sensei_before_main_content hook |
|
928 | - * |
|
929 | - * @hooked sensei_output_content_wrapper - 10 (outputs opening divs for the content) |
|
930 | - */ |
|
931 | - do_action( 'sensei_before_main_content' ); |
|
925 | + /** |
|
926 | + * sensei_before_main_content hook |
|
927 | + * |
|
928 | + * @hooked sensei_output_content_wrapper - 10 (outputs opening divs for the content) |
|
929 | + */ |
|
930 | + do_action( 'sensei_before_main_content' ); |
|
932 | 931 | |
933 | 932 | }// end get_sensei_header |
934 | 933 | |
@@ -944,28 +943,28 @@ discard block |
||
944 | 943 | */ |
945 | 944 | function get_sensei_footer(){ |
946 | 945 | |
947 | - /** |
|
948 | - * sensei_pagination hook |
|
949 | - * |
|
950 | - * @hooked sensei_pagination - 10 (outputs pagination) |
|
951 | - */ |
|
952 | - do_action( 'sensei_pagination' ); |
|
953 | - |
|
954 | - /** |
|
955 | - * sensei_after_main_content hook |
|
956 | - * |
|
957 | - * @hooked sensei_output_content_wrapper_end - 10 (outputs closing divs for the content) |
|
958 | - */ |
|
959 | - do_action( 'sensei_after_main_content' ); |
|
960 | - |
|
961 | - /** |
|
962 | - * sensei_sidebar hook |
|
963 | - * |
|
964 | - * @hooked sensei_get_sidebar - 10 |
|
965 | - */ |
|
966 | - do_action( 'sensei_sidebar' ); |
|
967 | - |
|
968 | - get_footer(); |
|
946 | + /** |
|
947 | + * sensei_pagination hook |
|
948 | + * |
|
949 | + * @hooked sensei_pagination - 10 (outputs pagination) |
|
950 | + */ |
|
951 | + do_action( 'sensei_pagination' ); |
|
952 | + |
|
953 | + /** |
|
954 | + * sensei_after_main_content hook |
|
955 | + * |
|
956 | + * @hooked sensei_output_content_wrapper_end - 10 (outputs closing divs for the content) |
|
957 | + */ |
|
958 | + do_action( 'sensei_after_main_content' ); |
|
959 | + |
|
960 | + /** |
|
961 | + * sensei_sidebar hook |
|
962 | + * |
|
963 | + * @hooked sensei_get_sidebar - 10 |
|
964 | + */ |
|
965 | + do_action( 'sensei_sidebar' ); |
|
966 | + |
|
967 | + get_footer(); |
|
969 | 968 | |
970 | 969 | }// end get_sensei_header |
971 | 970 | |
@@ -977,14 +976,14 @@ discard block |
||
977 | 976 | */ |
978 | 977 | function the_no_permissions_title(){ |
979 | 978 | |
980 | - /** |
|
981 | - * Filter the no permissions title just before it is echo'd on the |
|
982 | - * no-permissions.php file. |
|
983 | - * |
|
984 | - * @since 1.9.0 |
|
985 | - * @param $no_permissions_title |
|
986 | - */ |
|
987 | - echo apply_filters( 'sensei_the_no_permissions_title', Sensei()->permissions_message['title'] ); |
|
979 | + /** |
|
980 | + * Filter the no permissions title just before it is echo'd on the |
|
981 | + * no-permissions.php file. |
|
982 | + * |
|
983 | + * @since 1.9.0 |
|
984 | + * @param $no_permissions_title |
|
985 | + */ |
|
986 | + echo apply_filters( 'sensei_the_no_permissions_title', Sensei()->permissions_message['title'] ); |
|
988 | 987 | |
989 | 988 | } |
990 | 989 | |
@@ -995,14 +994,14 @@ discard block |
||
995 | 994 | */ |
996 | 995 | function the_no_permissions_message( $post_id ){ |
997 | 996 | |
998 | - /** |
|
999 | - * Filter the no permissions message just before it is echo'd on the |
|
1000 | - * no-permissions.php file. |
|
1001 | - * |
|
1002 | - * @since 1.9.0 |
|
1003 | - * @param $no_permissions_message |
|
1004 | - */ |
|
1005 | - echo apply_filters( 'sensei_the_no_permissions_message', Sensei()->permissions_message['message'] , $post_id ); |
|
997 | + /** |
|
998 | + * Filter the no permissions message just before it is echo'd on the |
|
999 | + * no-permissions.php file. |
|
1000 | + * |
|
1001 | + * @since 1.9.0 |
|
1002 | + * @param $no_permissions_message |
|
1003 | + */ |
|
1004 | + echo apply_filters( 'sensei_the_no_permissions_message', Sensei()->permissions_message['message'] , $post_id ); |
|
1006 | 1005 | |
1007 | 1006 | } |
1008 | 1007 | |
@@ -1013,8 +1012,8 @@ discard block |
||
1013 | 1012 | */ |
1014 | 1013 | function sensei_the_excerpt( $post_id ){ |
1015 | 1014 | |
1016 | - global $post; |
|
1017 | - the_excerpt( $post ); |
|
1015 | + global $post; |
|
1016 | + the_excerpt( $post ); |
|
1018 | 1017 | |
1019 | 1018 | } |
1020 | 1019 | |
@@ -1028,9 +1027,9 @@ discard block |
||
1028 | 1027 | */ |
1029 | 1028 | function sensei_get_current_page_url(){ |
1030 | 1029 | |
1031 | - global $wp; |
|
1032 | - $current_page_url = home_url( $wp->request ); |
|
1033 | - return $current_page_url; |
|
1030 | + global $wp; |
|
1031 | + $current_page_url = home_url( $wp->request ); |
|
1032 | + return $current_page_url; |
|
1034 | 1033 | |
1035 | 1034 | } |
1036 | 1035 | |
@@ -1042,7 +1041,7 @@ discard block |
||
1042 | 1041 | */ |
1043 | 1042 | function sensei_the_my_courses_content(){ |
1044 | 1043 | |
1045 | - echo Sensei()->course->load_user_courses_content( wp_get_current_user() ); |
|
1044 | + echo Sensei()->course->load_user_courses_content( wp_get_current_user() ); |
|
1046 | 1045 | |
1047 | 1046 | } // sensei_the_my_courses_content |
1048 | 1047 | |
@@ -1057,7 +1056,7 @@ discard block |
||
1057 | 1056 | */ |
1058 | 1057 | function sensei_load_template( $template_name ){ |
1059 | 1058 | |
1060 | - Sensei_Templates::get_template( $template_name ); |
|
1059 | + Sensei_Templates::get_template( $template_name ); |
|
1061 | 1060 | |
1062 | 1061 | } |
1063 | 1062 | |
@@ -1071,7 +1070,7 @@ discard block |
||
1071 | 1070 | */ |
1072 | 1071 | function sensei_load_template_part( $slug, $name ){ |
1073 | 1072 | |
1074 | - Sensei_Templates::get_part( $slug, $name ); |
|
1073 | + Sensei_Templates::get_part( $slug, $name ); |
|
1075 | 1074 | |
1076 | 1075 | } |
1077 | 1076 | |
@@ -1090,17 +1089,17 @@ discard block |
||
1090 | 1089 | */ |
1091 | 1090 | function sensei_the_lesson_excerpt( $lesson_id = '' ) { |
1092 | 1091 | |
1093 | - if( empty( $lesson_id )){ |
|
1092 | + if( empty( $lesson_id )){ |
|
1094 | 1093 | |
1095 | - $lesson_id = get_the_ID(); |
|
1094 | + $lesson_id = get_the_ID(); |
|
1096 | 1095 | |
1097 | - } |
|
1096 | + } |
|
1098 | 1097 | |
1099 | - if( 'lesson' != get_post_type( $lesson_id ) ){ |
|
1100 | - return; |
|
1101 | - } |
|
1098 | + if( 'lesson' != get_post_type( $lesson_id ) ){ |
|
1099 | + return; |
|
1100 | + } |
|
1102 | 1101 | |
1103 | - echo Sensei_Lesson::lesson_excerpt( get_post( $lesson_id ), false ); |
|
1102 | + echo Sensei_Lesson::lesson_excerpt( get_post( $lesson_id ), false ); |
|
1104 | 1103 | |
1105 | 1104 | }// End lesson_excerpt() |
1106 | 1105 | |
@@ -1110,16 +1109,16 @@ discard block |
||
1110 | 1109 | * @since 1.9.0 |
1111 | 1110 | */ |
1112 | 1111 | function sensei_the_course_results_lessons(){ |
1113 | - // load backwards compatible template name if it exists in the users theme |
|
1114 | - $located_template= locate_template( Sensei()->template_url . 'course-results/course-lessons.php' ); |
|
1115 | - if( $located_template ){ |
|
1112 | + // load backwards compatible template name if it exists in the users theme |
|
1113 | + $located_template= locate_template( Sensei()->template_url . 'course-results/course-lessons.php' ); |
|
1114 | + if( $located_template ){ |
|
1116 | 1115 | |
1117 | - Sensei_Templates::get_template( 'course-results/course-lessons.php' ); |
|
1118 | - return; |
|
1116 | + Sensei_Templates::get_template( 'course-results/course-lessons.php' ); |
|
1117 | + return; |
|
1119 | 1118 | |
1120 | - } |
|
1119 | + } |
|
1121 | 1120 | |
1122 | - Sensei_Templates::get_template( 'course-results/lessons.php' ); |
|
1121 | + Sensei_Templates::get_template( 'course-results/lessons.php' ); |
|
1123 | 1122 | } |
1124 | 1123 | |
1125 | 1124 | /** |
@@ -1131,7 +1130,7 @@ discard block |
||
1131 | 1130 | */ |
1132 | 1131 | function sensei_courses_per_row(){ |
1133 | 1132 | |
1134 | - echo Sensei_Course::get_loop_number_of_columns(); |
|
1133 | + echo Sensei_Course::get_loop_number_of_columns(); |
|
1135 | 1134 | |
1136 | 1135 | } |
1137 | 1136 | |
@@ -1145,7 +1144,7 @@ discard block |
||
1145 | 1144 | */ |
1146 | 1145 | function sensei_get_template( $template_name, $args, $path ){ |
1147 | 1146 | |
1148 | - Sensei_Templates::get_template( $template_name, $args, $path ); |
|
1147 | + Sensei_Templates::get_template( $template_name, $args, $path ); |
|
1149 | 1148 | |
1150 | 1149 | } |
1151 | 1150 | |
@@ -1159,14 +1158,14 @@ discard block |
||
1159 | 1158 | */ |
1160 | 1159 | function get_the_lesson_status_class(){ |
1161 | 1160 | |
1162 | - $status_class = ''; |
|
1163 | - $lesson_completed = Sensei_Utils::user_completed_lesson( get_the_ID(), get_current_user_id() ); |
|
1161 | + $status_class = ''; |
|
1162 | + $lesson_completed = Sensei_Utils::user_completed_lesson( get_the_ID(), get_current_user_id() ); |
|
1164 | 1163 | |
1165 | - if ( $lesson_completed ) { |
|
1166 | - $status_class = 'completed'; |
|
1167 | - } |
|
1164 | + if ( $lesson_completed ) { |
|
1165 | + $status_class = 'completed'; |
|
1166 | + } |
|
1168 | 1167 | |
1169 | - return $status_class; |
|
1168 | + return $status_class; |
|
1170 | 1169 | |
1171 | 1170 | }// end get_the_lesson_status_class |
1172 | 1171 | /** |
@@ -1178,5 +1177,5 @@ discard block |
||
1178 | 1177 | */ |
1179 | 1178 | function sensei_the_lesson_status_class(){ |
1180 | 1179 | |
1181 | - echo get_the_lesson_status_class(); |
|
1180 | + echo get_the_lesson_status_class(); |
|
1182 | 1181 | } |
@@ -16,11 +16,11 @@ discard block |
||
16 | 16 | */ |
17 | 17 | public function __construct () { |
18 | 18 | |
19 | - //register admin styles |
|
19 | + //register admin styles |
|
20 | 20 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles_global' ) ); |
21 | 21 | |
22 | - //register admin scripts |
|
23 | - add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ) ); |
|
22 | + //register admin scripts |
|
23 | + add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ) ); |
|
24 | 24 | |
25 | 25 | add_action( 'admin_print_styles', array( $this, 'admin_notices_styles' ) ); |
26 | 26 | add_action( 'settings_before_form', array( $this, 'install_pages_output' ) ); |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | add_action( 'admin_head', array( $this, 'admin_menu_highlight' ) ); |
30 | 30 | add_action( 'admin_init', array( $this, 'page_redirect' ) ); |
31 | 31 | add_action( 'admin_init', array( $this, 'sensei_add_custom_menu_items' ) ); |
32 | - add_action( 'admin_init', array( __CLASS__, 'install_pages' )); |
|
32 | + add_action( 'admin_init', array( __CLASS__, 'install_pages' )); |
|
33 | 33 | |
34 | 34 | // Duplicate lesson & courses |
35 | 35 | add_filter( 'post_row_actions', array( $this, 'duplicate_action_link' ), 10, 2 ); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | |
81 | 81 | if( $menu_cap ) { |
82 | 82 | $menu[] = array( '', 'read', 'separator-sensei', '', 'wp-menu-separator sensei' ); |
83 | - add_menu_page( 'Sensei', 'Sensei', $menu_cap, 'sensei' , array( Sensei()->analysis, 'analysis_page' ) , '', '50' ); |
|
83 | + add_menu_page( 'Sensei', 'Sensei', $menu_cap, 'sensei' , array( Sensei()->analysis, 'analysis_page' ) , '', '50' ); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | add_submenu_page( 'edit.php?post_type=course', __( 'Order Courses', 'woothemes-sensei' ), __( 'Order Courses', 'woothemes-sensei' ), 'manage_sensei', 'course-order', array( $this, 'course_order_screen' ) ); |
@@ -137,14 +137,14 @@ discard block |
||
137 | 137 | $submenu_file = 'edit-tags.php?taxonomy=course-category&post_type=course'; |
138 | 138 | $parent_file = 'edit.php?post_type=course'; |
139 | 139 | |
140 | - } elseif ( $screen->base == 'edit-tags' && $taxonomy == 'module' ) { |
|
140 | + } elseif ( $screen->base == 'edit-tags' && $taxonomy == 'module' ) { |
|
141 | 141 | |
142 | - $submenu_file = 'edit-tags.php?taxonomy=module'; |
|
143 | - $parent_file = 'edit.php?post_type=course'; |
|
142 | + $submenu_file = 'edit-tags.php?taxonomy=module'; |
|
143 | + $parent_file = 'edit.php?post_type=course'; |
|
144 | 144 | |
145 | 145 | } elseif ( in_array( $screen->id, array( 'sensei_message', 'edit-sensei_message' ) ) ) { |
146 | 146 | |
147 | - $submenu_file = 'edit.php?post_type=sensei_message'; |
|
147 | + $submenu_file = 'edit.php?post_type=sensei_message'; |
|
148 | 148 | $parent_file = 'sensei'; |
149 | 149 | |
150 | 150 | } |
@@ -172,9 +172,9 @@ discard block |
||
172 | 172 | */ |
173 | 173 | function install_pages_output() { |
174 | 174 | |
175 | - if( isset($_GET['sensei_install_complete']) && 'true' == $_GET['sensei_install_complete']) { |
|
175 | + if( isset($_GET['sensei_install_complete']) && 'true' == $_GET['sensei_install_complete']) { |
|
176 | 176 | |
177 | - ?> |
|
177 | + ?> |
|
178 | 178 | <div id="message" class="updated sensei-message sensei-connect"> |
179 | 179 | <p><?php _e( '<strong>Congratulations!</strong> – Sensei has been installed and set up.', 'woothemes-sensei' ); ?></p> |
180 | 180 | <p><a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.woothemes.com/sensei/" data-text="A premium Learning Management plugin for #WordPress that helps you create courses. Beautifully." data-via="WooThemes" data-size="large" data-hashtags="Sensei">Tweet</a> |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | </div> |
183 | 183 | <?php |
184 | 184 | |
185 | - } |
|
185 | + } |
|
186 | 186 | |
187 | 187 | } // End install_pages_output() |
188 | 188 | |
@@ -201,25 +201,25 @@ discard block |
||
201 | 201 | function create_page( $slug, $page_title = '', $page_content = '', $post_parent = 0 ) { |
202 | 202 | global $wpdb; |
203 | 203 | |
204 | - $page_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s LIMIT 1;", $slug ) ); |
|
204 | + $page_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s LIMIT 1;", $slug ) ); |
|
205 | 205 | if ( $page_id ) : |
206 | 206 | return $page_id; |
207 | 207 | endif; |
208 | 208 | |
209 | 209 | $page_data = array( |
210 | - 'post_status' => 'publish', |
|
211 | - 'post_type' => 'page', |
|
212 | - 'post_author' => 1, |
|
213 | - 'post_name' => $slug, |
|
214 | - 'post_title' => $page_title, |
|
215 | - 'post_content' => $page_content, |
|
216 | - 'post_parent' => $post_parent, |
|
217 | - 'comment_status' => 'closed' |
|
218 | - ); |
|
210 | + 'post_status' => 'publish', |
|
211 | + 'post_type' => 'page', |
|
212 | + 'post_author' => 1, |
|
213 | + 'post_name' => $slug, |
|
214 | + 'post_title' => $page_title, |
|
215 | + 'post_content' => $page_content, |
|
216 | + 'post_parent' => $post_parent, |
|
217 | + 'comment_status' => 'closed' |
|
218 | + ); |
|
219 | 219 | |
220 | - $page_id = wp_insert_post( $page_data ); |
|
220 | + $page_id = wp_insert_post( $page_data ); |
|
221 | 221 | |
222 | - return $page_id; |
|
222 | + return $page_id; |
|
223 | 223 | |
224 | 224 | } // End create_page() |
225 | 225 | |
@@ -233,12 +233,12 @@ discard block |
||
233 | 233 | function create_pages() { |
234 | 234 | |
235 | 235 | // Courses page |
236 | - $new_course_page_id = $this->create_page( esc_sql( _x('courses-overview', 'page_slug', 'woothemes-sensei') ), __('Courses', 'woothemes-sensei'), '' ); |
|
237 | - Sensei()->settings->set( 'course_page', $new_course_page_id ); |
|
236 | + $new_course_page_id = $this->create_page( esc_sql( _x('courses-overview', 'page_slug', 'woothemes-sensei') ), __('Courses', 'woothemes-sensei'), '' ); |
|
237 | + Sensei()->settings->set( 'course_page', $new_course_page_id ); |
|
238 | 238 | |
239 | - // User Dashboard page |
|
240 | - $new_my_course_page_id = $this->create_page( esc_sql( _x('my-courses', 'page_slug', 'woothemes-sensei') ), __('My Courses', 'woothemes-sensei'), '[sensei_user_courses]' ); |
|
241 | - Sensei()->settings->set( 'my_course_page',$new_my_course_page_id ); |
|
239 | + // User Dashboard page |
|
240 | + $new_my_course_page_id = $this->create_page( esc_sql( _x('my-courses', 'page_slug', 'woothemes-sensei') ), __('My Courses', 'woothemes-sensei'), '[sensei_user_courses]' ); |
|
241 | + Sensei()->settings->set( 'my_course_page',$new_my_course_page_id ); |
|
242 | 242 | |
243 | 243 | } // End create_pages() |
244 | 244 | |
@@ -259,8 +259,8 @@ discard block |
||
259 | 259 | wp_register_style( 'woothemes-sensei-global', Sensei()->plugin_url . 'assets/css/global.css', '', Sensei()->version, 'screen' ); |
260 | 260 | wp_enqueue_style( 'woothemes-sensei-global' ); |
261 | 261 | |
262 | - // Select 2 styles |
|
263 | - wp_enqueue_style( 'sensei-core-select2', Sensei()->plugin_url . 'assets/css/select2/select2.css', '', Sensei()->version, 'screen' ); |
|
262 | + // Select 2 styles |
|
263 | + wp_enqueue_style( 'sensei-core-select2', Sensei()->plugin_url . 'assets/css/select2/select2.css', '', Sensei()->version, 'screen' ); |
|
264 | 264 | |
265 | 265 | // Test for Write Panel Pages |
266 | 266 | if ( ( ( isset( $post_type ) && in_array( $post_type, $allowed_post_types ) ) && ( isset( $hook ) && in_array( $hook, $allowed_post_type_pages ) ) ) || ( isset( $_GET['page'] ) && in_array( $_GET['page'], $allowed_pages ) ) ) { |
@@ -273,32 +273,32 @@ discard block |
||
273 | 273 | } // End admin_styles_global() |
274 | 274 | |
275 | 275 | |
276 | - /** |
|
277 | - * Globally register all scripts needed in admin. |
|
278 | - * |
|
279 | - * The script users should enqueue the script when needed. |
|
280 | - * |
|
281 | - * @since 1.8.2 |
|
282 | - * @access public |
|
283 | - */ |
|
284 | - public function register_scripts( $hook ){ |
|
276 | + /** |
|
277 | + * Globally register all scripts needed in admin. |
|
278 | + * |
|
279 | + * The script users should enqueue the script when needed. |
|
280 | + * |
|
281 | + * @since 1.8.2 |
|
282 | + * @access public |
|
283 | + */ |
|
284 | + public function register_scripts( $hook ){ |
|
285 | 285 | |
286 | - $screen = get_current_screen(); |
|
286 | + $screen = get_current_screen(); |
|
287 | 287 | |
288 | - // Allow developers to load non-minified versions of scripts |
|
289 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
288 | + // Allow developers to load non-minified versions of scripts |
|
289 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
290 | 290 | |
291 | - // Select2 script used to enhance all select boxes |
|
292 | - wp_register_script( 'sensei-core-select2', Sensei()->plugin_url . '/assets/js/select2/select2' . $suffix . '.js', array( 'jquery' ), Sensei()->version ); |
|
291 | + // Select2 script used to enhance all select boxes |
|
292 | + wp_register_script( 'sensei-core-select2', Sensei()->plugin_url . '/assets/js/select2/select2' . $suffix . '.js', array( 'jquery' ), Sensei()->version ); |
|
293 | 293 | |
294 | - // load edit module scripts |
|
295 | - if( 'edit-module' == $screen->id ){ |
|
294 | + // load edit module scripts |
|
295 | + if( 'edit-module' == $screen->id ){ |
|
296 | 296 | |
297 | - wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery.min.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version, true ); |
|
297 | + wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery.min.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version, true ); |
|
298 | 298 | |
299 | - } |
|
299 | + } |
|
300 | 300 | |
301 | - } |
|
301 | + } |
|
302 | 302 | |
303 | 303 | |
304 | 304 | /** |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | * @return void |
309 | 309 | */ |
310 | 310 | function admin_install_notice() { |
311 | - ?> |
|
311 | + ?> |
|
312 | 312 | <div id="message" class="updated sensei-message sensei-connect"> |
313 | 313 | |
314 | 314 | <p> |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | * @return void |
344 | 344 | */ |
345 | 345 | function admin_installed_notice() { |
346 | - ?> |
|
346 | + ?> |
|
347 | 347 | <div id="message" class="updated sensei-message sensei-connect"> |
348 | 348 | |
349 | 349 | <p> |
@@ -371,8 +371,8 @@ discard block |
||
371 | 371 | </div> |
372 | 372 | <?php |
373 | 373 | |
374 | - // Set installed option |
|
375 | - update_option('sensei_installed', 0); |
|
374 | + // Set installed option |
|
375 | + update_option('sensei_installed', 0); |
|
376 | 376 | } // End admin_installed_notice() |
377 | 377 | |
378 | 378 | |
@@ -404,21 +404,21 @@ discard block |
||
404 | 404 | function admin_notices_styles() { |
405 | 405 | |
406 | 406 | // Installed notices |
407 | - if ( 1 == get_option( 'sensei_installed' ) ) { |
|
407 | + if ( 1 == get_option( 'sensei_installed' ) ) { |
|
408 | 408 | |
409 | - wp_enqueue_style( 'sensei-activation', plugins_url( '/assets/css/activation.css', dirname( __FILE__ ) ), '', Sensei()->version ); |
|
409 | + wp_enqueue_style( 'sensei-activation', plugins_url( '/assets/css/activation.css', dirname( __FILE__ ) ), '', Sensei()->version ); |
|
410 | 410 | |
411 | - if (get_option('skip_install_sensei_pages')!=1 && Sensei()->get_page_id('course')<1 && !isset($_GET['install_sensei_pages']) && !isset($_GET['skip_install_sensei_pages'])) { |
|
412 | - add_action( 'admin_notices', array( $this, 'admin_install_notice' ) ); |
|
413 | - } elseif ( !isset($_GET['page']) || $_GET['page']!='woothemes-sensei-settings' ) { |
|
414 | - add_action( 'admin_notices', array( $this, 'admin_installed_notice' ) ); |
|
415 | - } // End If Statement |
|
411 | + if (get_option('skip_install_sensei_pages')!=1 && Sensei()->get_page_id('course')<1 && !isset($_GET['install_sensei_pages']) && !isset($_GET['skip_install_sensei_pages'])) { |
|
412 | + add_action( 'admin_notices', array( $this, 'admin_install_notice' ) ); |
|
413 | + } elseif ( !isset($_GET['page']) || $_GET['page']!='woothemes-sensei-settings' ) { |
|
414 | + add_action( 'admin_notices', array( $this, 'admin_installed_notice' ) ); |
|
415 | + } // End If Statement |
|
416 | 416 | |
417 | - } // End If Statement |
|
417 | + } // End If Statement |
|
418 | 418 | |
419 | - if ( Sensei_Language_Pack_Manager::has_language_pack_available() ) { |
|
420 | - add_action( 'admin_notices', array( $this, 'language_pack_install_notice' ) ); |
|
421 | - } |
|
419 | + if ( Sensei_Language_Pack_Manager::has_language_pack_available() ) { |
|
420 | + add_action( 'admin_notices', array( $this, 'language_pack_install_notice' ) ); |
|
421 | + } |
|
422 | 422 | |
423 | 423 | } // End admin_notices_styles() |
424 | 424 | |
@@ -534,30 +534,30 @@ discard block |
||
534 | 534 | */ |
535 | 535 | private function duplicate_lesson_quizzes( $old_lesson_id, $new_lesson_id ) { |
536 | 536 | |
537 | - $old_quiz_id = Sensei()->lesson->lesson_quizzes( $old_lesson_id ); |
|
538 | - $old_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $old_quiz_id ); |
|
537 | + $old_quiz_id = Sensei()->lesson->lesson_quizzes( $old_lesson_id ); |
|
538 | + $old_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $old_quiz_id ); |
|
539 | 539 | |
540 | - // duplicate the generic wp post information |
|
540 | + // duplicate the generic wp post information |
|
541 | 541 | $new_quiz = $this->duplicate_post( get_post( $old_quiz_id ), '' ); |
542 | 542 | |
543 | 543 | //update the new lesson data |
544 | - add_post_meta( $new_lesson_id, '_lesson_quiz', $new_quiz->ID ); |
|
544 | + add_post_meta( $new_lesson_id, '_lesson_quiz', $new_quiz->ID ); |
|
545 | 545 | |
546 | 546 | //update the new quiz data |
547 | - add_post_meta( $new_quiz->ID, '_quiz_lesson', $new_lesson_id ); |
|
548 | - wp_update_post( |
|
549 | - array( |
|
550 | - 'ID' => $new_quiz->ID, |
|
551 | - 'post_parent' => $new_lesson_id |
|
552 | - ) |
|
553 | - ); |
|
547 | + add_post_meta( $new_quiz->ID, '_quiz_lesson', $new_lesson_id ); |
|
548 | + wp_update_post( |
|
549 | + array( |
|
550 | + 'ID' => $new_quiz->ID, |
|
551 | + 'post_parent' => $new_lesson_id |
|
552 | + ) |
|
553 | + ); |
|
554 | 554 | |
555 | 555 | foreach( $old_quiz_questions as $question ) { |
556 | 556 | |
557 | 557 | // copy the question order over to the new quiz |
558 | 558 | $old_question_order = get_post_meta( $question->ID, '_quiz_question_order'. $old_quiz_id, true ); |
559 | - $new_question_order = str_ireplace( $old_quiz_id, $new_quiz->ID , $old_question_order ); |
|
560 | - add_post_meta( $question->ID, '_quiz_question_order' . $new_quiz->ID, $new_question_order ); |
|
559 | + $new_question_order = str_ireplace( $old_quiz_id, $new_quiz->ID , $old_question_order ); |
|
560 | + add_post_meta( $question->ID, '_quiz_question_order' . $new_quiz->ID, $new_question_order ); |
|
561 | 561 | |
562 | 562 | // Add question to quiz |
563 | 563 | add_post_meta( $question->ID, '_quiz_id', $new_quiz->ID, false ); |
@@ -879,21 +879,21 @@ discard block |
||
879 | 879 | break; |
880 | 880 | |
881 | 881 | case 'checkbox': |
882 | - //backwards compatibility |
|
883 | - if( empty( $data ) || 'on' == $data ){ |
|
884 | - $checked_value = 'on'; |
|
885 | - }elseif( 'yes' == $data ) { |
|
882 | + //backwards compatibility |
|
883 | + if( empty( $data ) || 'on' == $data ){ |
|
884 | + $checked_value = 'on'; |
|
885 | + }elseif( 'yes' == $data ) { |
|
886 | 886 | |
887 | - $checked_value = 'yes'; |
|
887 | + $checked_value = 'yes'; |
|
888 | 888 | |
889 | - }elseif( 'auto' == $data ) { |
|
889 | + }elseif( 'auto' == $data ) { |
|
890 | 890 | |
891 | - $checked_value = 'auto'; |
|
891 | + $checked_value = 'auto'; |
|
892 | 892 | |
893 | - } else { |
|
894 | - $checked_value = 1; |
|
895 | - $data = intval( $data ); |
|
896 | - } |
|
893 | + } else { |
|
894 | + $checked_value = 1; |
|
895 | + $data = intval( $data ); |
|
896 | + } |
|
897 | 897 | $checked = checked( $checked_value, $data, false ); |
898 | 898 | $html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $field['id'] ) . '" ' . $checked . ' ' . $disabled . '/>' . "\n"; |
899 | 899 | break; |
@@ -997,26 +997,26 @@ discard block |
||
997 | 997 | |
998 | 998 | if( 0 < count( $courses ) ) { |
999 | 999 | |
1000 | - // order the courses as set by the users |
|
1001 | - $all_course_ids = array(); |
|
1002 | - foreach( $courses as $course ){ |
|
1000 | + // order the courses as set by the users |
|
1001 | + $all_course_ids = array(); |
|
1002 | + foreach( $courses as $course ){ |
|
1003 | 1003 | |
1004 | - $all_course_ids[] = (string)$course->ID; |
|
1004 | + $all_course_ids[] = (string)$course->ID; |
|
1005 | 1005 | |
1006 | - } |
|
1007 | - $order_string = $this->get_course_order(); |
|
1006 | + } |
|
1007 | + $order_string = $this->get_course_order(); |
|
1008 | 1008 | |
1009 | - if( !empty( $order_string ) ){ |
|
1010 | - $ordered_course_ids = explode(',' , $order_string ); |
|
1011 | - $all_course_ids = array_unique( array_merge( $ordered_course_ids , $all_course_ids ) ); |
|
1012 | - } |
|
1009 | + if( !empty( $order_string ) ){ |
|
1010 | + $ordered_course_ids = explode(',' , $order_string ); |
|
1011 | + $all_course_ids = array_unique( array_merge( $ordered_course_ids , $all_course_ids ) ); |
|
1012 | + } |
|
1013 | 1013 | |
1014 | 1014 | |
1015 | 1015 | $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n"; |
1016 | 1016 | $html .= '<ul class="sortable-course-list">' . "\n"; |
1017 | 1017 | $count = 0; |
1018 | 1018 | foreach ( $all_course_ids as $course_id ) { |
1019 | - $course = get_post( $course_id ); |
|
1019 | + $course = get_post( $course_id ); |
|
1020 | 1020 | $count++; |
1021 | 1021 | $class = 'course'; |
1022 | 1022 | if ( $count == 1 ) { $class .= ' first'; } |
@@ -1131,73 +1131,73 @@ discard block |
||
1131 | 1131 | |
1132 | 1132 | $displayed_lessons = array(); |
1133 | 1133 | |
1134 | - $modules = Sensei()->modules->get_course_modules( intval( $course_id ) ); |
|
1135 | - |
|
1136 | - foreach( $modules as $module ) { |
|
1137 | - |
|
1138 | - $args = array( |
|
1139 | - 'post_type' => 'lesson', |
|
1140 | - 'post_status' => 'publish', |
|
1141 | - 'posts_per_page' => -1, |
|
1142 | - 'meta_query' => array( |
|
1143 | - array( |
|
1144 | - 'key' => '_lesson_course', |
|
1145 | - 'value' => intval( $course_id ), |
|
1146 | - 'compare' => '=' |
|
1147 | - ) |
|
1148 | - ), |
|
1149 | - 'tax_query' => array( |
|
1150 | - array( |
|
1151 | - 'taxonomy' => Sensei()->modules->taxonomy, |
|
1152 | - 'field' => 'id', |
|
1153 | - 'terms' => intval( $module->term_id ) |
|
1154 | - ) |
|
1155 | - ), |
|
1156 | - 'meta_key' => '_order_module_' . $module->term_id, |
|
1157 | - 'orderby' => 'meta_value_num date', |
|
1158 | - 'order' => 'ASC', |
|
1159 | - 'suppress_filters' => 0 |
|
1160 | - ); |
|
1161 | - |
|
1162 | - $lessons = get_posts( $args ); |
|
1163 | - |
|
1164 | - if( count( $lessons ) > 0 ) { |
|
1165 | - $html .= '<h3>' . $module->name . '</h3>' . "\n"; |
|
1166 | - $html .= '<ul class="sortable-lesson-list" data-module_id="' . $module->term_id . '">' . "\n"; |
|
1167 | - |
|
1168 | - $count = 0; |
|
1169 | - foreach( $lessons as $lesson ) { |
|
1170 | - $count++; |
|
1171 | - $class = 'lesson'; |
|
1172 | - if ( $count == 1 ) { $class .= ' first'; } |
|
1173 | - if ( $count == count( $lesson ) ) { $class .= ' last'; } |
|
1174 | - if ( $count % 2 != 0 ) { |
|
1175 | - $class .= ' alternate'; |
|
1176 | - } |
|
1177 | - |
|
1178 | - $html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $lesson->ID ) . '" style="width: 100%;"> ' . $lesson->post_title . '</span></li>' . "\n"; |
|
1179 | - |
|
1180 | - $displayed_lessons[] = $lesson->ID; |
|
1181 | - } |
|
1182 | - |
|
1183 | - $html .= '</ul>' . "\n"; |
|
1184 | - |
|
1185 | - $html .= '<input type="hidden" name="lesson-order-module-' . $module->term_id . '" value="" />' . "\n"; |
|
1186 | - } |
|
1187 | - } |
|
1188 | - |
|
1189 | - |
|
1190 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
1134 | + $modules = Sensei()->modules->get_course_modules( intval( $course_id ) ); |
|
1135 | + |
|
1136 | + foreach( $modules as $module ) { |
|
1137 | + |
|
1138 | + $args = array( |
|
1139 | + 'post_type' => 'lesson', |
|
1140 | + 'post_status' => 'publish', |
|
1141 | + 'posts_per_page' => -1, |
|
1142 | + 'meta_query' => array( |
|
1143 | + array( |
|
1144 | + 'key' => '_lesson_course', |
|
1145 | + 'value' => intval( $course_id ), |
|
1146 | + 'compare' => '=' |
|
1147 | + ) |
|
1148 | + ), |
|
1149 | + 'tax_query' => array( |
|
1150 | + array( |
|
1151 | + 'taxonomy' => Sensei()->modules->taxonomy, |
|
1152 | + 'field' => 'id', |
|
1153 | + 'terms' => intval( $module->term_id ) |
|
1154 | + ) |
|
1155 | + ), |
|
1156 | + 'meta_key' => '_order_module_' . $module->term_id, |
|
1157 | + 'orderby' => 'meta_value_num date', |
|
1158 | + 'order' => 'ASC', |
|
1159 | + 'suppress_filters' => 0 |
|
1160 | + ); |
|
1161 | + |
|
1162 | + $lessons = get_posts( $args ); |
|
1163 | + |
|
1164 | + if( count( $lessons ) > 0 ) { |
|
1165 | + $html .= '<h3>' . $module->name . '</h3>' . "\n"; |
|
1166 | + $html .= '<ul class="sortable-lesson-list" data-module_id="' . $module->term_id . '">' . "\n"; |
|
1167 | + |
|
1168 | + $count = 0; |
|
1169 | + foreach( $lessons as $lesson ) { |
|
1170 | + $count++; |
|
1171 | + $class = 'lesson'; |
|
1172 | + if ( $count == 1 ) { $class .= ' first'; } |
|
1173 | + if ( $count == count( $lesson ) ) { $class .= ' last'; } |
|
1174 | + if ( $count % 2 != 0 ) { |
|
1175 | + $class .= ' alternate'; |
|
1176 | + } |
|
1177 | + |
|
1178 | + $html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $lesson->ID ) . '" style="width: 100%;"> ' . $lesson->post_title . '</span></li>' . "\n"; |
|
1179 | + |
|
1180 | + $displayed_lessons[] = $lesson->ID; |
|
1181 | + } |
|
1182 | + |
|
1183 | + $html .= '</ul>' . "\n"; |
|
1184 | + |
|
1185 | + $html .= '<input type="hidden" name="lesson-order-module-' . $module->term_id . '" value="" />' . "\n"; |
|
1186 | + } |
|
1187 | + } |
|
1188 | + |
|
1189 | + |
|
1190 | + $lessons = Sensei()->course->course_lessons( $course_id ); |
|
1191 | 1191 | |
1192 | 1192 | if( 0 < count( $lessons ) ) { |
1193 | 1193 | |
1194 | - //get module term ids, will be used to exclude lessons |
|
1195 | - $module_items_ids = array(); |
|
1196 | - if( ! empty( $modules ) ) { |
|
1197 | - foreach ($modules as $module) { |
|
1198 | - $module_items_ids[] = $module->term_id; |
|
1199 | - } |
|
1200 | - } |
|
1194 | + //get module term ids, will be used to exclude lessons |
|
1195 | + $module_items_ids = array(); |
|
1196 | + if( ! empty( $modules ) ) { |
|
1197 | + foreach ($modules as $module) { |
|
1198 | + $module_items_ids[] = $module->term_id; |
|
1199 | + } |
|
1200 | + } |
|
1201 | 1201 | |
1202 | 1202 | if( 0 < count( $displayed_lessons ) ) { |
1203 | 1203 | $html .= '<h3>' . __( 'Other Lessons', 'woothemes-sensei' ) . '</h3>' . "\n"; |
@@ -1207,13 +1207,13 @@ discard block |
||
1207 | 1207 | $count = 0; |
1208 | 1208 | foreach ( $lessons as $lesson ) { |
1209 | 1209 | |
1210 | - // if lesson belongs to one fo the course modules then exclude it here |
|
1211 | - // as it is listed above |
|
1212 | - if( has_term( $module_items_ids, 'module', $lesson->ID ) ){ |
|
1210 | + // if lesson belongs to one fo the course modules then exclude it here |
|
1211 | + // as it is listed above |
|
1212 | + if( has_term( $module_items_ids, 'module', $lesson->ID ) ){ |
|
1213 | 1213 | |
1214 | - continue; |
|
1214 | + continue; |
|
1215 | 1215 | |
1216 | - } |
|
1216 | + } |
|
1217 | 1217 | |
1218 | 1218 | $count++; |
1219 | 1219 | $class = 'lesson'; |
@@ -1257,28 +1257,28 @@ discard block |
||
1257 | 1257 | |
1258 | 1258 | if( $course_id ) { |
1259 | 1259 | |
1260 | - $modules = Sensei()->modules->get_course_modules( intval( $course_id ) ); |
|
1260 | + $modules = Sensei()->modules->get_course_modules( intval( $course_id ) ); |
|
1261 | 1261 | |
1262 | - foreach( $modules as $module ) { |
|
1262 | + foreach( $modules as $module ) { |
|
1263 | 1263 | |
1264 | 1264 | |
1265 | - if( isset( $_POST[ 'lesson-order-module-' . $module->term_id ] ) |
|
1266 | - && $_POST[ 'lesson-order-module-' . $module->term_id ] ) { |
|
1265 | + if( isset( $_POST[ 'lesson-order-module-' . $module->term_id ] ) |
|
1266 | + && $_POST[ 'lesson-order-module-' . $module->term_id ] ) { |
|
1267 | 1267 | |
1268 | - $order = explode( ',', $_POST[ 'lesson-order-module-' . $module->term_id ] ); |
|
1269 | - $i = 1; |
|
1270 | - foreach( $order as $lesson_id ) { |
|
1268 | + $order = explode( ',', $_POST[ 'lesson-order-module-' . $module->term_id ] ); |
|
1269 | + $i = 1; |
|
1270 | + foreach( $order as $lesson_id ) { |
|
1271 | 1271 | |
1272 | - if( $lesson_id ) { |
|
1273 | - update_post_meta( $lesson_id, '_order_module_' . $module->term_id, $i ); |
|
1274 | - ++$i; |
|
1275 | - } |
|
1272 | + if( $lesson_id ) { |
|
1273 | + update_post_meta( $lesson_id, '_order_module_' . $module->term_id, $i ); |
|
1274 | + ++$i; |
|
1275 | + } |
|
1276 | 1276 | |
1277 | - }// end for each order |
|
1277 | + }// end for each order |
|
1278 | 1278 | |
1279 | - }// end if |
|
1279 | + }// end if |
|
1280 | 1280 | |
1281 | - } // end for each modules |
|
1281 | + } // end for each modules |
|
1282 | 1282 | |
1283 | 1283 | |
1284 | 1284 | if( $order_string ) { |
@@ -1361,47 +1361,47 @@ discard block |
||
1361 | 1361 | |
1362 | 1362 | /** |
1363 | 1363 | * Adding admin notice if the current |
1364 | - * installed theme is not compatible |
|
1365 | - * |
|
1364 | + * installed theme is not compatible |
|
1365 | + * |
|
1366 | 1366 | * @return void |
1367 | 1367 | */ |
1368 | 1368 | public function theme_compatibility_notices() { |
1369 | 1369 | |
1370 | - if( isset( $_GET['sensei_hide_notice'] ) ) { |
|
1371 | - switch( esc_attr( $_GET['sensei_hide_notice'] ) ) { |
|
1370 | + if( isset( $_GET['sensei_hide_notice'] ) ) { |
|
1371 | + switch( esc_attr( $_GET['sensei_hide_notice'] ) ) { |
|
1372 | 1372 | case 'menu_settings': add_user_meta( get_current_user_id(), 'sensei_hide_menu_settings_notice', true ); break; |
1373 | 1373 | case 'theme_check': add_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true ); break; |
1374 | 1374 | } |
1375 | - } |
|
1375 | + } |
|
1376 | 1376 | |
1377 | - // white list templates that are already support by default and do not show notice for them |
|
1378 | - $template = get_option( 'template' ); |
|
1377 | + // white list templates that are already support by default and do not show notice for them |
|
1378 | + $template = get_option( 'template' ); |
|
1379 | 1379 | |
1380 | - $white_list = array( 'twentyeleven', |
|
1381 | - 'twentytwelve', |
|
1382 | - 'twentyfourteen', |
|
1383 | - 'twentyfifteen', |
|
1384 | - 'twentysixteen', |
|
1385 | - 'storefront', |
|
1386 | - ); |
|
1380 | + $white_list = array( 'twentyeleven', |
|
1381 | + 'twentytwelve', |
|
1382 | + 'twentyfourteen', |
|
1383 | + 'twentyfifteen', |
|
1384 | + 'twentysixteen', |
|
1385 | + 'storefront', |
|
1386 | + ); |
|
1387 | 1387 | |
1388 | - if ( in_array( $template, $white_list ) ) { |
|
1388 | + if ( in_array( $template, $white_list ) ) { |
|
1389 | 1389 | |
1390 | - return; |
|
1390 | + return; |
|
1391 | 1391 | |
1392 | - } |
|
1392 | + } |
|
1393 | 1393 | |
1394 | - // don't show the notice if the user chose to hide it |
|
1395 | - $hide_theme_check_notice = get_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true ); |
|
1396 | - if( $hide_theme_check_notice ) { |
|
1394 | + // don't show the notice if the user chose to hide it |
|
1395 | + $hide_theme_check_notice = get_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true ); |
|
1396 | + if( $hide_theme_check_notice ) { |
|
1397 | 1397 | |
1398 | - return; |
|
1398 | + return; |
|
1399 | 1399 | |
1400 | - } |
|
1400 | + } |
|
1401 | 1401 | |
1402 | - // show the notice for themes not supporting sensei |
|
1403 | - if ( ! current_theme_supports( 'sensei' ) ) { |
|
1404 | - ?> |
|
1402 | + // show the notice for themes not supporting sensei |
|
1403 | + if ( ! current_theme_supports( 'sensei' ) ) { |
|
1404 | + ?> |
|
1405 | 1405 | |
1406 | 1406 | <div id="message" class="error sensei-message sensei-connect"> |
1407 | 1407 | <p> |
@@ -1437,7 +1437,7 @@ discard block |
||
1437 | 1437 | public function reset_theme_check_notices() { |
1438 | 1438 | global $current_user; |
1439 | 1439 | wp_get_current_user(); |
1440 | - $user_id = $current_user->ID; |
|
1440 | + $user_id = $current_user->ID; |
|
1441 | 1441 | |
1442 | 1442 | delete_user_meta( $user_id, 'sensei_hide_theme_check_notice' ); |
1443 | 1443 | } |
@@ -1457,62 +1457,62 @@ discard block |
||
1457 | 1457 | return $prevent_access; |
1458 | 1458 | } |
1459 | 1459 | |
1460 | - /** |
|
1461 | - * Hooked onto admin_init. Listens for install_sensei_pages and skip_install_sensei_pages query args |
|
1462 | - * on the sensei settings page. |
|
1463 | - * |
|
1464 | - * The function |
|
1465 | - * |
|
1466 | - * @since 1.8.7 |
|
1467 | - */ |
|
1468 | - public static function install_pages(){ |
|
1460 | + /** |
|
1461 | + * Hooked onto admin_init. Listens for install_sensei_pages and skip_install_sensei_pages query args |
|
1462 | + * on the sensei settings page. |
|
1463 | + * |
|
1464 | + * The function |
|
1465 | + * |
|
1466 | + * @since 1.8.7 |
|
1467 | + */ |
|
1468 | + public static function install_pages(){ |
|
1469 | 1469 | |
1470 | - // only fire on the settings page |
|
1471 | - if( ! isset( $_GET['page'] ) |
|
1472 | - || 'woothemes-sensei-settings' != $_GET['page'] |
|
1473 | - || 1 == get_option('skip_install_sensei_pages') ){ |
|
1470 | + // only fire on the settings page |
|
1471 | + if( ! isset( $_GET['page'] ) |
|
1472 | + || 'woothemes-sensei-settings' != $_GET['page'] |
|
1473 | + || 1 == get_option('skip_install_sensei_pages') ){ |
|
1474 | 1474 | |
1475 | - return; |
|
1475 | + return; |
|
1476 | 1476 | |
1477 | - } |
|
1477 | + } |
|
1478 | 1478 | |
1479 | - // Install/page installer |
|
1480 | - $install_complete = false; |
|
1479 | + // Install/page installer |
|
1480 | + $install_complete = false; |
|
1481 | 1481 | |
1482 | - // Add pages button |
|
1483 | - $settings_url = ''; |
|
1484 | - if (isset($_GET['install_sensei_pages']) && $_GET['install_sensei_pages']) { |
|
1482 | + // Add pages button |
|
1483 | + $settings_url = ''; |
|
1484 | + if (isset($_GET['install_sensei_pages']) && $_GET['install_sensei_pages']) { |
|
1485 | 1485 | |
1486 | - Sensei()->admin->create_pages(); |
|
1486 | + Sensei()->admin->create_pages(); |
|
1487 | 1487 | |
1488 | - update_option('skip_install_sensei_pages', 1); |
|
1488 | + update_option('skip_install_sensei_pages', 1); |
|
1489 | 1489 | |
1490 | - $install_complete = true; |
|
1491 | - $settings_url = remove_query_arg('install_sensei_pages'); |
|
1490 | + $install_complete = true; |
|
1491 | + $settings_url = remove_query_arg('install_sensei_pages'); |
|
1492 | 1492 | |
1493 | - // Skip button |
|
1494 | - } elseif (isset($_GET['skip_install_sensei_pages']) && $_GET['skip_install_sensei_pages']) { |
|
1493 | + // Skip button |
|
1494 | + } elseif (isset($_GET['skip_install_sensei_pages']) && $_GET['skip_install_sensei_pages']) { |
|
1495 | 1495 | |
1496 | - update_option('skip_install_sensei_pages', 1); |
|
1497 | - $install_complete = true; |
|
1498 | - $settings_url = remove_query_arg('skip_install_sensei_pages'); |
|
1496 | + update_option('skip_install_sensei_pages', 1); |
|
1497 | + $install_complete = true; |
|
1498 | + $settings_url = remove_query_arg('skip_install_sensei_pages'); |
|
1499 | 1499 | |
1500 | - } |
|
1500 | + } |
|
1501 | 1501 | |
1502 | - if ($install_complete) { |
|
1502 | + if ($install_complete) { |
|
1503 | 1503 | |
1504 | - // refresh the rewrite rules on init |
|
1505 | - update_option('sensei_flush_rewrite_rules', '1'); |
|
1504 | + // refresh the rewrite rules on init |
|
1505 | + update_option('sensei_flush_rewrite_rules', '1'); |
|
1506 | 1506 | |
1507 | - // Set installed option |
|
1508 | - update_option('sensei_installed', 0); |
|
1507 | + // Set installed option |
|
1508 | + update_option('sensei_installed', 0); |
|
1509 | 1509 | |
1510 | - $complete_url = add_query_arg( 'sensei_install_complete', 'true', $settings_url ); |
|
1511 | - wp_redirect( $complete_url ); |
|
1510 | + $complete_url = add_query_arg( 'sensei_install_complete', 'true', $settings_url ); |
|
1511 | + wp_redirect( $complete_url ); |
|
1512 | 1512 | |
1513 | - } |
|
1513 | + } |
|
1514 | 1514 | |
1515 | - }// end install_pages |
|
1515 | + }// end install_pages |
|
1516 | 1516 | |
1517 | 1517 | } // End Class |
1518 | 1518 |