theme-compatibility
4 years ago
tinymce_translate.php
4 years ago
tutor-general-functions.php
4 years ago
tutor-template-functions.php
4 years ago
tutor-template-hook.php
4 years ago
tutor-general-functions.php
932 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; |
| 4 | } |
| 5 | |
| 6 | /** |
| 7 | * Tutor input sanitization |
| 8 | */ |
| 9 | |
| 10 | if ( ! function_exists( 'tutor_sanitize_data' ) ) { |
| 11 | /** |
| 12 | * Escaping for Sanitize data. |
| 13 | * |
| 14 | * @since 1.9.13 |
| 15 | * |
| 16 | * @param string $input. |
| 17 | * @param string $type. |
| 18 | * @return string |
| 19 | */ |
| 20 | function tutor_sanitize_data( $input = null, $type = null ) { |
| 21 | $array = array(); |
| 22 | $object = new stdClass(); |
| 23 | |
| 24 | if ( is_string( $input ) ) { |
| 25 | |
| 26 | if ( 'textarea' == $type ) { |
| 27 | $input = sanitize_textarea_field( $input ); |
| 28 | } elseif ( 'kses' == $type ) { |
| 29 | $input = wp_kses_post( $input ); |
| 30 | } else { |
| 31 | $input = sanitize_text_field( $input ); |
| 32 | } |
| 33 | |
| 34 | return $input; |
| 35 | |
| 36 | } elseif ( is_object( $input ) && count( get_object_vars( $input ) ) ) { |
| 37 | |
| 38 | foreach ( $input as $key => $value ) { |
| 39 | if ( is_object( $value ) ) { |
| 40 | $object->$key = tutor_sanitize_data( $value ); |
| 41 | } else { |
| 42 | $key = sanitize_text_field( $key ); |
| 43 | $value = sanitize_text_field( $value ); |
| 44 | $object->$key = $value; |
| 45 | } |
| 46 | } |
| 47 | return $object; |
| 48 | } elseif ( is_array( $input ) && count( $input ) ) { |
| 49 | foreach ( $input as $key => $value ) { |
| 50 | if ( is_array( $value ) ) { |
| 51 | $array[ $key ] = tutor_sanitize_data( $value ); |
| 52 | } else { |
| 53 | $key = sanitize_text_field( $key ); |
| 54 | $value = sanitize_text_field( $value ); |
| 55 | $array[ $key ] = $value; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | return $array; |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | if ( ! function_exists( 'tutor_placeholder_img_src' ) ) { |
| 65 | function tutor_placeholder_img_src() { |
| 66 | $src = tutor()->url . 'assets/images/placeholder.png'; |
| 67 | return apply_filters( 'tutor_placeholder_img_src', $src ); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @return string |
| 73 | * |
| 74 | * Get course categories selecting UI |
| 75 | * |
| 76 | * @since v.1.3.4 |
| 77 | */ |
| 78 | |
| 79 | if ( ! function_exists( 'tutor_course_categories_dropdown' ) ) { |
| 80 | function tutor_course_categories_dropdown( $post_ID = 0, $args = array() ) { |
| 81 | |
| 82 | $default = array( |
| 83 | 'classes' => '', |
| 84 | 'name' => 'tax_input[course-category]', |
| 85 | 'multiple' => true, |
| 86 | ); |
| 87 | |
| 88 | $args = apply_filters( 'tutor_course_categories_dropdown_args', array_merge( $default, $args ) ); |
| 89 | |
| 90 | $multiple_select = ''; |
| 91 | |
| 92 | if ( tutor_utils()->array_get( 'multiple', $args ) ) { |
| 93 | if ( isset( $args['name'] ) ) { |
| 94 | $args['name'] = $args['name'] . '[]'; |
| 95 | } |
| 96 | $multiple_select = "multiple='multiple'"; |
| 97 | } |
| 98 | |
| 99 | extract( $args ); |
| 100 | |
| 101 | $classes = (array) $classes; |
| 102 | $classes = implode( ' ', $classes ); |
| 103 | |
| 104 | $categories = tutor_utils()->get_course_categories(); |
| 105 | |
| 106 | $output = ''; |
| 107 | $output .= '<select name="' . $name . '" ' . $multiple_select . ' class="' . $classes . '" data-placeholder="' . __( 'Search Course Category. ex. Design, Development, Business', 'tutor' ) . '">'; |
| 108 | $output .= '<option value="">' . __( 'Select a category', 'tutor' ) . '</option>'; |
| 109 | $output .= _generate_categories_dropdown_option( $post_ID, $categories, $args ); |
| 110 | $output .= '</select>'; |
| 111 | |
| 112 | return $output; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * @return string |
| 118 | * |
| 119 | * Get course tags selecting UI |
| 120 | * |
| 121 | * @since v.1.3.4 |
| 122 | */ |
| 123 | |
| 124 | if ( ! function_exists( 'tutor_course_tags_dropdown' ) ) { |
| 125 | function tutor_course_tags_dropdown( $post_ID = 0, $args = array() ) { |
| 126 | |
| 127 | $default = array( |
| 128 | 'classes' => '', |
| 129 | 'name' => 'tax_input[course-tag]', |
| 130 | 'multiple' => true, |
| 131 | ); |
| 132 | |
| 133 | $args = apply_filters( 'tutor_course_tags_dropdown_args', array_merge( $default, $args ) ); |
| 134 | |
| 135 | $multiple_select = ''; |
| 136 | |
| 137 | if ( tutor_utils()->array_get( 'multiple', $args ) ) { |
| 138 | if ( isset( $args['name'] ) ) { |
| 139 | $args['name'] = $args['name'] . '[]'; |
| 140 | } |
| 141 | $multiple_select = "multiple='multiple'"; |
| 142 | } |
| 143 | |
| 144 | extract( $args ); |
| 145 | |
| 146 | $classes = (array) $classes; |
| 147 | $classes = implode( ' ', $classes ); |
| 148 | |
| 149 | $tags = tutor_utils()->get_course_tags(); |
| 150 | |
| 151 | $output = ''; |
| 152 | $output .= '<select name=' . $name . ' ' . $multiple_select . ' class="' . $classes . '" data-placeholder="' . __( 'Search Course Tags. ex. Design, Development, Business', 'tutor' ) . '">'; |
| 153 | $output .= '<option value="">' . __( 'Select a tag', 'tutor' ) . '</option>'; |
| 154 | $output .= _generate_tags_dropdown_option( $post_ID, $tags, $args ); |
| 155 | $output .= '</select>'; |
| 156 | |
| 157 | return $output; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * @param $categories |
| 163 | * @param string $parent_name |
| 164 | * |
| 165 | * @return string |
| 166 | * |
| 167 | * Get selecting options, recursive supports |
| 168 | * |
| 169 | * @since v.1.3.4 |
| 170 | */ |
| 171 | |
| 172 | if ( ! function_exists( '_generate_categories_dropdown_option' ) ) { |
| 173 | function _generate_categories_dropdown_option( $post_ID = 0, $categories = array(), $args = array(), $depth = 0 ) { |
| 174 | $output = ''; |
| 175 | |
| 176 | if ( ! tutor_utils()->count( $categories ) ) { |
| 177 | return $output; |
| 178 | } |
| 179 | |
| 180 | if ( ! is_numeric( $post_ID ) || $post_ID < 1 ) { |
| 181 | return $output; |
| 182 | } |
| 183 | |
| 184 | foreach ( $categories as $category_id => $category ) { |
| 185 | if ( ! $category->parent ) { |
| 186 | $depth = 0; |
| 187 | } |
| 188 | |
| 189 | $childrens = tutor_utils()->array_get( 'children', $category ); |
| 190 | $has_in_term = has_term( $category->term_id, 'course-category', $post_ID ); |
| 191 | |
| 192 | $depth_seperator = ''; |
| 193 | if ( $depth ) { |
| 194 | for ( $depth_i = 0; $depth_i < $depth; $depth_i++ ) { |
| 195 | $depth_seperator .= '-'; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | $output .= '<option value="' . $category->term_id . '" ' . selected( $has_in_term, true, false ) . '> ' . $depth_seperator . ' ' . $category->name . '</option>'; |
| 200 | |
| 201 | if ( tutor_utils()->count( $childrens ) ) { |
| 202 | $depth++; |
| 203 | $output .= _generate_categories_dropdown_option( $post_ID, $childrens, $args, $depth ); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | return $output; |
| 208 | } |
| 209 | } |
| 210 | /** |
| 211 | * @param $tags |
| 212 | * @param string $parent_name |
| 213 | * |
| 214 | * @return string |
| 215 | * |
| 216 | * Get selecting options, recursive supports |
| 217 | * |
| 218 | * @since v.1.3.4 |
| 219 | */ |
| 220 | |
| 221 | if ( ! function_exists( '_generate_tags_dropdown_option' ) ) { |
| 222 | function _generate_tags_dropdown_option( $post_ID = 0, $tags = array(), $args = array(), $depth = 0 ) { |
| 223 | $output = ''; |
| 224 | |
| 225 | if ( ! tutor_utils()->count( $tags ) ) { |
| 226 | return $output; |
| 227 | } |
| 228 | |
| 229 | if ( ! is_numeric( $post_ID ) || $post_ID < 1 ) { |
| 230 | return $output; |
| 231 | } |
| 232 | |
| 233 | foreach ( $tags as $tag ) { |
| 234 | |
| 235 | $has_in_term = has_term( $tag->term_id, 'course-tag', $post_ID ); |
| 236 | |
| 237 | $output .= '<option value="' . $tag->name . '" ' . selected( $has_in_term, true, false ) . '>' . $tag->name . '</option>'; |
| 238 | |
| 239 | } |
| 240 | |
| 241 | return $output; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * @param array $args |
| 247 | * |
| 248 | * @return string |
| 249 | * |
| 250 | * Generate course categories checkbox |
| 251 | * @since v.1.3.4 |
| 252 | */ |
| 253 | |
| 254 | if ( ! function_exists( 'tutor_course_categories_checkbox' ) ) { |
| 255 | function tutor_course_categories_checkbox( $post_ID = 0, $args = array() ) { |
| 256 | $default = array( |
| 257 | 'name' => 'tax_input[course-category]', |
| 258 | ); |
| 259 | |
| 260 | $args = apply_filters( 'tutor_course_categories_checkbox_args', array_merge( $default, $args ) ); |
| 261 | |
| 262 | if ( isset( $args['name'] ) ) { |
| 263 | $args['name'] = $args['name'] . '[]'; |
| 264 | } |
| 265 | |
| 266 | extract( $args ); |
| 267 | |
| 268 | $categories = tutor_utils()->get_course_categories(); |
| 269 | $output = ''; |
| 270 | $output .= __tutor_generate_categories_checkbox( $post_ID, $categories, $args ); |
| 271 | |
| 272 | return $output; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * @param array $args |
| 278 | * |
| 279 | * @return string |
| 280 | * |
| 281 | * Generate course tags checkbox |
| 282 | * @since v.1.3.4 |
| 283 | */ |
| 284 | |
| 285 | if ( ! function_exists( 'tutor_course_tags_checkbox' ) ) { |
| 286 | function tutor_course_tags_checkbox( $post_ID = 0, $args = array() ) { |
| 287 | $default = array( |
| 288 | 'name' => 'tax_input[course-tag]', |
| 289 | ); |
| 290 | |
| 291 | $args = apply_filters( 'tutor_course_tags_checkbox_args', array_merge( $default, $args ) ); |
| 292 | |
| 293 | if ( isset( $args['name'] ) ) { |
| 294 | $args['name'] = $args['name'] . '[]'; |
| 295 | } |
| 296 | |
| 297 | extract( $args ); |
| 298 | |
| 299 | $tags = tutor_utils()->get_course_tags(); |
| 300 | $output = ''; |
| 301 | $output .= __tutor_generate_tags_checkbox( $post_ID, $tags, $args ); |
| 302 | |
| 303 | return $output; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * @param $categories |
| 309 | * @param string $parent_name |
| 310 | * @param array $args |
| 311 | * |
| 312 | * @return string |
| 313 | * |
| 314 | * Internal function to generate course categories checkbox |
| 315 | * |
| 316 | * @since v.1.3.4 |
| 317 | */ |
| 318 | if ( ! function_exists( '__tutor_generate_categories_checkbox' ) ) { |
| 319 | function __tutor_generate_categories_checkbox( $post_ID = 0, $categories = array(), $args = array() ) { |
| 320 | |
| 321 | $output = ''; |
| 322 | $input_name = tutor_utils()->array_get( 'name', $args ); |
| 323 | |
| 324 | if ( tutor_utils()->count( $categories ) ) { |
| 325 | $output .= '<ul class="tax-input-course-category">'; |
| 326 | foreach ( $categories as $category_id => $category ) { |
| 327 | $childrens = tutor_utils()->array_get( 'children', $category ); |
| 328 | $has_in_term = has_term( $category->term_id, 'course-category', $post_ID ); |
| 329 | |
| 330 | $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>'; |
| 331 | |
| 332 | if ( tutor_utils()->count( $childrens ) ) { |
| 333 | $output .= __tutor_generate_categories_checkbox( $post_ID, $childrens, $args ); |
| 334 | } |
| 335 | $output .= ' </li>'; |
| 336 | } |
| 337 | $output .= '</ul>'; |
| 338 | } |
| 339 | |
| 340 | return $output; |
| 341 | |
| 342 | } |
| 343 | } |
| 344 | /** |
| 345 | * @param $tags |
| 346 | * @param string $parent_name |
| 347 | * @param array $args |
| 348 | * |
| 349 | * @return string |
| 350 | * |
| 351 | * Internal function to generate course tags checkbox |
| 352 | * |
| 353 | * @since v.1.3.4 |
| 354 | */ |
| 355 | if ( ! function_exists( '__tutor_generate_tags_checkbox' ) ) { |
| 356 | function __tutor_generate_tags_checkbox( $post_ID = 0, $tags = array(), $args = array() ) { |
| 357 | |
| 358 | $output = ''; |
| 359 | $input_name = tutor_utils()->array_get( 'name', $args ); |
| 360 | |
| 361 | if ( tutor_utils()->count( $tags ) ) { |
| 362 | $output .= '<ul class="tax-input-course-tag">'; |
| 363 | foreach ( $tags as $tag ) { |
| 364 | $has_in_term = has_term( $tag->term_id, 'course-tag', $post_ID ); |
| 365 | |
| 366 | $output .= '<li class="tax-input-course-tag-item tax-input-course-tag-item-' . $tag->term_id . '"><label class="course-tag-checkbox"> <input type="checkbox" name="' . $input_name . '" value="' . $tag->term_id . '" ' . checked( $has_in_term, true, false ) . ' /> <span>' . $tag->name . '</span> </label>'; |
| 367 | |
| 368 | $output .= ' </li>'; |
| 369 | } |
| 370 | $output .= '</ul>'; |
| 371 | } |
| 372 | |
| 373 | return $output; |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * @param string $content |
| 379 | * @param string $title |
| 380 | * |
| 381 | * @return string |
| 382 | * |
| 383 | * Wrap course builder sections within div for frontend |
| 384 | * |
| 385 | * @since v.1.3.4 |
| 386 | */ |
| 387 | |
| 388 | if ( ! function_exists( 'course_builder_section_wrap' ) ) { |
| 389 | function course_builder_section_wrap( $content = '', $title = '', $echo = true ) { |
| 390 | ob_start(); |
| 391 | ?> |
| 392 | <div class="tutor-course-builder-section"> |
| 393 | <div class="tutor-course-builder-section-title"> |
| 394 | <h3> |
| 395 | <i class="tutor-icon-angle-up-filled"></i> |
| 396 | <span><?php echo $title; ?></span> |
| 397 | </h3> |
| 398 | </div> |
| 399 | <div class="tutor-course-builder-section-content"> |
| 400 | <?php echo $content; ?> |
| 401 | </div> |
| 402 | </div> |
| 403 | <?php |
| 404 | $html = ob_get_clean(); |
| 405 | |
| 406 | if ( $echo ) { |
| 407 | echo tutor_kses_html( $html ); |
| 408 | } else { |
| 409 | return $html; |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | |
| 415 | if ( ! function_exists( 'get_tutor_header' ) ) { |
| 416 | function get_tutor_header( $fullScreen = false ) { |
| 417 | $enable_spotlight_mode = tutor_utils()->get_option( 'enable_spotlight_mode' ); |
| 418 | |
| 419 | if ( $enable_spotlight_mode || $fullScreen ) { |
| 420 | ?> |
| 421 | <!doctype html> |
| 422 | <html <?php language_attributes(); ?>> |
| 423 | |
| 424 | <head> |
| 425 | <meta charset="<?php bloginfo( 'charset' ); ?>" /> |
| 426 | <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 427 | <link rel="profile" href="https://gmpg.org/xfn/11" /> |
| 428 | <?php wp_head(); ?> |
| 429 | </head> |
| 430 | |
| 431 | <body <?php body_class(); ?>> |
| 432 | <div id="tutor-page-wrap" class="tutor-site-wrap site"> |
| 433 | <?php |
| 434 | } else { |
| 435 | tutor_utils()->tutor_custom_header(); |
| 436 | } |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | if ( ! function_exists( 'get_tutor_footer' ) ) { |
| 441 | function get_tutor_footer( $fullScreen = false ) { |
| 442 | $enable_spotlight_mode = tutor_utils()->get_option( 'enable_spotlight_mode' ); |
| 443 | if ( $enable_spotlight_mode || $fullScreen ) { |
| 444 | ?> |
| 445 | </div> |
| 446 | <?php wp_footer(); ?> |
| 447 | |
| 448 | </body> |
| 449 | |
| 450 | </html> |
| 451 | <?php |
| 452 | } else { |
| 453 | tutor_utils()->tutor_custom_footer(); |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | /** |
| 459 | * @param null $key |
| 460 | * @param bool $default |
| 461 | * |
| 462 | * @return array|bool|mixed |
| 463 | * |
| 464 | * Get tutor option by this helper function |
| 465 | * |
| 466 | * @since v.1.3.6 |
| 467 | */ |
| 468 | if ( ! function_exists( 'get_tutor_option' ) ) { |
| 469 | function get_tutor_option( $key = null, $default = false ) { |
| 470 | return tutor_utils()->get_option( $key, $default ); |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | /** |
| 475 | * @param null $key |
| 476 | * @param bool $value |
| 477 | * |
| 478 | * Update tutor option by this helper function |
| 479 | * |
| 480 | * @since v.1.3.6 |
| 481 | */ |
| 482 | if ( ! function_exists( 'update_tutor_option' ) ) { |
| 483 | function update_tutor_option( $key = null, $value = false ) { |
| 484 | tutor_utils()->update_option( $key, $value ); |
| 485 | } |
| 486 | } |
| 487 | /** |
| 488 | * @param int $course_id |
| 489 | * @param null $key |
| 490 | * @param bool $default |
| 491 | * |
| 492 | * @return array|bool|mixed |
| 493 | * |
| 494 | * Get tutor course settings by course ID |
| 495 | * |
| 496 | * @since v.1.4.1 |
| 497 | */ |
| 498 | if ( ! function_exists( 'get_tutor_course_settings' ) ) { |
| 499 | function get_tutor_course_settings( $course_id = 0, $key = null, $default = false ) { |
| 500 | return tutor_utils()->get_course_settings( $course_id, $key, $default ); |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | /** |
| 505 | * @param int $lesson_id |
| 506 | * @param null $key |
| 507 | * @param bool $default |
| 508 | * |
| 509 | * @return array|bool|mixed |
| 510 | * |
| 511 | * Get lesson content drip settings |
| 512 | */ |
| 513 | |
| 514 | if ( ! function_exists( 'get_item_content_drip_settings' ) ) { |
| 515 | function get_item_content_drip_settings( $lesson_id = 0, $key = null, $default = false ) { |
| 516 | return tutor_utils()->get_item_content_drip_settings( $lesson_id, $key, $default ); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | /** |
| 521 | * @param null $msg |
| 522 | * @param string $type |
| 523 | * @param bool $echo |
| 524 | * |
| 525 | * @return string |
| 526 | * |
| 527 | * Print Alert by tutor_alert() |
| 528 | * |
| 529 | * @since v.1.4.1 |
| 530 | */ |
| 531 | if ( ! function_exists( 'tutor_alert' ) ) { |
| 532 | function tutor_alert( $msg = null, $type = 'warning', $echo = true ) { |
| 533 | if ( ! $msg ) { |
| 534 | |
| 535 | if ( $type === 'any' ) { |
| 536 | if ( ! $msg ) { |
| 537 | $type = 'warning'; |
| 538 | $msg = tutor_flash_get( $type ); |
| 539 | } |
| 540 | if ( ! $msg ) { |
| 541 | $type = 'danger'; |
| 542 | $msg = tutor_flash_get( $type ); |
| 543 | } |
| 544 | if ( ! $msg ) { |
| 545 | $type = 'success'; |
| 546 | $msg = tutor_flash_get( $type ); |
| 547 | } |
| 548 | } else { |
| 549 | $msg = tutor_flash_get( $type ); |
| 550 | } |
| 551 | } |
| 552 | if ( ! $msg ) { |
| 553 | return $msg; |
| 554 | } |
| 555 | |
| 556 | $html = '<div class="asas tutor-alert tutor-' . esc_attr( $type ) . '"> |
| 557 | <div class="tutor-alert-text"> |
| 558 | <span class="tutor-alert-icon tutor-icon-34 tutor-icon-circle-outline-info-filled tutor-mr-10"></span> |
| 559 | <span>' . esc_attr( $msg ) . '</span> |
| 560 | </div> |
| 561 | </div>'; |
| 562 | if ( $echo ) { |
| 563 | echo tutor_kses_html( $html ); |
| 564 | } |
| 565 | return $html; |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | |
| 570 | /** |
| 571 | * @param bool $echo |
| 572 | * |
| 573 | * Simply call tutor_nonce_field() to generate nonce field |
| 574 | * |
| 575 | * @since v.1.4.2 |
| 576 | */ |
| 577 | |
| 578 | if ( ! function_exists( 'tutor_nonce_field' ) ) { |
| 579 | function tutor_nonce_field( $echo = true ) { |
| 580 | wp_nonce_field( tutor()->nonce_action, tutor()->nonce, $echo ); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | /** |
| 585 | * @param null $key |
| 586 | * @param string $message |
| 587 | * |
| 588 | * Set Flash Message |
| 589 | */ |
| 590 | |
| 591 | if ( ! function_exists( 'tutor_flash_set' ) ) { |
| 592 | function tutor_flash_set( $key = null, $message = '' ) { |
| 593 | if ( ! $key ) { |
| 594 | return; |
| 595 | } |
| 596 | // ensure session is started |
| 597 | if ( session_status() !== PHP_SESSION_ACTIVE ) { |
| 598 | session_start(); |
| 599 | } |
| 600 | $_SESSION[ $key ] = $message; |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | /** |
| 605 | * @param null $key |
| 606 | * |
| 607 | * @return array|bool|mixed|null |
| 608 | * |
| 609 | * @since v.1.4.2 |
| 610 | * |
| 611 | * Get flash message |
| 612 | */ |
| 613 | |
| 614 | if ( ! function_exists( 'tutor_flash_get' ) ) { |
| 615 | function tutor_flash_get( $key = null ) { |
| 616 | if ( $key ) { |
| 617 | // ensure session is started |
| 618 | if ( session_status() !== PHP_SESSION_ACTIVE ) { |
| 619 | @session_start(); |
| 620 | } |
| 621 | if ( empty( $_SESSION ) ) { |
| 622 | return null; |
| 623 | } |
| 624 | $message = tutor_utils()->array_get( $key, $_SESSION ); |
| 625 | if ( $message ) { |
| 626 | unset( $_SESSION[ $key ] ); |
| 627 | } |
| 628 | return $message; |
| 629 | } |
| 630 | return $key; |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | if ( ! function_exists( 'tutor_redirect_back' ) ) { |
| 635 | /** |
| 636 | * @param null $url |
| 637 | * |
| 638 | * Redirect to back or a specific URL and terminate |
| 639 | * |
| 640 | * @since v.1.4.3 |
| 641 | */ |
| 642 | function tutor_redirect_back( $url = null ) { |
| 643 | if ( ! $url ) { |
| 644 | $url = tutor_utils()->referer(); |
| 645 | } |
| 646 | wp_safe_redirect( $url ); |
| 647 | exit(); |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | /** |
| 652 | * @param string $action |
| 653 | * @param bool $echo |
| 654 | * |
| 655 | * @return string |
| 656 | * |
| 657 | * @since v.1.4.3 |
| 658 | */ |
| 659 | |
| 660 | if ( ! function_exists( 'tutor_action_field' ) ) { |
| 661 | function tutor_action_field( $action = '', $echo = true ) { |
| 662 | $output = ''; |
| 663 | if ( $action ) { |
| 664 | $output = '<input type="hidden" name="tutor_action" value="' . $action . '">'; |
| 665 | } |
| 666 | |
| 667 | if ( $echo ) { |
| 668 | echo tutor_kses_html( $output ); |
| 669 | } else { |
| 670 | return $output; |
| 671 | } |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | /** |
| 676 | * @return int|string |
| 677 | * |
| 678 | * Return current Time from WordPress time |
| 679 | * |
| 680 | * @since v.1.4.3 |
| 681 | */ |
| 682 | |
| 683 | if ( ! function_exists( 'tutor_time' ) ) { |
| 684 | function tutor_time() { |
| 685 | // return current_time( 'timestamp' ); |
| 686 | return time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | /** |
| 691 | * Toggle maintenance mode for the site. |
| 692 | * |
| 693 | * Creates/deletes the maintenance file to enable/disable maintenance mode. |
| 694 | * |
| 695 | * @since v.1.4.6 |
| 696 | * |
| 697 | * @global WP_Filesystem_Base $wp_filesystem Subclass |
| 698 | * |
| 699 | * @param bool $enable True to enable maintenance mode, false to disable. |
| 700 | */ |
| 701 | if ( ! function_exists( 'tutor_maintenance_mode' ) ) { |
| 702 | function tutor_maintenance_mode( $enable = false ) { |
| 703 | $file = ABSPATH . '.tutor_maintenance'; |
| 704 | if ( $enable ) { |
| 705 | // Create maintenance file to signal that we are upgrading |
| 706 | $maintenance_string = '<?php $upgrading = ' . time() . '; ?>'; |
| 707 | |
| 708 | if ( ! file_exists( $file ) ) { |
| 709 | file_put_contents( $file, $maintenance_string ); |
| 710 | } |
| 711 | } else { |
| 712 | if ( file_exists( $file ) ) { |
| 713 | unlink( $file ); |
| 714 | } |
| 715 | } |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | /** |
| 720 | * @return bool |
| 721 | * |
| 722 | * Check if the current page is course single page |
| 723 | * |
| 724 | * @since v.1.6.0 |
| 725 | */ |
| 726 | |
| 727 | if ( ! function_exists( 'is_single_course' ) ) { |
| 728 | function is_single_course($check_spotlight=false) { |
| 729 | global $wp_query; |
| 730 | $course_post_type = tutor()->course_post_type; |
| 731 | |
| 732 | $post_types = array($course_post_type); |
| 733 | if($check_spotlight){ |
| 734 | $post_types = array_merge($post_types, array( |
| 735 | 'lesson', |
| 736 | 'tutor_quiz', |
| 737 | 'tutor_assignments', |
| 738 | 'tutor_zoom_meeting' |
| 739 | )); |
| 740 | } |
| 741 | |
| 742 | if ( is_single() && ! empty( $wp_query->query['post_type'] ) && in_array($wp_query->query['post_type'], $post_types) ) { |
| 743 | return true; |
| 744 | } |
| 745 | return false; |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | /** |
| 750 | * Require wp_date form return js date format. |
| 751 | * this is helpful for date picker |
| 752 | * |
| 753 | * @return string |
| 754 | * |
| 755 | * @since 1.9.7 |
| 756 | */ |
| 757 | if ( ! function_exists( 'tutor_js_date_format_against_wp' ) ) { |
| 758 | function tutor_js_date_format_against_wp() { |
| 759 | $wp_date_format = get_option( 'date_format' ); |
| 760 | $default_format = 'yy-mm-dd'; |
| 761 | |
| 762 | $formats = array( |
| 763 | 'Y-m-d' => 'Y-M-d', |
| 764 | 'm/d/Y' => 'M-d-Y', |
| 765 | 'd/m/Y' => 'd-M-Y', |
| 766 | 'F j, Y' => 'MMMM d, yyyy', |
| 767 | ); |
| 768 | return isset( $formats[ $wp_date_format ] ) ? $formats[ $wp_date_format ] : $default_format; |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | /** |
| 773 | * Convert date to desire format |
| 774 | * |
| 775 | * @param $format string |
| 776 | * |
| 777 | * @param $date string |
| 778 | * |
| 779 | * @return string ( date ) |
| 780 | */ |
| 781 | if ( ! function_exists( 'tutor_get_formated_date' ) ) { |
| 782 | function tutor_get_formated_date( $require_format, $user_date ) { |
| 783 | $require_format===null ? $require_format = get_option( 'date_format' ). ', ' . get_option( 'time_format' ) : 0; |
| 784 | !is_numeric($user_date) ? $user_date = strtotime(str_replace('/', '-', $user_date )) : 0; |
| 785 | |
| 786 | return date( $require_format, $user_date ); |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | if ( ! function_exists( '_tutor_search_by_title_only' ) ) { |
| 791 | /** |
| 792 | * Search SQL filter for matching against post title only. |
| 793 | * |
| 794 | * @link http://wordpress.stackexchange.com/a/11826/1685 |
| 795 | * |
| 796 | * @param string $search |
| 797 | * @param WP_Query $wp_query |
| 798 | */ |
| 799 | function _tutor_search_by_title_only( $search, $wp_query ) { |
| 800 | if ( ! empty( $search ) && ! empty( $wp_query->query_vars['search_terms'] ) ) { |
| 801 | global $wpdb; |
| 802 | |
| 803 | $q = $wp_query->query_vars; |
| 804 | $n = ! empty( $q['exact'] ) ? '' : '%'; |
| 805 | |
| 806 | $search = array(); |
| 807 | |
| 808 | foreach ( ( array ) $q['search_terms'] as $term ) |
| 809 | $search[] = $wpdb->prepare( "$wpdb->posts.post_title LIKE %s", $n . $wpdb->esc_like( $term ) . $n ); |
| 810 | |
| 811 | if ( ! is_user_logged_in() ) |
| 812 | $search[] = "$wpdb->posts.post_password = ''"; |
| 813 | |
| 814 | $search = ' AND ' . implode( ' AND ', $search ); |
| 815 | } |
| 816 | |
| 817 | return $search; |
| 818 | } |
| 819 | |
| 820 | } |
| 821 | |
| 822 | if ( ! function_exists( 'pr' ) ) { |
| 823 | /** |
| 824 | * Function to print_r |
| 825 | * |
| 826 | * @param array $var . |
| 827 | * @return array |
| 828 | */ |
| 829 | function pr( $var ) { |
| 830 | $template = PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg' ? '<pre class="pr">%s</pre>' : "\n%s\n\n"; |
| 831 | printf( $template, trim( print_r( $var, true ) ) ); |
| 832 | |
| 833 | return $var; |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | if ( ! function_exists( 'tutor_vd' ) ) { |
| 838 | /** |
| 839 | * Function to var_dump |
| 840 | * |
| 841 | * @param array $var . |
| 842 | * @return array |
| 843 | */ |
| 844 | function tutor_vd( $var ) { |
| 845 | $template = PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg' ? '<pre class="pr">%s</pre>' : "\n%s\n\n"; |
| 846 | printf( $template, trim( var_dump( $var, true ) ) ); |
| 847 | |
| 848 | return $var; |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | |
| 853 | |
| 854 | if ( ! function_exists( 'get_request' ) ) { |
| 855 | /** |
| 856 | * Function to get_request |
| 857 | * |
| 858 | * @param array $var . |
| 859 | * @return array |
| 860 | */ |
| 861 | function get_request( $var ) { |
| 862 | return isset( $_REQUEST[ $var ] ) ? sanitize_text_field( $_REQUEST[ $var ] ) : false; |
| 863 | |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | if(!function_exists('tutor_kses_allowed_html')) { |
| 868 | function tutor_kses_allowed_html($allowed_tags, $context) { |
| 869 | $tags = array('input', 'style', 'script', 'select', 'form', 'option', 'optgroup', 'iframe', 'bdi', 'source'); |
| 870 | $atts = array('min', 'max', 'maxlength', 'type', 'method', 'enctype', 'action', 'selected', 'class', 'id', 'disabled', 'checked', 'readonly', 'name', 'aria-*', 'style', 'role', 'placeholder', 'value', 'data-*', 'src', 'width', 'height', 'frameborder', 'allow', 'fullscreen', 'title', 'multiple' ); |
| 871 | |
| 872 | foreach($tags as $tag) { |
| 873 | $tag_attrs = array(); |
| 874 | |
| 875 | foreach($atts as $att) { |
| 876 | $tag_attrs[$att] = true; |
| 877 | } |
| 878 | |
| 879 | $allowed_tags[$tag] = $tag_attrs; |
| 880 | } |
| 881 | |
| 882 | return $allowed_tags; |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | if(!function_exists('tutor_kses_allowed_css')) { |
| 887 | function tutor_kses_allowed_css( $styles ) { |
| 888 | $styles[] = 'display'; |
| 889 | $styles[] = '--progress-value'; |
| 890 | return $styles; |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | if(!function_exists('tutor_kses_html')) { |
| 895 | function tutor_kses_html( $content ) { |
| 896 | |
| 897 | return $content; |
| 898 | add_filter( 'wp_kses_allowed_html', 'tutor_kses_allowed_html', 10, 2 ); |
| 899 | add_filter( 'safe_style_css', 'tutor_kses_allowed_css' ); |
| 900 | |
| 901 | $content = preg_replace('/<!--(.|\s)*?-->/', '', $content); |
| 902 | $content = wp_kses_post( $content ); |
| 903 | $content = str_replace('&', '&', $content); |
| 904 | |
| 905 | remove_filter( 'safe_style_css', 'tutor_kses_allowed_css' ); |
| 906 | remove_filter( 'wp_kses_allowed_html', 'tutor_kses_allowed_html' ); |
| 907 | |
| 908 | return $content; |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | /** |
| 913 | * @return array |
| 914 | * |
| 915 | * Get all Withdraw Methods available on this system |
| 916 | * |
| 917 | * @since v.1.5.7 |
| 918 | */ |
| 919 | if (!function_exists('get_tutor_all_withdrawal_methods')) { |
| 920 | function get_tutor_all_withdrawal_methods() { |
| 921 | return apply_filters( 'tutor_withdrawal_methods_all', array() ); |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | |
| 926 | if(!function_exists('tutor_log')) { |
| 927 | function tutor_log($data) { |
| 928 | ob_start(); |
| 929 | var_dump($data); |
| 930 | error_log(ob_get_clean()); |
| 931 | } |
| 932 | } |