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.0 3.6.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
507 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 function generate_categories_select_for_pmpro($level_categories = array(), $args = array()){
289
290 $default = array(
291 'classes' => '',
292 'name' => 'tax_input[course-category]',
293 'multiple' => true,
294 );
295
296 $args = apply_filters('tutor_course_categories_dropdown_args', array_merge($default, $args));
297
298 $multiple_select = '';
299
300 if (tutor_utils()->array_get('multiple', $args)){
301 if (isset($args['name'])){
302 $args['name'] = $args['name'].'[]';
303 }
304 $multiple_select = "multiple='multiple'";
305 }
306
307 extract($args);
308
309 $classes = (array) $classes;
310 $classes = implode(' ', $classes);
311
312 $categories = tutor_utils()->get_course_categories();
313
314 $output = '';
315 $output .= "<select name='{$name}' {$multiple_select} class='{$classes}'>";
316 $output .= "<option value=''>". __('Select categories', 'tutor') ."</option>";
317 $output .= _generate_categories_select_option_for_pmpro($level_categories, $categories, $args);
318 $output .= "</select>";
319
320 return $output;
321 }
322
323 function _generate_categories_select_option_for_pmpro($level_categories = array(), $categories, $args = array(), $depth = 0){
324 $output = '';
325
326 if (tutor_utils()->count($categories)) {
327 foreach ( $categories as $category_id => $category ) {
328 if ( ! $category->parent){
329 $depth = 0;
330 }
331
332 $childrens = tutor_utils()->array_get( 'children', $category );
333 $has_in_term = in_array($category->term_id, $level_categories);
334
335 $depth_seperator = '';
336 if ($depth){
337 for ($depth_i = 0; $depth_i < $depth; $depth_i++){
338 $depth_seperator.='-';
339 }
340 }
341
342 $output .= "<option value='{$category->term_id}' ".selected($has_in_term, true, false)." >{$depth_seperator} {$category->name}</option> ";
343
344 if ( tutor_utils()->count( $childrens ) ) {
345 $depth++;
346 $output .= _generate_categories_select_option_for_pmpro($level_categories,$childrens, $args, $depth);
347 }
348 }
349 }
350 return $output;
351 }*/
352
353
354 /**
355 * @param null $key
356 * @param bool $default
357 *
358 * @return array|bool|mixed
359 *
360 * Get tutor option by this helper function
361 *
362 * @since v.1.3.6
363 */
364 if ( ! function_exists('get_tutor_option')){
365 function get_tutor_option($key = null, $default = false){
366 return tutils()->get_option($key, $default);
367 }
368 }
369
370 /**
371 * @param null $key
372 * @param bool $value
373 *
374 * Update tutor option by this helper function
375 *
376 * @since v.1.3.6
377 */
378 if ( ! function_exists('update_tutor_option')){
379 function update_tutor_option($key = null, $value = false){
380 tutils()->update_option($key, $value);
381 }
382 }
383 /**
384 * @param int $course_id
385 * @param null $key
386 * @param bool $default
387 *
388 * @return array|bool|mixed
389 *
390 * Get tutor course settings by course ID
391 *
392 * @since v.1.4.1
393 */
394 if ( ! function_exists('get_tutor_course_settings')) {
395 function get_tutor_course_settings( $course_id = 0, $key = null, $default = false ) {
396 return tutils()->get_course_settings( $course_id, $key, $default );
397 }
398 }
399
400 /**
401 * @param int $lesson_id
402 * @param null $key
403 * @param bool $default
404 *
405 * @return array|bool|mixed
406 *
407 * Get lesson content drip settings
408 */
409
410 if ( ! function_exists('get_item_content_drip_settings')){
411 function get_item_content_drip_settings($lesson_id = 0, $key = null, $default = false){
412 return tutils()->get_item_content_drip_settings( $lesson_id, $key, $default );
413 }
414 }
415
416 /**
417 * @param null $msg
418 * @param string $type
419 * @param bool $echo
420 *
421 * @return string
422 *
423 * Print Alert by tutor_alert()
424 *
425 * @since v.1.4.1
426 */
427 if ( ! function_exists('tutor_alert')){
428 function tutor_alert($msg = null, $type = 'warning', $echo = true){
429 if ( ! $msg){
430 $msg = tutor_flash_get($type);
431 }
432 if ( ! $msg){
433 return $msg;
434 }
435
436 $html = "<div class='tutor-alert tutor-alert-{$type}'>{$msg}</div>";
437 if ($echo){
438 echo $html;
439 }
440 return $html;
441 }
442 }
443
444
445 /**
446 * @param bool $echo
447 *
448 * Simply call tutor_nonce_field() to generate nonce field
449 *
450 * @since v.1.4.2
451 */
452
453 if ( ! function_exists('tutor_nonce_field')) {
454 function tutor_nonce_field( $echo = true ) {
455 wp_nonce_field( tutor()->nonce_action, tutor()->nonce, $echo );
456 }
457 }
458
459 /**
460 * @param null $key
461 * @param string $message
462 *
463 * Set Flash Message
464 */
465
466 if ( ! function_exists('tutor_flash_set')) {
467 function tutor_flash_set( $key = null, $message = '' ) {
468 if ( ! $key ) {
469 return;
470 }
471 // ensure session is started
472 if ( session_status() !== PHP_SESSION_ACTIVE ) {
473 session_start();
474 }
475 $_SESSION[ $key ] = $message;
476 }
477 }
478
479 /**
480 * @param null $key
481 *
482 * @return array|bool|mixed|null
483 *
484 * @since v.1.4.2
485 *
486 * Get flash message
487 */
488
489 if ( ! function_exists('tutor_flash_get')) {
490 function tutor_flash_get( $key = null ) {
491 if ( $key ) {
492 // ensure session is started
493 if ( session_status() !== PHP_SESSION_ACTIVE ) {
494 session_start();
495 }
496 if ( empty( $_SESSION ) ) {
497 return null;
498 }
499 $message = tutils()->array_get( $key, $_SESSION );
500 if ( $message ) {
501 unset( $_SESSION[ $key ] );
502 }
503 return $message;
504 }
505 return $key;
506 }
507 }