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.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / includes / tutor-general-functions.php
tutor / includes Last commit date
theme-compatibility 6 years ago tutor-general-functions.php 6 years ago tutor-template-functions.php 6 years ago tutor-template-hook.php 6 years ago
tutor-general-functions.php
541 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) )
4 exit;
5
6 /**
7 * Tutor general Functions
8 */
9
10 if ( ! function_exists('tutor_withdrawal_methods')){
11 function tutor_withdrawal_methods(){
12 $withdraw = new \TUTOR\Withdraw();
13
14 return $withdraw->available_withdraw_methods;
15 }
16 }
17
18 if ( ! function_exists('tutor_placeholder_img_src')) {
19 function tutor_placeholder_img_src() {
20 $src = tutor()->url . 'assets/images/placeholder.jpg';
21 return apply_filters( 'tutor_placeholder_img_src', $src );
22 }
23 }
24
25 /**
26 * @return string
27 *
28 * Get course categories selecting UI
29 *
30 * @since v.1.3.4
31 */
32
33 if ( ! function_exists('tutor_course_categories_dropdown')){
34 function tutor_course_categories_dropdown($post_ID = 0, $args = array()){
35
36 $default = array(
37 'classes' => '',
38 'name' => 'tax_input[course-category]',
39 'multiple' => true,
40 );
41
42 $args = apply_filters('tutor_course_categories_dropdown_args', array_merge($default, $args));
43
44 $multiple_select = '';
45
46 if (tutor_utils()->array_get('multiple', $args)){
47 if (isset($args['name'])){
48 $args['name'] = $args['name'].'[]';
49 }
50 $multiple_select = "multiple='multiple'";
51 }
52
53 extract($args);
54
55 $classes = (array) $classes;
56 $classes = implode(' ', $classes);
57
58 $categories = tutor_utils()->get_course_categories();
59
60 $output = '';
61 $output .= "<select name='{$name}' {$multiple_select} class='{$classes}' data-placeholder='". __('Search Course Category. ex. Design, Development, Business', 'tutor') ."'>";
62 $output .= "<option value=''>". __('Select a category', 'tutor') ."</option>";
63 $output .= _generate_categories_dropdown_option($post_ID, $categories, $args);
64 $output .= "</select>";
65
66 return $output;
67 }
68 }
69
70 /**
71 * @param $categories
72 * @param string $parent_name
73 *
74 * @return string
75 *
76 * Get selecting options, recursive supports
77 *
78 * @since v.1.3.4
79 */
80
81 if ( ! function_exists('_generate_categories_dropdown_option')){
82 function _generate_categories_dropdown_option($post_ID = 0, $categories, $args = array(), $depth = 0){
83 $output = '';
84
85 if (tutor_utils()->count($categories)) {
86 foreach ( $categories as $category_id => $category ) {
87 if ( ! $category->parent){
88 $depth = 0;
89 }
90
91 $childrens = tutor_utils()->array_get( 'children', $category );
92 $has_in_term = has_term( $category->term_id, 'course-category', $post_ID );
93
94 $depth_seperator = '';
95 if ($depth){
96 for ($depth_i = 0; $depth_i < $depth; $depth_i++){
97 $depth_seperator.='-';
98 }
99 }
100
101 $output .= "<option value='{$category->term_id}' ".selected($has_in_term, true, false)." > {$depth_seperator} {$category->name}</option> ";
102
103 if ( tutor_utils()->count( $childrens ) ) {
104 $depth++;
105 $output .= _generate_categories_dropdown_option($post_ID,$childrens, $args, $depth);
106 }
107 }
108 }
109 return $output;
110 }
111 }
112
113 /**
114 * @param array $args
115 *
116 * @return string
117 *
118 * Generate course categories checkbox
119 * @since v.1.3.4
120 */
121
122 if ( ! function_exists('tutor_course_categories_checkbox')){
123 function tutor_course_categories_checkbox($post_ID = 0, $args = array()){
124 $default = array(
125 'name' => 'tax_input[course-category]',
126 );
127
128 $args = apply_filters('tutor_course_categories_checkbox_args', array_merge($default, $args));
129
130 if (isset($args['name'])){
131 $args['name'] = $args['name'].'[]';
132 }
133
134 extract($args);
135
136 $categories = tutor_utils()->get_course_categories();
137 $output = '';
138 $output .= __tutor_generate_categories_checkbox($post_ID, $categories, $args);
139
140 return $output;
141 }
142 }
143
144 /**
145 * @param $categories
146 * @param string $parent_name
147 * @param array $args
148 *
149 * @return string
150 *
151 * Internal function to generate course categories checkbox
152 *
153 * @since v.1.3.4
154 */
155 if ( ! function_exists('__tutor_generate_categories_checkbox')){
156 function __tutor_generate_categories_checkbox($post_ID = 0, $categories, $args = array()){
157 $output = '';
158 $input_name = tutor_utils()->array_get('name', $args);
159
160 if (tutor_utils()->count($categories)) {
161 $output .= "<ul class='tax-input-course-category'>";
162 foreach ( $categories as $category_id => $category ) {
163 $childrens = tutor_utils()->array_get( 'children', $category );
164 $has_in_term = has_term( $category->term_id, 'course-category', $post_ID );
165
166 $output .= "<li class='tax-input-course-category-item tax-input-course-category-item-{$category->term_id} '><label class='course-category-checkbox'> <input type='checkbox' name='{$input_name}' value='{$category->term_id}' ".checked($has_in_term, true, false)." /> <span>{$category->name}</span> </label>";
167
168 if ( tutor_utils()->count( $childrens ) ) {
169 $output .= __tutor_generate_categories_checkbox($post_ID,$childrens, $args);
170 }
171 $output .= " </li>";
172 }
173 $output .= "</ul>";
174 }
175 return $output;
176 }
177 }
178
179 /**
180 * @param string $content
181 * @param string $title
182 *
183 * @return string
184 *
185 * Wrap course builder sections within div for frontend
186 *
187 * @since v.1.3.4
188 */
189
190 if ( ! function_exists('course_builder_section_wrap')) {
191 function course_builder_section_wrap( $content = '', $title = '', $echo = true ) {
192 ob_start();
193 ?>
194 <div class="tutor-course-builder-section">
195 <div class="tutor-course-builder-section-title">
196 <h3><i class="tutor-icon-down"></i> <span><?php echo $title; ?></span></h3>
197 </div>
198 <div class="tutor-course-builder-section-content">
199 <?php echo $content; ?>
200 </div>
201 </div>
202 <?php
203 $html = ob_get_clean();
204
205 if ($echo){
206 echo $html;
207 }else{
208 return $html;
209 }
210 }
211 }
212
213
214 if ( ! function_exists('get_tutor_header')){
215 function get_tutor_header($fullScreen = false){
216 $enable_spotlight_mode = tutor_utils()->get_option('enable_spotlight_mode');
217
218 if ($enable_spotlight_mode || $fullScreen){
219 ?>
220 <!doctype html>
221 <html <?php language_attributes(); ?>>
222 <head>
223 <meta charset="<?php bloginfo( 'charset' ); ?>" />
224 <meta name="viewport" content="width=device-width, initial-scale=1" />
225 <link rel="profile" href="https://gmpg.org/xfn/11" />
226 <?php wp_head(); ?>
227 </head>
228 <body <?php body_class(); ?>>
229 <div id="tutor-page-wrap" class="tutor-site-wrap site">
230 <?php
231 }else{
232 get_header();
233 }
234
235 }
236 }
237
238 if (! function_exists('get_tutor_footer')){
239 function get_tutor_footer($fullScreen = false){
240 $enable_spotlight_mode = tutor_utils()->get_option('enable_spotlight_mode');
241 if ($enable_spotlight_mode || $fullScreen){
242 ?>
243 </div>
244 <?php wp_footer(); ?>
245
246 </body>
247 </html>
248 <?php
249 }else{
250 get_footer();
251 }
252 }
253 }
254
255 /**
256 * @param int $parent_id
257 * @param array $level_categories
258 *
259 * Generate Courses categories for Paid Memberships Pro
260 *
261 * @since v.1.3.6
262 */
263 if ( ! function_exists('generate_categories_for_pmpro')) {
264 function generate_categories_for_pmpro( $parent_id = 0, $level_categories = array() ) {
265 $args = array(
266 'taxonomy' => 'course-category',
267 'parent' => $parent_id,
268 'hide_empty' => false,
269 );
270 $cats = get_categories( apply_filters( 'course_categories_pmpro_args', $args ) );
271 if ( $cats ) {
272 foreach ( $cats as $cat ) {
273 $name = 'membershipcategory_' . $cat->term_id;
274 if ( ! empty( $level_categories ) ) {
275 $checked = checked( in_array( $cat->term_id, $level_categories ), true, false );
276 } else {
277 $checked = '';
278 }
279 echo "<ul><li class=membershipcategory><input type=checkbox name={$name} id={$name} value=yes {$checked}><label for={$name}>{$cat->name}</label>";
280 generate_categories_for_pmpro( $cat->term_id, $level_categories );
281 echo '</li></ul>';
282 }
283 }
284 }
285 }
286
287 /**
288 * @param null $key
289 * @param bool $default
290 *
291 * @return array|bool|mixed
292 *
293 * Get tutor option by this helper function
294 *
295 * @since v.1.3.6
296 */
297 if ( ! function_exists('get_tutor_option')){
298 function get_tutor_option($key = null, $default = false){
299 return tutils()->get_option($key, $default);
300 }
301 }
302
303 /**
304 * @param null $key
305 * @param bool $value
306 *
307 * Update tutor option by this helper function
308 *
309 * @since v.1.3.6
310 */
311 if ( ! function_exists('update_tutor_option')){
312 function update_tutor_option($key = null, $value = false){
313 tutils()->update_option($key, $value);
314 }
315 }
316 /**
317 * @param int $course_id
318 * @param null $key
319 * @param bool $default
320 *
321 * @return array|bool|mixed
322 *
323 * Get tutor course settings by course ID
324 *
325 * @since v.1.4.1
326 */
327 if ( ! function_exists('get_tutor_course_settings')) {
328 function get_tutor_course_settings( $course_id = 0, $key = null, $default = false ) {
329 return tutils()->get_course_settings( $course_id, $key, $default );
330 }
331 }
332
333 /**
334 * @param int $lesson_id
335 * @param null $key
336 * @param bool $default
337 *
338 * @return array|bool|mixed
339 *
340 * Get lesson content drip settings
341 */
342
343 if ( ! function_exists('get_item_content_drip_settings')){
344 function get_item_content_drip_settings($lesson_id = 0, $key = null, $default = false){
345 return tutils()->get_item_content_drip_settings( $lesson_id, $key, $default );
346 }
347 }
348
349 /**
350 * @param null $msg
351 * @param string $type
352 * @param bool $echo
353 *
354 * @return string
355 *
356 * Print Alert by tutor_alert()
357 *
358 * @since v.1.4.1
359 */
360 if ( ! function_exists('tutor_alert')){
361 function tutor_alert($msg = null, $type = 'warning', $echo = true){
362 if ( ! $msg){
363
364 if ($type === 'any'){
365 if ( ! $msg){
366 $type = 'warning';
367 $msg = tutor_flash_get($type);
368 }
369 if ( ! $msg){
370 $type = 'danger';
371 $msg = tutor_flash_get($type);
372 }
373 if ( ! $msg){
374 $type = 'success';
375 $msg = tutor_flash_get($type);
376 }
377
378 }else{
379 $msg = tutor_flash_get($type);
380 }
381
382
383 }
384 if ( ! $msg){
385 return $msg;
386 }
387
388 $html = "<div class='tutor-alert tutor-alert-{$type}'>{$msg}</div>";
389 if ($echo){
390 echo $html;
391 }
392 return $html;
393 }
394 }
395
396
397 /**
398 * @param bool $echo
399 *
400 * Simply call tutor_nonce_field() to generate nonce field
401 *
402 * @since v.1.4.2
403 */
404
405 if ( ! function_exists('tutor_nonce_field')) {
406 function tutor_nonce_field( $echo = true ) {
407 wp_nonce_field( tutor()->nonce_action, tutor()->nonce, $echo );
408 }
409 }
410
411 /**
412 * @param null $key
413 * @param string $message
414 *
415 * Set Flash Message
416 */
417
418 if ( ! function_exists('tutor_flash_set')) {
419 function tutor_flash_set( $key = null, $message = '' ) {
420 if ( ! $key ) {
421 return;
422 }
423 // ensure session is started
424 if ( session_status() !== PHP_SESSION_ACTIVE ) {
425 session_start();
426 }
427 $_SESSION[ $key ] = $message;
428 }
429 }
430
431 /**
432 * @param null $key
433 *
434 * @return array|bool|mixed|null
435 *
436 * @since v.1.4.2
437 *
438 * Get flash message
439 */
440
441 if ( ! function_exists('tutor_flash_get')) {
442 function tutor_flash_get( $key = null ) {
443 if ( $key ) {
444 // ensure session is started
445 if ( session_status() !== PHP_SESSION_ACTIVE ) {
446 @session_start();
447 }
448 if ( empty( $_SESSION ) ) {
449 return null;
450 }
451 $message = tutils()->array_get( $key, $_SESSION );
452 if ( $message ) {
453 unset( $_SESSION[ $key ] );
454 }
455 return $message;
456 }
457 return $key;
458 }
459 }
460
461 if ( ! function_exists('tutor_redirect_back')) {
462 /**
463 * @param null $url
464 *
465 * Redirect to back or a specific URL and terminate
466 *
467 * @since v.1.4.3
468 */
469 function tutor_redirect_back( $url = null ) {
470 if ( ! $url ) {
471 $url = tutils()->referer();
472 }
473 wp_safe_redirect( $url );
474 exit();
475 }
476 }
477
478 /**
479 * @param string $action
480 * @param bool $echo
481 *
482 * @return string
483 *
484 * @since v.1.4.3
485 */
486
487 if ( ! function_exists('tutor_action_field')) {
488 function tutor_action_field( $action = '', $echo = true ) {
489 $output = '';
490 if ( $action ) {
491 $output = "<input type='hidden' name='tutor_action' value='{$action}'>";
492 }
493
494 if ( $echo ) {
495 echo $output;
496 } else {
497 return $output;
498 }
499 }
500 }
501
502 /**
503 * @return int|string
504 *
505 * Return current Time from wordpress time
506 *
507 * @since v.1.4.3
508 */
509
510 if ( ! function_exists('tutor_time')) {
511 function tutor_time() {
512 //return current_time( 'timestamp' );
513 return time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
514 }
515 }
516
517 /**
518 * Toggle maintenance mode for the site.
519 *
520 * Creates/deletes the maintenance file to enable/disable maintenance mode.
521 *
522 * @since v.1.4.6
523 *
524 * @global WP_Filesystem_Base $wp_filesystem Subclass
525 *
526 * @param bool $enable True to enable maintenance mode, false to disable.
527 */
528 if ( ! function_exists('tutor_maintenance_mode')) {
529 function tutor_maintenance_mode( $enable = false ) {
530 global $wp_filesystem;
531 $file = $wp_filesystem->abspath() . '.tutor_maintenance';
532 if ( $enable ) {
533 // Create maintenance file to signal that we are upgrading
534 $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
535 $wp_filesystem->delete( $file );
536 $wp_filesystem->put_contents( $file, $maintenance_string, FS_CHMOD_FILE );
537 } elseif ( ! $enable && $wp_filesystem->exists( $file ) ) {
538 $wp_filesystem->delete( $file );
539 }
540 }
541 }