| 1 |
<?php |
| 2 |
/** |
| 3 |
* LearnPress Core Functions |
| 4 |
* Define common functions for both front-end and back-end |
| 5 |
* |
| 6 |
* @author ThimPress |
| 7 |
* @package LearnPress/Functions |
| 8 |
* @version 1.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
defined( 'ABSPATH' ) || exit; |
| 12 |
|
| 13 |
/** |
| 14 |
* Vue write php has script, so when sanitize will error, so use code is mask pass check sanitize, esc |
| 15 |
* |
| 16 |
* @param $content |
| 17 |
* |
| 18 |
* @return void |
| 19 |
* @since 4.1.6.9 |
| 20 |
*/ |
| 21 |
function learn_press_echo_vuejs_write_on_php( $content ) { |
| 22 |
echo ( $content ); |
| 23 |
} |
| 24 |
|
| 25 |
function learnpress_gutenberg_disable_cpt( $can_edit, $post_type ) { |
| 26 |
$post_types = array( |
| 27 |
LP_COURSE_CPT => LP_Settings::get_option( 'enable_gutenberg_course', 'no' ), |
| 28 |
LP_LESSON_CPT => LP_Settings::get_option( 'enable_gutenberg_lesson', 'no' ), |
| 29 |
LP_QUIZ_CPT => LP_Settings::get_option( 'enable_gutenberg_quiz', 'no' ), |
| 30 |
LP_QUESTION_CPT => LP_Settings::get_option( 'enable_gutenberg_question', 'no' ), |
| 31 |
); |
| 32 |
|
| 33 |
foreach ( $post_types as $key => $pt ) { |
| 34 |
if ( $post_type === $key && $pt !== 'yes' ) { |
| 35 |
$can_edit = false; |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
return $can_edit; |
| 40 |
} |
| 41 |
add_filter( 'use_block_editor_for_post_type', 'learnpress_gutenberg_disable_cpt', 10, 2 ); |
| 42 |
|
| 43 |
/** |
| 44 |
* Get instance of a CURD class by type |
| 45 |
* |
| 46 |
* @param string $type |
| 47 |
* |
| 48 |
* @return bool|LP_Course_CURD|LP_User_CURD|LP_Quiz_CURD|LP_Question_CURD |
| 49 |
* @deprecated 4.1.7.2 |
| 50 |
*/ |
| 51 |
/*function learn_press_get_curd( $type ) { |
| 52 |
$curds = array( |
| 53 |
'user' => 'LP_User_CURD', |
| 54 |
'course' => 'LP_Course_CURD', |
| 55 |
'quiz' => 'LP_Quiz_CURD', |
| 56 |
'question' => 'LP_Question_CURD', |
| 57 |
); |
| 58 |
|
| 59 |
$curd = false; |
| 60 |
|
| 61 |
if ( ! empty( $curds[ $type ] ) && class_exists( $curds[ $type ] ) ) { |
| 62 |
$curd = new $curds[ $type ](); |
| 63 |
} |
| 64 |
|
| 65 |
return apply_filters( 'learn-press/curd', $curd, $type, $curds ); |
| 66 |
}*/ |
| 67 |
|
| 68 |
if ( ! function_exists( 'lp_add_body_class' ) ) { |
| 69 |
function lp_add_body_class( $classes ) { |
| 70 |
$classes = (array) $classes; |
| 71 |
|
| 72 |
if ( learn_press_is_profile() ) { |
| 73 |
$classes[] = 'learnpress-profile'; |
| 74 |
} elseif ( learn_press_is_checkout() ) { |
| 75 |
$classes[] = 'learnpress-checkout'; |
| 76 |
} |
| 77 |
|
| 78 |
return $classes; |
| 79 |
} |
| 80 |
add_filter( 'body_class', 'lp_add_body_class' ); |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Short function to get name of a theme |
| 85 |
* |
| 86 |
* @param string $folder |
| 87 |
* |
| 88 |
* @return mixed|string |
| 89 |
*/ |
| 90 |
function learn_press_get_theme_name( $folder ) { |
| 91 |
$theme = wp_get_theme( $folder ); |
| 92 |
|
| 93 |
return ! empty( $theme['Name'] ) ? $theme['Name'] : ''; |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Clean. |
| 98 |
* |
| 99 |
* @param [type] $var |
| 100 |
* |
| 101 |
* @version 4.0.0 |
| 102 |
* @author Nhamdv <daonham95@gmail.com> |
| 103 |
*/ |
| 104 |
function learnpress_clean( $var ) { |
| 105 |
if ( is_array( $var ) ) { |
| 106 |
return array_map( 'learnpress_clean', $var ); |
| 107 |
} else { |
| 108 |
return is_scalar( $var ) ? sanitize_text_field( $var ) : $var; |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* Display HTML of element for building QuickTip JS. |
| 114 |
* |
| 115 |
* @param string $tip |
| 116 |
* @param bool $echo |
| 117 |
* @param array $options |
| 118 |
* |
| 119 |
* @return string |
| 120 |
* @since 3.0.0 |
| 121 |
*/ |
| 122 |
function learn_press_quick_tip( $tip, $echo = true, $options = array() ) { |
| 123 |
$atts = ''; |
| 124 |
if ( $options ) { |
| 125 |
foreach ( $options as $k => $v ) { |
| 126 |
$options[ $k ] = "data-{$k}=\"{$v}\""; |
| 127 |
} |
| 128 |
$atts = ' ' . implode( ' ', $options ); |
| 129 |
} |
| 130 |
|
| 131 |
$tip = sprintf( '<span class="learn-press-tip" ' . $atts . '>%s</span>', $tip ); |
| 132 |
|
| 133 |
if ( $echo ) { |
| 134 |
echo wp_kses_post( $tip ); |
| 135 |
} |
| 136 |
|
| 137 |
return $tip; |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* Get current post ID. |
| 142 |
* |
| 143 |
* @return int |
| 144 |
*/ |
| 145 |
function learn_press_get_post() { |
| 146 |
global $post; |
| 147 |
|
| 148 |
$post_id = learn_press_get_request( 'post' ); |
| 149 |
|
| 150 |
if ( ! $post_id ) { |
| 151 |
$post_id = ! empty( $post ) ? $post->ID : 0; |
| 152 |
} |
| 153 |
if ( empty( $post_id ) ) { |
| 154 |
$post_id = learn_press_get_request( 'post_ID' ); |
| 155 |
} |
| 156 |
|
| 157 |
return absint( $post_id ); |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* Get the LearnPress plugin url |
| 162 |
* |
| 163 |
* @param string $sub_dir |
| 164 |
* |
| 165 |
* @return string |
| 166 |
*/ |
| 167 |
function learn_press_plugin_url( $sub_dir = '' ) { |
| 168 |
return LearnPress::instance()->plugin_url( $sub_dir ); |
| 169 |
} |
| 170 |
|
| 171 |
/** |
| 172 |
* Get the LearnPress plugin path. |
| 173 |
* |
| 174 |
* @param string $sub_dir |
| 175 |
* |
| 176 |
* @return string |
| 177 |
*/ |
| 178 |
function learn_press_plugin_path( $sub_dir = '' ) { |
| 179 |
return LearnPress::instance()->plugin_path( $sub_dir ); |
| 180 |
} |
| 181 |
|
| 182 |
/** |
| 183 |
* Includes file base on LearnPress path |
| 184 |
* |
| 185 |
* @param string $file |
| 186 |
* @param string $folder |
| 187 |
* @param bool $include_once |
| 188 |
* |
| 189 |
* @return bool |
| 190 |
*/ |
| 191 |
function learn_press_include( $file, $folder = 'inc', $include_once = true ) { |
| 192 |
$include = learn_press_plugin_path( "{$folder}/{$file}" ); |
| 193 |
|
| 194 |
if ( file_exists( $include ) ) { |
| 195 |
if ( $include_once ) { |
| 196 |
include_once $include; |
| 197 |
} else { |
| 198 |
include $include; |
| 199 |
} |
| 200 |
|
| 201 |
return true; |
| 202 |
} |
| 203 |
|
| 204 |
return false; |
| 205 |
} |
| 206 |
|
| 207 |
/** |
| 208 |
* Get current IP of the user |
| 209 |
* |
| 210 |
* @return mixed |
| 211 |
*/ |
| 212 |
function learn_press_get_ip() { |
| 213 |
if ( isset( $_SERVER['HTTP_X_REAL_IP'] ) ) { |
| 214 |
return sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_REAL_IP'] ) ); |
| 215 |
} elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
| 216 |
// Proxy servers can send through this header like this: X-Forwarded-For: client1, proxy1, proxy2 |
| 217 |
// Make sure we always only send through the first IP in the list which should always be the client IP. |
| 218 |
return (string) rest_is_ip_address( trim( current( preg_split( '/,/', sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ) ) ) ); |
| 219 |
} elseif ( isset( $_SERVER['REMOTE_ADDR'] ) ) { |
| 220 |
return sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ); |
| 221 |
} |
| 222 |
return ''; |
| 223 |
} |
| 224 |
|
| 225 |
/** |
| 226 |
* Get user agent. |
| 227 |
* |
| 228 |
* @return string |
| 229 |
*/ |
| 230 |
function learn_press_get_user_agent(): string { |
| 231 |
return LP_Helper::sanitize_params_submitted( $_SERVER['HTTP_USER_AGENT'] ?? '' ); |
| 232 |
} |
| 233 |
|
| 234 |
/** |
| 235 |
* Generate an unique string. |
| 236 |
* |
| 237 |
* @param string $prefix |
| 238 |
* |
| 239 |
* @return string |
| 240 |
*/ |
| 241 |
function learn_press_uniqid( $prefix = '' ) { |
| 242 |
$hash = str_replace( '.', '', microtime( true ) . uniqid() ); |
| 243 |
|
| 244 |
return apply_filters( 'learn-press/generate-hash', $prefix . $hash, $prefix ); |
| 245 |
} |
| 246 |
|
| 247 |
function learn_press_random_value( $len = 8 ) { |
| 248 |
return substr( md5( uniqid( mt_rand(), true ) ), 0, $len ); |
| 249 |
} |
| 250 |
|
| 251 |
function learn_press_map_columns_format( $columns, $format ) { |
| 252 |
$return = array(); |
| 253 |
foreach ( $columns as $k => $v ) { |
| 254 |
if ( ! empty( $format[ $k ] ) ) { |
| 255 |
$return[] = $format[ $k ]; |
| 256 |
} else { |
| 257 |
$return[] = '%s'; // default is string |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
return $return; |
| 262 |
} |
| 263 |
|
| 264 |
/** |
| 265 |
* Check to see if an endpoint is showing in current URL. |
| 266 |
* |
| 267 |
* @param bool $endpoint |
| 268 |
* |
| 269 |
* @return bool |
| 270 |
*/ |
| 271 |
function learn_press_is_endpoint_url( $endpoint = false ) { |
| 272 |
global $wp; |
| 273 |
|
| 274 |
$endpoints = array(); |
| 275 |
|
| 276 |
if ( $endpoint !== false ) { |
| 277 |
if ( ! isset( $endpoints[ $endpoint ] ) ) { |
| 278 |
return false; |
| 279 |
} else { |
| 280 |
$endpoint_var = $endpoints[ $endpoint ]; |
| 281 |
} |
| 282 |
|
| 283 |
return isset( $wp->query_vars[ $endpoint_var ] ); |
| 284 |
} else { |
| 285 |
foreach ( $endpoints as $key => $value ) { |
| 286 |
if ( isset( $wp->query_vars[ $key ] ) ) { |
| 287 |
return true; |
| 288 |
} |
| 289 |
} |
| 290 |
|
| 291 |
return false; |
| 292 |
} |
| 293 |
} |
| 294 |
|
| 295 |
/** |
| 296 |
* Get current URL user is viewing. |
| 297 |
* |
| 298 |
* @return string |
| 299 |
*/ |
| 300 |
function learn_press_get_current_url() { |
| 301 |
static $current_url; |
| 302 |
|
| 303 |
if ( ! $current_url ) { |
| 304 |
$url = untrailingslashit( esc_url_raw( $_SERVER['REQUEST_URI'] ) ); |
| 305 |
|
| 306 |
if ( ! preg_match( '!^https?!', $url ) ) { |
| 307 |
$siteurl = trailingslashit( get_home_url() ); |
| 308 |
$home_query = ''; |
| 309 |
|
| 310 |
if ( strpos( $siteurl, '?' ) !== false ) { |
| 311 |
$parts = explode( '?', $siteurl ); |
| 312 |
$home_query = $parts[1]; |
| 313 |
$siteurl = $parts[0]; |
| 314 |
} |
| 315 |
|
| 316 |
if ( $home_query ) { |
| 317 |
parse_str( untrailingslashit( $home_query ), $home_query ); |
| 318 |
$url = esc_url_raw( add_query_arg( $home_query, $url ) ); |
| 319 |
} |
| 320 |
|
| 321 |
$segs1 = explode( '/', $siteurl ); |
| 322 |
$segs2 = explode( '/', $url ); |
| 323 |
|
| 324 |
if ( $removed = array_intersect( $segs1, $segs2 ) ) { |
| 325 |
if ( $segs2 = array_diff( $segs2, $removed ) ) { |
| 326 |
$current_url = $siteurl . join( '/', $segs2 ); |
| 327 |
if ( strpos( $current_url, '?' ) === false ) { |
| 328 |
$current_url = trailingslashit( $current_url ); |
| 329 |
} |
| 330 |
} |
| 331 |
} |
| 332 |
} |
| 333 |
} |
| 334 |
|
| 335 |
return $current_url; |
| 336 |
} |
| 337 |
|
| 338 |
/** |
| 339 |
* Compares an url with current URL user is viewing |
| 340 |
* |
| 341 |
* @param string $url |
| 342 |
* |
| 343 |
* @return bool |
| 344 |
*/ |
| 345 |
function learn_press_is_current_url( $url ) { |
| 346 |
$current_url = learn_press_get_current_url(); |
| 347 |
|
| 348 |
return ( $current_url && $url ) && strcmp( $current_url, learn_press_sanitize_url( $url ) ) == 0; |
| 349 |
} |
| 350 |
|
| 351 |
/** |
| 352 |
* Remove unneeded characters in an URL |
| 353 |
* |
| 354 |
* @param string $url |
| 355 |
* @param bool $trailingslashit |
| 356 |
* |
| 357 |
* @return string |
| 358 |
*/ |
| 359 |
function learn_press_sanitize_url( $url, $trailingslashit = true ) { |
| 360 |
if ( $url ) { |
| 361 |
preg_match( '!(https?://)?(.*)!', $url, $matches ); |
| 362 |
$url_without_http = $matches[2]; |
| 363 |
$url_without_http = preg_replace( '![/]+!', '/', $url_without_http ); |
| 364 |
$url = $matches[1] . $url_without_http; |
| 365 |
|
| 366 |
return ( $trailingslashit && |
| 367 |
strpos( $url, '?' ) === false ) ? trailingslashit( $url ) : untrailingslashit( $url ); |
| 368 |
} |
| 369 |
|
| 370 |
return $url; |
| 371 |
} |
| 372 |
|
| 373 |
/** |
| 374 |
* Get all types of question supported |
| 375 |
* |
| 376 |
* @return mixed |
| 377 |
*/ |
| 378 |
function learn_press_question_types() { |
| 379 |
return LP_Question::get_types(); |
| 380 |
} |
| 381 |
|
| 382 |
/** |
| 383 |
* Get human name of question's type by slug |
| 384 |
* |
| 385 |
* @param string $slug |
| 386 |
* |
| 387 |
* @return array |
| 388 |
*/ |
| 389 |
function learn_press_question_name_from_slug( $slug ) { |
| 390 |
$types = learn_press_question_types(); |
| 391 |
$name = ! empty( $types[ $slug ] ) ? $types[ $slug ] : ''; |
| 392 |
|
| 393 |
return apply_filters( 'learn-press/question/slug-to-name', $name, $slug ); |
| 394 |
} |
| 395 |
|
| 396 |
/** |
| 397 |
* Get terms of a course by taxonomy. |
| 398 |
* E.g: course_tag, course_category |
| 399 |
* |
| 400 |
* @param int $course_id |
| 401 |
* @param string $taxonomy |
| 402 |
* @param array $args |
| 403 |
* |
| 404 |
* @return array|mixed |
| 405 |
*/ |
| 406 |
function learn_press_get_course_terms( $course_id, $taxonomy, $args = array() ) { |
| 407 |
if ( ! taxonomy_exists( $taxonomy ) ) { |
| 408 |
return array(); |
| 409 |
} |
| 410 |
|
| 411 |
// Support ordering by parent |
| 412 |
if ( ! empty( $args['orderby'] ) && in_array( $args['orderby'], array( 'name_num', 'parent' ) ) ) { |
| 413 |
$fields = isset( $args['fields'] ) ? $args['fields'] : 'all'; |
| 414 |
$orderby = $args['orderby']; |
| 415 |
|
| 416 |
// Unset for wp_get_post_terms |
| 417 |
unset( $args['orderby'] ); |
| 418 |
unset( $args['fields'] ); |
| 419 |
|
| 420 |
$terms = wp_get_post_terms( $course_id, $taxonomy, $args ); |
| 421 |
|
| 422 |
switch ( $orderby ) { |
| 423 |
case 'name_num': |
| 424 |
usort( $terms, '_learn_press_get_course_terms_name_num_usort_callback' ); |
| 425 |
break; |
| 426 |
case 'parent': |
| 427 |
usort( $terms, '_learn_press_get_course_terms_parent_usort_callback' ); |
| 428 |
break; |
| 429 |
} |
| 430 |
|
| 431 |
switch ( $fields ) { |
| 432 |
case 'names': |
| 433 |
$terms = wp_list_pluck( $terms, 'name' ); |
| 434 |
break; |
| 435 |
case 'ids': |
| 436 |
$terms = wp_list_pluck( $terms, 'term_id' ); |
| 437 |
break; |
| 438 |
case 'slugs': |
| 439 |
$terms = wp_list_pluck( $terms, 'slug' ); |
| 440 |
break; |
| 441 |
} |
| 442 |
} elseif ( ! empty( $args['orderby'] ) && $args['orderby'] === 'menu_order' ) { |
| 443 |
// wp_get_post_terms doesn't let us use custom sort order |
| 444 |
$args['include'] = wp_get_post_terms( $course_id, $taxonomy, array( 'fields' => 'ids' ) ); |
| 445 |
|
| 446 |
if ( empty( $args['include'] ) ) { |
| 447 |
$terms = array(); |
| 448 |
} else { |
| 449 |
// This isn't needed for get_terms |
| 450 |
unset( $args['orderby'] ); |
| 451 |
|
| 452 |
// Set args for get_terms |
| 453 |
$args['menu_order'] = isset( $args['order'] ) ? $args['order'] : 'ASC'; |
| 454 |
$args['hide_empty'] = isset( $args['hide_empty'] ) ? $args['hide_empty'] : 0; |
| 455 |
$args['fields'] = isset( $args['fields'] ) ? $args['fields'] : 'names'; |
| 456 |
|
| 457 |
// Ensure slugs is valid for get_terms - slugs isn't supported |
| 458 |
$args['fields'] = $args['fields'] === 'slugs' ? 'id=>slug' : $args['fields']; |
| 459 |
$terms = get_terms( $taxonomy, $args ); |
| 460 |
} |
| 461 |
} else { |
| 462 |
$terms = wp_get_post_terms( $course_id, $taxonomy, $args ); |
| 463 |
} |
| 464 |
|
| 465 |
// @deprecated |
| 466 |
$terms = apply_filters( 'learn_press_get_course_terms', $terms, $course_id, $taxonomy, $args ); |
| 467 |
|
| 468 |
return apply_filters( 'learn-press/course/terms', $terms, $course_id, $taxonomy, $args ); |
| 469 |
} |
| 470 |
|
| 471 |
/** |
| 472 |
* Callback function for sorting terms of course by name. |
| 473 |
* |
| 474 |
* @param object $a |
| 475 |
* @param object $b |
| 476 |
* |
| 477 |
* @return int |
| 478 |
*/ |
| 479 |
function _learn_press_get_course_terms_name_num_usort_callback( $a, $b ) { |
| 480 |
if ( $a->name + 0 === $b->name + 0 ) { |
| 481 |
return 0; |
| 482 |
} |
| 483 |
|
| 484 |
return ( $a->name + 0 < $b->name + 0 ) ? - 1 : 1; |
| 485 |
} |
| 486 |
|
| 487 |
/** |
| 488 |
* Callback function for sorting terms of course by parent. |
| 489 |
* |
| 490 |
* @param object $a |
| 491 |
* @param object $b |
| 492 |
* |
| 493 |
* @return int |
| 494 |
*/ |
| 495 |
function _learn_press_get_course_terms_parent_usort_callback( $a, $b ) { |
| 496 |
if ( $a->parent === $b->parent ) { |
| 497 |
return 0; |
| 498 |
} |
| 499 |
|
| 500 |
return ( $a->parent < $b->parent ) ? 1 : - 1; |
| 501 |
} |
| 502 |
|
| 503 |
/** |
| 504 |
* Get posts by it's post-name (slug). |
| 505 |
* |
| 506 |
* @param string $name |
| 507 |
* @param string $type |
| 508 |
* @param bool $single |
| 509 |
* |
| 510 |
* @return array|bool|null|WP_Post |
| 511 |
*/ |
| 512 |
function learn_press_get_post_by_name( $name, $type, $single = true ) { |
| 513 |
$post_name = sanitize_title( $name ); |
| 514 |
$id = LP_Object_Cache::get( $type . '-' . $post_name, 'learn-press/post-names' ); |
| 515 |
|
| 516 |
if ( false === $id ) { |
| 517 |
foreach ( array( $name, urldecode( $name ) ) as $_name ) { |
| 518 |
$args = array( |
| 519 |
'name' => $_name, |
| 520 |
'post_type' => array( $type ), |
| 521 |
); |
| 522 |
|
| 523 |
$posts = get_posts( $args ); |
| 524 |
|
| 525 |
if ( $posts ) { |
| 526 |
$post = $posts[0]; |
| 527 |
$id = $post->ID; |
| 528 |
wp_cache_set( $id, $post, 'posts' ); |
| 529 |
LP_Object_Cache::set( $type . '-' . $name, $id, 'learn-press/post-names' ); |
| 530 |
break; |
| 531 |
} |
| 532 |
} |
| 533 |
} |
| 534 |
|
| 535 |
return $id ? get_post( $id ) : false; |
| 536 |
} |
| 537 |
|
| 538 |
if ( ! function_exists( 'learn_press_is_ajax' ) ) { |
| 539 |
function learn_press_is_ajax() { |
| 540 |
return defined( 'LP_DOING_AJAX' ) && LP_DOING_AJAX && 'yes' != learn_press_get_request( 'noajax' ); |
| 541 |
} |
| 542 |
} |
| 543 |
|
| 544 |
/** |
| 545 |
* Get page id from admin settings page |
| 546 |
* |
| 547 |
* @param string $name |
| 548 |
* |
| 549 |
* @since 3.0.0 |
| 550 |
* @version 1.0.2 |
| 551 |
* @return int |
| 552 |
*/ |
| 553 |
function learn_press_get_page_id( string $name ): int { |
| 554 |
$page_id = LP_Settings::get_option( "{$name}_page_id", false ); |
| 555 |
|
| 556 |
/*if ( function_exists( 'icl_object_id' ) ) { |
| 557 |
$page_id = icl_object_id( $page_id, 'page', false, defined( 'ICL_LANGUAGE_CODE' ) ? ICL_LANGUAGE_CODE : '' ); |
| 558 |
}*/ |
| 559 |
|
| 560 |
$page_id = (int) $page_id; |
| 561 |
|
| 562 |
return apply_filters( 'learn_press_get_page_id', $page_id, $name ); |
| 563 |
} |
| 564 |
|
| 565 |
/** |
| 566 |
* display the seconds in time format h:i:s |
| 567 |
* |
| 568 |
* @param $seconds |
| 569 |
* @param string $separator |
| 570 |
* |
| 571 |
* @return string |
| 572 |
*/ |
| 573 |
function learn_press_seconds_to_time( $seconds, $separator = ':' ) { |
| 574 |
return sprintf( |
| 575 |
'%02d%s%02d%s%02d', |
| 576 |
floor( $seconds / 3600 ), |
| 577 |
$separator, |
| 578 |
( $seconds / 60 ) % 60, |
| 579 |
$separator, |
| 580 |
$seconds % 60 |
| 581 |
); |
| 582 |
} |
| 583 |
|
| 584 |
/* nav */ |
| 585 |
if ( ! function_exists( 'learn_press_course_paging_nav' ) ) { |
| 586 |
|
| 587 |
/** |
| 588 |
* Display navigation to next/previous set of posts when applicable. |
| 589 |
* |
| 590 |
* @param array |
| 591 |
*/ |
| 592 |
function learn_press_course_paging_nav( $args = array() ) { |
| 593 |
learn_press_paging_nav( |
| 594 |
array( |
| 595 |
'num_pages' => $GLOBALS['wp_query']->max_num_pages, |
| 596 |
'wrapper_class' => 'navigation pagination', |
| 597 |
) |
| 598 |
); |
| 599 |
} |
| 600 |
} |
| 601 |
|
| 602 |
/* nav */ |
| 603 |
if ( ! function_exists( 'learn_press_paging_nav' ) ) { |
| 604 |
function learn_press_paging_nav( $args = array() ) { |
| 605 |
$args = wp_parse_args( |
| 606 |
$args, |
| 607 |
array( |
| 608 |
'num_pages' => 0, |
| 609 |
'paged' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1, |
| 610 |
'wrapper_class' => 'learn-press-pagination', |
| 611 |
'base' => false, |
| 612 |
'format' => '', |
| 613 |
'echo' => true, |
| 614 |
) |
| 615 |
); |
| 616 |
|
| 617 |
if ( $args['num_pages'] < 2 ) { |
| 618 |
return false; |
| 619 |
} |
| 620 |
|
| 621 |
$paged = $args['paged']; |
| 622 |
$pagenum_link = html_entity_decode( $args['base'] === false ? get_pagenum_link() : $args['base'] ); |
| 623 |
|
| 624 |
$query_args = array(); |
| 625 |
$url_parts = explode( '?', $pagenum_link ); |
| 626 |
|
| 627 |
if ( isset( $url_parts[1] ) ) { |
| 628 |
wp_parse_str( $url_parts[1], $query_args ); |
| 629 |
} |
| 630 |
|
| 631 |
$pagenum_link = esc_url_raw( remove_query_arg( array_keys( $query_args ), $pagenum_link ) ); |
| 632 |
$pagenum_link = trailingslashit( $pagenum_link ) . '%_%'; |
| 633 |
|
| 634 |
$format = $GLOBALS['wp_rewrite']->using_index_permalinks() && ! strpos( |
| 635 |
$pagenum_link, |
| 636 |
'index.php' |
| 637 |
) ? 'index.php/' : ''; |
| 638 |
$format .= $args['format'] ? $args['format'] : ( $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( |
| 639 |
'page/%#%', |
| 640 |
'paged' |
| 641 |
) : '?paged=%#%' ); |
| 642 |
|
| 643 |
$link_args = array( |
| 644 |
'base' => $pagenum_link, |
| 645 |
'format' => $format, |
| 646 |
'total' => $args['num_pages'], |
| 647 |
'current' => max( 1, $paged ), |
| 648 |
'mid_size' => 1, |
| 649 |
'add_args' => array_map( 'urlencode', $query_args ), |
| 650 |
'prev_text' => __( '<', 'learnpress' ), |
| 651 |
'next_text' => __( '>', 'learnpress' ), |
| 652 |
'type' => 'list', |
| 653 |
); |
| 654 |
|
| 655 |
// Set up paginated links. |
| 656 |
$links = paginate_links( $link_args ); |
| 657 |
|
| 658 |
ob_start(); |
| 659 |
|
| 660 |
if ( $links ) { |
| 661 |
?> |
| 662 |
<div class="<?php echo esc_attr( $args['wrapper_class'] ); ?>"> |
| 663 |
<?php echo wp_kses_post( $links ); ?> |
| 664 |
</div> |
| 665 |
<?php |
| 666 |
} |
| 667 |
|
| 668 |
$output = ob_get_clean(); |
| 669 |
|
| 670 |
if ( $args['echo'] ) { |
| 671 |
echo wp_kses_post( $output ); |
| 672 |
} |
| 673 |
|
| 674 |
return $output; |
| 675 |
} |
| 676 |
} |
| 677 |
|
| 678 |
/** |
| 679 |
* Get number of pages by rows and items per page. |
| 680 |
* |
| 681 |
* @param int $total |
| 682 |
* @param int $limit |
| 683 |
* |
| 684 |
* @return int |
| 685 |
*/ |
| 686 |
function learn_press_get_num_pages( $total, $limit = 10 ) { |
| 687 |
$limit = $limit <= 0 ? 10 : $limit; |
| 688 |
|
| 689 |
if ( $total <= $limit ) { |
| 690 |
return 1; |
| 691 |
} |
| 692 |
|
| 693 |
$pages = absint( $total / $limit ); |
| 694 |
|
| 695 |
if ( $total % $limit != 0 ) { |
| 696 |
$pages ++; |
| 697 |
} |
| 698 |
|
| 699 |
return $pages; |
| 700 |
} |
| 701 |
|
| 702 |
/** |
| 703 |
* Get text |
| 704 |
* |
| 705 |
* @param $status_id |
| 706 |
* |
| 707 |
* @return mixed |
| 708 |
*/ |
| 709 |
function learn_press_get_status_text( $status_id ) { |
| 710 |
switch ( $status_id ) { |
| 711 |
case 1: |
| 712 |
$text = 'pending'; |
| 713 |
break; |
| 714 |
case 2: |
| 715 |
$text = 'complete'; |
| 716 |
break; |
| 717 |
case - 1: |
| 718 |
$text = 'cancel'; |
| 719 |
break; |
| 720 |
case - 2: |
| 721 |
$text = 'refund'; |
| 722 |
break; |
| 723 |
default: |
| 724 |
$text = 'on-hold'; |
| 725 |
} |
| 726 |
|
| 727 |
return $text; |
| 728 |
} |
| 729 |
|
| 730 |
function learn_press_get_course_duration_support() { |
| 731 |
return apply_filters( |
| 732 |
'learn_press_course_duration_support', |
| 733 |
array( |
| 734 |
'minute' => esc_html__( 'Minute(s)', 'learnpress' ), |
| 735 |
'hour' => esc_html__( 'Hour(s)', 'learnpress' ), |
| 736 |
'day' => esc_html__( 'Day(s)', 'learnpress' ), |
| 737 |
'week' => esc_html__( 'Week(s)', 'learnpress' ), |
| 738 |
) |
| 739 |
); |
| 740 |
} |
| 741 |
|
| 742 |
function learn_press_number_to_string_time( $number ) { |
| 743 |
$str = $number; |
| 744 |
|
| 745 |
if ( preg_match( '!([0-9.]+) (minute|hour|day|week)!', $number, $matches ) ) { |
| 746 |
switch ( $matches[2] ) { |
| 747 |
case 'hour': |
| 748 |
$minute = $matches[1] * 60; |
| 749 |
$str = sprintf( '%s hour %s minute', absint( $minute / 60 ), $minute % 60 ); |
| 750 |
break; |
| 751 |
case 'day': |
| 752 |
$hour = $matches[1] * 24; |
| 753 |
$str = sprintf( '%s day %s hour', absint( $hour / 24 ), $hour % 24 ); |
| 754 |
break; |
| 755 |
case 'week': |
| 756 |
$day = $matches[1] * 7; |
| 757 |
$str = sprintf( '%s week %s day', absint( $day / 7 ), $day % 7 ); |
| 758 |
break; |
| 759 |
} |
| 760 |
} |
| 761 |
|
| 762 |
return $str; |
| 763 |
} |
| 764 |
|
| 765 |
function learn_press_human_time_to_seconds( $time, $default = '' ) { |
| 766 |
$duration = learn_press_get_course_duration_support(); |
| 767 |
$duration_keys = array_keys( $duration ); |
| 768 |
|
| 769 |
if ( preg_match_all( '!([0-9]+)\s*(' . join( '|', $duration_keys ) . ')?!', $time, $matches ) ) { |
| 770 |
$a1 = $matches[1][0]; |
| 771 |
$a2 = in_array( $matches[2][0], $duration_keys ) ? $matches[2][0] : ''; |
| 772 |
} else { |
| 773 |
$a1 = absint( $time ); |
| 774 |
$a2 = ''; |
| 775 |
} |
| 776 |
|
| 777 |
if ( $a2 ) { |
| 778 |
$b = array( |
| 779 |
'minute' => 60, |
| 780 |
'hour' => 3600, |
| 781 |
'day' => 3600 * 24, |
| 782 |
'week' => 3600 * 24 * 7, |
| 783 |
); |
| 784 |
$a1 = $a1 * $b[ $a2 ]; |
| 785 |
} |
| 786 |
|
| 787 |
return $a1; |
| 788 |
} |
| 789 |
|
| 790 |
/** |
| 791 |
* Send email notification. |
| 792 |
* |
| 793 |
* @param string $to . |
| 794 |
* @param string $action . |
| 795 |
* @param array $vars . |
| 796 |
* |
| 797 |
* @return bool |
| 798 |
* @deprecated 4.1.7.2 |
| 799 |
*/ |
| 800 |
/*function learn_press_send_mail( $to = '', $action = '', $vars = array() ) { |
| 801 |
$email_settings = LP_Settings::instance(); |
| 802 |
|
| 803 |
if ( ! $email_settings->get( $action . '.enable' ) ) { |
| 804 |
return "The action {$action} doesnt support"; |
| 805 |
} |
| 806 |
|
| 807 |
$user = get_user_by( 'email', $to ); |
| 808 |
|
| 809 |
$vars['log_in'] = apply_filters( 'learn_press_site_url', get_home_url() ); |
| 810 |
|
| 811 |
// Send email. |
| 812 |
$email = new LP_Email(); |
| 813 |
$email->set_action( $action ); |
| 814 |
$email->parse_email( $vars ); |
| 815 |
$email->add_recipient( $to ); |
| 816 |
|
| 817 |
return $email->send(); |
| 818 |
}*/ |
| 819 |
|
| 820 |
/* |
| 821 |
* Send email notification when a course be published |
| 822 |
* @deprecated 4.1.7.2 |
| 823 |
*/ |
| 824 |
/*function learn_press_publish_course( $new_status, $old_status, $post ) { |
| 825 |
if ( $old_status == 'pending' && $new_status == 'publish' && $post->post_type == 'lp_course' ) { |
| 826 |
$instructor = get_userdata( $post->post_author ); |
| 827 |
$mail_to = $instructor->user_email; |
| 828 |
|
| 829 |
learn_press_send_mail( |
| 830 |
$mail_to, |
| 831 |
'published_course', |
| 832 |
apply_filters( |
| 833 |
'learn_press_vars_enrolled_course', |
| 834 |
array( |
| 835 |
'user_name' => $instructor->display_name, |
| 836 |
'course_name' => $post->post_title, |
| 837 |
'course_link' => get_permalink( $post->ID ), |
| 838 |
), |
| 839 |
$post, |
| 840 |
$instructor |
| 841 |
) |
| 842 |
); |
| 843 |
} |
| 844 |
}*/ |
| 845 |
|
| 846 |
//add_action( 'transition_post_status', 'learn_press_publish_course', 10, 3 ); |
| 847 |
|
| 848 |
/** |
| 849 |
* @param $user_id |
| 850 |
* |
| 851 |
* @return WP_Query |
| 852 |
*/ |
| 853 |
function learn_press_get_own_courses( $user_id ) { |
| 854 |
$arr_query = array( |
| 855 |
'post_type' => 'lp_course', |
| 856 |
'author' => $user_id, |
| 857 |
'post_status' => 'publish', |
| 858 |
'ignore_sticky_posts' => true, |
| 859 |
'posts_per_page' => - 1, |
| 860 |
); |
| 861 |
$my_query = new WP_Query( $arr_query ); |
| 862 |
|
| 863 |
return $my_query; |
| 864 |
} |
| 865 |
|
| 866 |
/** |
| 867 |
* Return array list of currency positions. |
| 868 |
* |
| 869 |
* @param bool|string $currency |
| 870 |
* |
| 871 |
* @return array |
| 872 |
*/ |
| 873 |
function learn_press_currency_positions( $currency = false ) { |
| 874 |
$positions = array( |
| 875 |
'left' => __( 'Left', 'learnpress' ), |
| 876 |
'right' => __( 'Right', 'learnpress' ), |
| 877 |
'left_with_space' => __( 'Left with space', 'learnpress' ), |
| 878 |
'right_with_space' => __( 'Right with space', 'learnpress' ), |
| 879 |
); |
| 880 |
|
| 881 |
if ( false === $currency ) { |
| 882 |
$currency = learn_press_get_currency_symbol(); |
| 883 |
} |
| 884 |
|
| 885 |
$settings = LP_Settings::instance(); |
| 886 |
|
| 887 |
$thousands_separator = ''; |
| 888 |
$decimals_separator = $settings->get( 'decimals_separator', '.' ); |
| 889 |
$number_of_decimals = $settings->get( 'number_of_decimals', 2 ); |
| 890 |
|
| 891 |
if ( $number_of_decimals > 0 ) { |
| 892 |
$example = '69' . $decimals_separator . str_repeat( '9', $number_of_decimals ); |
| 893 |
} else { |
| 894 |
$example = '69'; |
| 895 |
} |
| 896 |
|
| 897 |
foreach ( $positions as $pos => $text ) { |
| 898 |
switch ( $pos ) { |
| 899 |
case 'left': |
| 900 |
$text = sprintf( '%s ( %s%s )', $text, $currency, $example ); |
| 901 |
break; |
| 902 |
case 'right': |
| 903 |
$text = sprintf( '%s ( %s%s )', $text, $example, $currency ); |
| 904 |
break; |
| 905 |
case 'left_with_space': |
| 906 |
$text = sprintf( '%s ( %s %s )', $text, $currency, $example ); |
| 907 |
break; |
| 908 |
case 'right_with_space': |
| 909 |
$text = sprintf( '%s ( %s %s )', $text, $example, $currency ); |
| 910 |
break; |
| 911 |
} |
| 912 |
$positions[ $pos ] = $text; |
| 913 |
} |
| 914 |
|
| 915 |
$positions = apply_filters( 'learn_press_currency_positions', $positions ); |
| 916 |
|
| 917 |
return apply_filters( 'learn-press/currency-positions', $positions ); |
| 918 |
} |
| 919 |
|
| 920 |
/** |
| 921 |
* @return array |
| 922 |
*/ |
| 923 |
function learn_press_get_payment_currencies() { |
| 924 |
return apply_filters( 'learn_press_get_payment_currencies', learn_press_currencies() ); |
| 925 |
} |
| 926 |
|
| 927 |
/** |
| 928 |
* Get the list of currencies with code and name. |
| 929 |
* |
| 930 |
* @return array |
| 931 |
* @version 3.0.0 |
| 932 |
* |
| 933 |
* @author ThimPress |
| 934 |
*/ |
| 935 |
function learn_press_currencies() { |
| 936 |
$currencies = array( |
| 937 |
'AFN' => __( 'Afghan afghani', 'learnpress' ), |
| 938 |
'ALL' => __( 'Albanian lek', 'learnpress' ), |
| 939 |
'DZD' => __( 'Algerian dinar', 'learnpress' ), |
| 940 |
'EUR' => __( 'Euro', 'learnpress' ), |
| 941 |
'AOA' => __( 'Angolan kwanza', 'learnpress' ), |
| 942 |
'XCD' => __( 'East Caribbean dollar', 'learnpress' ), |
| 943 |
'ARS' => __( 'Argentine peso', 'learnpress' ), |
| 944 |
'AMD' => __( 'Armenian dram', 'learnpress' ), |
| 945 |
'AWG' => __( 'Aruban florin', 'learnpress' ), |
| 946 |
'AUD' => __( 'Australian dollar', 'learnpress' ), |
| 947 |
'AZN' => __( 'Azerbaijani manat', 'learnpress' ), |
| 948 |
'BSD' => __( 'Bahamian dollar', 'learnpress' ), |
| 949 |
'BHD' => __( 'Bahraini dinar', 'learnpress' ), |
| 950 |
'BDT' => __( 'Bangladeshi taka', 'learnpress' ), |
| 951 |
'BBD' => __( 'Barbadian dollar', 'learnpress' ), |
| 952 |
'BYR' => __( 'Belarusian ruble', 'learnpress' ), |
| 953 |
'BZD' => __( 'Belizean dollar', 'learnpress' ), |
| 954 |
'XOF' => __( 'West African CFA franc', 'learnpress' ), |
| 955 |
'BMD' => __( 'Bermudian dollar', 'learnpress' ), |
| 956 |
'BTN' => __( 'Bhutanese ngultrum', 'learnpress' ), |
| 957 |
'BOB' => __( 'Bolivian boliviano', 'learnpress' ), |
| 958 |
'USD' => __( 'US dollar', 'learnpress' ), |
| 959 |
'BAM' => __( 'Bosnia and Herzegovina convertible mark', 'learnpress' ), |
| 960 |
'BWP' => __( 'Botswana pula', 'learnpress' ), |
| 961 |
'BRL' => __( 'Brazilian real', 'learnpress' ), |
| 962 |
'BND' => __( 'Brunei dollar', 'learnpress' ), |
| 963 |
'BGN' => __( 'Bulgarian lev', 'learnpress' ), |
| 964 |
'MMK' => __( 'Burmese kyat', 'learnpress' ), |
| 965 |
'BIF' => __( 'Burundian franc', 'learnpress' ), |
| 966 |
'KHR' => __( 'Cambodian riel', 'learnpress' ), |
| 967 |
'XAF' => __( 'Central African CFA franc', 'learnpress' ), |
| 968 |
'CAD' => __( 'Canadian dollar', 'learnpress' ), |
| 969 |
'CVE' => __( 'Cape Verdean escudo', 'learnpress' ), |
| 970 |
'KYD' => __( 'Cayman Islands dollar', 'learnpress' ), |
| 971 |
'CLP' => __( 'Chilean peso', 'learnpress' ), |
| 972 |
'CNY' => __( 'Chinese renminbi', 'learnpress' ), |
| 973 |
'COP' => __( 'Colombian peso', 'learnpress' ), |
| 974 |
'KMF' => __( 'Comorian franc', 'learnpress' ), |
| 975 |
'CDF' => __( 'Congolese franc', 'learnpress' ), |
| 976 |
'NZD' => __( 'New Zealand dollar', 'learnpress' ), |
| 977 |
'CRC' => __( 'Costa Rican colón', 'learnpress' ), |
| 978 |
'HRK' => __( 'Croatian kuna', 'learnpress' ), |
| 979 |
'CUC' => __( 'Cuban peso', 'learnpress' ), |
| 980 |
'ANG' => __( 'Netherlands Antilles guilder', 'learnpress' ), |
| 981 |
'CZK' => __( 'Czech koruna', 'learnpress' ), |
| 982 |
'DKK' => __( 'Danish krone', 'learnpress' ), |
| 983 |
'DJF' => __( 'Djiboutian franc', 'learnpress' ), |
| 984 |
'DOP' => __( 'Dominican peso', 'learnpress' ), |
| 985 |
'EGP' => __( 'Egyptian pound', 'learnpress' ), |
| 986 |
'SVC' => __( 'Salvadoran colón', 'learnpress' ), |
| 987 |
'ERN' => __( 'Eritrean nakfa', 'learnpress' ), |
| 988 |
'ETB' => __( 'Ethiopian birr', 'learnpress' ), |
| 989 |
'FKP' => __( 'Falkland Islands pound', 'learnpress' ), |
| 990 |
'FJD' => __( 'Fijian dollar', 'learnpress' ), |
| 991 |
'XPF' => __( 'CFP franc', 'learnpress' ), |
| 992 |
'GMD' => __( 'Gambian dalasi', 'learnpress' ), |
| 993 |
'GEL' => __( 'Georgian lari', 'learnpress' ), |
| 994 |
'GHS' => __( 'Ghanian cedi', 'learnpress' ), |
| 995 |
'GIP' => __( 'Gibraltar pound', 'learnpress' ), |
| 996 |
'GTQ' => __( 'Guatemalan quetzal', 'learnpress' ), |
| 997 |
'GBP' => __( 'British pound', 'learnpress' ), |
| 998 |
'GNF' => __( 'Guinean franc', 'learnpress' ), |
| 999 |
'GYD' => __( 'Guyanese dollar', 'learnpress' ), |
| 1000 |
'HTG' => __( 'Haitian gourde', 'learnpress' ), |
| 1001 |
'HNL' => __( 'Honduran lempira', 'learnpress' ), |
| 1002 |
'HKD' => __( 'Hong Kong dollar', 'learnpress' ), |
| 1003 |
'HUF' => __( 'Hungarian forint', 'learnpress' ), |
| 1004 |
'ISK' => __( 'Icelandic króna', 'learnpress' ), |
| 1005 |
'INR' => __( 'Indian rupee', 'learnpress' ), |
| 1006 |
'IDR' => __( 'Indonesian rupiah', 'learnpress' ), |
| 1007 |
'IRR' => __( 'Iranian rial', 'learnpress' ), |
| 1008 |
'IQD' => __( 'Iraqi dinar', 'learnpress' ), |
| 1009 |
'ILS' => __( 'Israeli new sheqel', 'learnpress' ), |
| 1010 |
'JMD' => __( 'Jamaican dollar', 'learnpress' ), |
| 1011 |
'JPY' => __( 'Japanese yen ', 'learnpress' ), |
| 1012 |
'JOD' => __( 'Jordanian dinar', 'learnpress' ), |
| 1013 |
'KZT' => __( 'Kazakhstani tenge', 'learnpress' ), |
| 1014 |
'KES' => __( 'Kenyan shilling', 'learnpress' ), |
| 1015 |
'KPW' => __( 'North Korean won', 'learnpress' ), |
| 1016 |
'KWD' => __( 'Kuwaiti dinar', 'learnpress' ), |
| 1017 |
'KGS' => __( 'Kyrgyzstani som', 'learnpress' ), |
| 1018 |
'KRW' => __( 'South Korean won', 'learnpress' ), |
| 1019 |
'LAK' => __( 'Lao kip', 'learnpress' ), |
| 1020 |
'LVL' => __( 'Latvian lats', 'learnpress' ), |
| 1021 |
'LBP' => __( 'Lebanese pound', 'learnpress' ), |
| 1022 |
'LSL' => __( 'Lesotho loti', 'learnpress' ), |
| 1023 |
'LRD' => __( 'Liberian dollar', 'learnpress' ), |
| 1024 |
'LD' => __( 'Libyan dinar', 'learnpress' ), |
| 1025 |
'CHF' => __( 'Swiss franc', 'learnpress' ), |
| 1026 |
'LTL' => __( 'Lithuanian litas', 'learnpress' ), |
| 1027 |
'MOP' => __( 'Macanese pataca', 'learnpress' ), |
| 1028 |
'MKD' => __( 'Macedonian denar', 'learnpress' ), |
| 1029 |
'MGA' => __( 'Malagasy ariary', 'learnpress' ), |
| 1030 |
'MWK' => __( 'Malawian kwacha', 'learnpress' ), |
| 1031 |
'MYR' => __( 'Malaysian ringgit', 'learnpress' ), |
| 1032 |
'MVR' => __( 'Maldivian rufiyaa', 'learnpress' ), |
| 1033 |
'MRO' => __( 'Mauritanian ouguiya', 'learnpress' ), |
| 1034 |
'MUR' => __( 'Mauritian rupee', 'learnpress' ), |
| 1035 |
'MXN' => __( 'Mexican peso', 'learnpress' ), |
| 1036 |
'MDL' => __( 'Moldovan leu', 'learnpress' ), |
| 1037 |
'MNT' => __( 'Mongolian tugrik', 'learnpress' ), |
| 1038 |
'MAD' => __( 'Moroccan dirham', 'learnpress' ), |
| 1039 |
'MZN' => __( 'Mozambican metical', 'learnpress' ), |
| 1040 |
'NAD' => __( 'Namibian dollar', 'learnpress' ), |
| 1041 |
'NPR' => __( 'Nepalese rupee', 'learnpress' ), |
| 1042 |
'NIO' => __( 'Nicaraguan córdoba', 'learnpress' ), |
| 1043 |
'NGN' => __( 'Nigerian naira', 'learnpress' ), |
| 1044 |
'NOK' => __( 'Norwegian krone', 'learnpress' ), |
| 1045 |
'OMR' => __( 'Omani rial', 'learnpress' ), |
| 1046 |
'PKR' => __( 'Pakistani rupee', 'learnpress' ), |
| 1047 |
'PAB' => __( 'Panamanian balboa', 'learnpress' ), |
| 1048 |
'PGK' => __( 'Papua New Guinea kina', 'learnpress' ), |
| 1049 |
'PYG' => __( 'Paraguayan guarani', 'learnpress' ), |
| 1050 |
'PEN' => __( 'Peruvian nuevo sol', 'learnpress' ), |
| 1051 |
'PHP' => __( 'Philippine peso', 'learnpress' ), |
| 1052 |
'PLN' => __( 'Polish zloty', 'learnpress' ), |
| 1053 |
'QAR' => __( 'Qatari riyal', 'learnpress' ), |
| 1054 |
'RON' => __( 'Romanian leu', 'learnpress' ), |
| 1055 |
'RUB' => __( 'Russian ruble', 'learnpress' ), |
| 1056 |
'RWF' => __( 'Rwandan franc', 'learnpress' ), |
| 1057 |
'WST' => __( 'Samoan tālā', 'learnpress' ), |
| 1058 |
'STD' => __( 'São Tomé and Príncipe dobra', 'learnpress' ), |
| 1059 |
'SAR' => __( 'Saudi riyal', 'learnpress' ), |
| 1060 |
'RSD' => __( 'Serbian dinar', 'learnpress' ), |
| 1061 |
'SCR' => __( 'Seychellois rupee', 'learnpress' ), |
| 1062 |
'SLL' => __( 'Sierra Leonean leone', 'learnpress' ), |
| 1063 |
'SGD' => __( 'Singapore dollar', 'learnpress' ), |
| 1064 |
'SBD' => __( 'Solomon Islands dollar', 'learnpress' ), |
| 1065 |
'SOS' => __( 'Somali shilling', 'learnpress' ), |
| 1066 |
'ZAR' => __( 'South African rand', 'learnpress' ), |
| 1067 |
'LKR' => __( 'Sri Lankan rupee', 'learnpress' ), |
| 1068 |
'SHP' => __( 'St. Helena pound', 'learnpress' ), |
| 1069 |
'SDG' => __( 'Sudanese pound', 'learnpress' ), |
| 1070 |
'SRD' => __( 'Surinamese dollar', 'learnpress' ), |
| 1071 |
'SZL' => __( 'Swazi lilangeni', 'learnpress' ), |
| 1072 |
'SEK' => __( 'Swedish krona', 'learnpress' ), |
| 1073 |
'SYP' => __( 'Syrian pound', 'learnpress' ), |
| 1074 |
'TWD' => __( 'New Taiwan dollar', 'learnpress' ), |
| 1075 |
'TJS' => __( 'Tajikistani somoni', 'learnpress' ), |
| 1076 |
'TZS' => __( 'Tanzanian shilling', 'learnpress' ), |
| 1077 |
'THB' => __( 'Thai baht ', 'learnpress' ), |
| 1078 |
'TOP' => __( 'Tongan pa’anga', 'learnpress' ), |
| 1079 |
'TTD' => __( 'Trinidad and Tobago dollar', 'learnpress' ), |
| 1080 |
'TND' => __( 'Tunisian dinar', 'learnpress' ), |
| 1081 |
'TRY' => __( 'Turkish lira', 'learnpress' ), |
| 1082 |
'TMT' => __( 'Turkmenistani manat', 'learnpress' ), |
| 1083 |
'UGX' => __( 'Ugandan shilling', 'learnpress' ), |
| 1084 |
'UAH' => __( 'Ukrainian hryvnia', 'learnpress' ), |
| 1085 |
'AED' => __( 'United Arab Emirates dirham', 'learnpress' ), |
| 1086 |
'UYU' => __( 'Uruguayan peso', 'learnpress' ), |
| 1087 |
'UZS' => __( 'Uzbekistani som', 'learnpress' ), |
| 1088 |
'VUV' => __( 'Vanuatu vatu', 'learnpress' ), |
| 1089 |
'VEF' => __( 'Venezuelan bolivar', 'learnpress' ), |
| 1090 |
'VND' => __( 'Vietnamese dong', 'learnpress' ), |
| 1091 |
'YER' => __( 'Yemeni rial', 'learnpress' ), |
| 1092 |
'ZMK' => __( 'Zambian kwacha', 'learnpress' ), |
| 1093 |
'ZWL' => __( 'Zimbabwean dollar', 'learnpress' ), |
| 1094 |
'JEP' => __( 'Jersey pound', 'learnpress' ), |
| 1095 |
'LYD' => __( 'Libyan dinar', 'learnpress' ), |
| 1096 |
); |
| 1097 |
|
| 1098 |
asort( $currencies ); |
| 1099 |
|
| 1100 |
return apply_filters( 'learn-press/currencies', $currencies ); |
| 1101 |
} |
| 1102 |
|
| 1103 |
/** |
| 1104 |
* Get current setting of currency. |
| 1105 |
* |
| 1106 |
* @return string |
| 1107 |
*/ |
| 1108 |
function learn_press_get_currency() { |
| 1109 |
$currency = apply_filters( 'learn_press_currency', LP_Settings::instance()->get( 'currency', 'USD' ) ); |
| 1110 |
|
| 1111 |
return apply_filters( 'learn-press/currency', $currency ); |
| 1112 |
} |
| 1113 |
|
| 1114 |
/** |
| 1115 |
* Return list of common symbols of the currencies on the world. |
| 1116 |
* |
| 1117 |
* @return array |
| 1118 |
*/ |
| 1119 |
function learn_press_currency_symbols() { |
| 1120 |
$symbols = array( |
| 1121 |
'AED' => 'د.إ', |
| 1122 |
'AFN' => '؋', |
| 1123 |
'ALL' => 'L', |
| 1124 |
'AMD' => 'AMD', |
| 1125 |
'ANG' => 'ƒ', |
| 1126 |
'AOA' => 'Kz', |
| 1127 |
'ARS' => '$', |
| 1128 |
'AUD' => '$', |
| 1129 |
'AWG' => 'Afl.', |
| 1130 |
'AZN' => 'AZN', |
| 1131 |
'BAM' => 'KM', |
| 1132 |
'BBD' => '$', |
| 1133 |
'BDT' => '৳ ', |
| 1134 |
'BGN' => 'лв.', |
| 1135 |
'BHD' => '.د.ب', |
| 1136 |
'BIF' => 'Fr', |
| 1137 |
'BMD' => '$', |
| 1138 |
'BND' => '$', |
| 1139 |
'BOB' => 'Bs.', |
| 1140 |
'BRL' => 'R$', |
| 1141 |
'BSD' => '$', |
| 1142 |
'BTC' => '฿', |
| 1143 |
'BTN' => 'Nu.', |
| 1144 |
'BWP' => 'P', |
| 1145 |
'BYR' => 'Br', |
| 1146 |
'BYN' => 'Br', |
| 1147 |
'BZD' => '$', |
| 1148 |
'CAD' => '$', |
| 1149 |
'CDF' => 'Fr', |
| 1150 |
'CHF' => 'CHF', |
| 1151 |
'CLP' => '$', |
| 1152 |
'CNY' => '¥', |
| 1153 |
'COP' => '$', |
| 1154 |
'CRC' => '₡', |
| 1155 |
'CUC' => '$', |
| 1156 |
'CUP' => '$', |
| 1157 |
'CVE' => '$', |
| 1158 |
'CZK' => 'Kč', |
| 1159 |
'DJF' => 'Fr', |
| 1160 |
'DKK' => 'DKK', |
| 1161 |
'DOP' => 'RD$', |
| 1162 |
'DZD' => 'د.ج', |
| 1163 |
'EGP' => 'EGP', |
| 1164 |
'ERN' => 'Nfk', |
| 1165 |
'ETB' => 'Br', |
| 1166 |
'EUR' => '€', |
| 1167 |
'FJD' => '$', |
| 1168 |
'FKP' => '£', |
| 1169 |
'GBP' => '£', |
| 1170 |
'GEL' => '₾', |
| 1171 |
'GGP' => '£', |
| 1172 |
'GHS' => '₵', |
| 1173 |
'GIP' => '£', |
| 1174 |
'GMD' => 'D', |
| 1175 |
'GNF' => 'Fr', |
| 1176 |
'GTQ' => 'Q', |
| 1177 |
'GYD' => '$', |
| 1178 |
'HKD' => '$', |
| 1179 |
'HNL' => 'L', |
| 1180 |
'HRK' => 'kn', |
| 1181 |
'HTG' => 'G', |
| 1182 |
'HUF' => 'Ft', |
| 1183 |
'IDR' => 'Rp', |
| 1184 |
'ILS' => '₪', |
| 1185 |
'IMP' => '£', |
| 1186 |
'INR' => '₹', |
| 1187 |
'IQD' => 'ع.د', |
| 1188 |
'IRR' => '﷼', |
| 1189 |
'IRT' => 'تومان', |
| 1190 |
'ISK' => 'kr.', |
| 1191 |
'JEP' => '£', |
| 1192 |
'JMD' => '$', |
| 1193 |
'JOD' => 'د.ا', |
| 1194 |
'JPY' => '¥', |
| 1195 |
'KES' => 'KSh', |
| 1196 |
'KGS' => 'сом', |
| 1197 |
'KHR' => '៛', |
| 1198 |
'KMF' => 'Fr', |
| 1199 |
'KPW' => '₩', |
| 1200 |
'KRW' => '₩', |
| 1201 |
'KWD' => 'د.ك', |
| 1202 |
'KYD' => '$', |
| 1203 |
'KZT' => '₸', |
| 1204 |
'LAK' => '₭', |
| 1205 |
'LBP' => 'ل.ل', |
| 1206 |
'LKR' => 'රු', |
| 1207 |
'LRD' => '$', |
| 1208 |
'LSL' => 'L', |
| 1209 |
'LYD' => 'ل.د', |
| 1210 |
'MAD' => 'د.م.', |
| 1211 |
'MDL' => 'MDL', |
| 1212 |
'MGA' => 'Ar', |
| 1213 |
'MKD' => 'ден', |
| 1214 |
'MMK' => 'Ks', |
| 1215 |
'MNT' => '₮', |
| 1216 |
'MOP' => 'P', |
| 1217 |
'MRU' => 'UM', |
| 1218 |
'MUR' => '₨', |
| 1219 |
'MVR' => '.ރ', |
| 1220 |
'MWK' => 'MK', |
| 1221 |
'MXN' => '$', |
| 1222 |
'MYR' => 'RM', |
| 1223 |
'MZN' => 'MT', |
| 1224 |
'NAD' => 'N$', |
| 1225 |
'NGN' => '₦', |
| 1226 |
'NIO' => 'C$', |
| 1227 |
'NOK' => 'kr', |
| 1228 |
'NPR' => '₨', |
| 1229 |
'NZD' => '$', |
| 1230 |
'OMR' => 'ر.ع.', |
| 1231 |
'PAB' => 'B/.', |
| 1232 |
'PEN' => 'S/', |
| 1233 |
'PGK' => 'K', |
| 1234 |
'PHP' => '₱', |
| 1235 |
'PKR' => '₨', |
| 1236 |
'PLN' => 'zł', |
| 1237 |
'PRB' => 'р.', |
| 1238 |
'PYG' => '₲', |
| 1239 |
'QAR' => 'ر.ق', |
| 1240 |
'RMB' => '¥', |
| 1241 |
'RON' => 'lei', |
| 1242 |
'RSD' => 'рсд', |
| 1243 |
'RUB' => '₽', |
| 1244 |
'RWF' => 'Fr', |
| 1245 |
'SAR' => 'ر.س', |
| 1246 |
'SBD' => '$', |
| 1247 |
'SCR' => '₨', |
| 1248 |
'SDG' => 'ج.س.', |
| 1249 |
'SEK' => 'kr', |
| 1250 |
'SGD' => '$', |
| 1251 |
'SHP' => '£', |
| 1252 |
'SLL' => 'Le', |
| 1253 |
'SOS' => 'Sh', |
| 1254 |
'SRD' => '$', |
| 1255 |
'SSP' => '£', |
| 1256 |
'STN' => 'Db', |
| 1257 |
'SYP' => 'ل.س', |
| 1258 |
'SZL' => 'L', |
| 1259 |
'THB' => '฿', |
| 1260 |
'TJS' => 'ЅМ', |
| 1261 |
'TMT' => 'm', |
| 1262 |
'TND' => 'د.ت', |
| 1263 |
'TOP' => 'T$', |
| 1264 |
'TRY' => '₺', |
| 1265 |
'TTD' => '$', |
| 1266 |
'TWD' => 'NT$', |
| 1267 |
'TZS' => 'Sh', |
| 1268 |
'UAH' => '₴', |
| 1269 |
'UGX' => 'UGX', |
| 1270 |
'USD' => '$', |
| 1271 |
'UYU' => '$', |
| 1272 |
'UZS' => 'UZS', |
| 1273 |
'VEF' => 'Bs F', |
| 1274 |
'VES' => 'Bs.S', |
| 1275 |
'VND' => '₫', |
| 1276 |
'VUV' => 'Vt', |
| 1277 |
'WST' => 'T', |
| 1278 |
'XAF' => 'CFA', |
| 1279 |
'XCD' => '$', |
| 1280 |
'XOF' => 'CFA', |
| 1281 |
'XPF' => 'Fr', |
| 1282 |
'YER' => '﷼', |
| 1283 |
'ZAR' => 'R', |
| 1284 |
'ZMW' => 'ZK', |
| 1285 |
); |
| 1286 |
|
| 1287 |
return apply_filters( 'learn-press/currency-symbols', $symbols ); |
| 1288 |
} |
| 1289 |
|
| 1290 |
/** |
| 1291 |
* Return currency symbol from the code. |
| 1292 |
* |
| 1293 |
* @param string $currency |
| 1294 |
* |
| 1295 |
* @return string |
| 1296 |
*/ |
| 1297 |
function learn_press_get_currency_symbol( $currency = '' ) { |
| 1298 |
if ( ! $currency ) { |
| 1299 |
$currency = learn_press_get_currency(); |
| 1300 |
} |
| 1301 |
$symbols = learn_press_currency_symbols(); |
| 1302 |
$currency_symbol = isset( $symbols[ $currency ] ) ? $symbols[ $currency ] : ''; |
| 1303 |
|
| 1304 |
$currency_symbol = apply_filters( 'learn_press_currency_symbol', $currency_symbol, $currency ); |
| 1305 |
|
| 1306 |
return apply_filters( 'learn-press/currency-symbol', $currency_symbol, $currency ); |
| 1307 |
} |
| 1308 |
|
| 1309 |
/** |
| 1310 |
* Get static page for LP page by name. |
| 1311 |
* |
| 1312 |
* @param string $key |
| 1313 |
* |
| 1314 |
* @return string |
| 1315 |
* @editor tungnx |
| 1316 |
* @modify 4.1.4 |
| 1317 |
*/ |
| 1318 |
function learn_press_get_page_link( string $key ): string { |
| 1319 |
$page_id = learn_press_get_page_id( $key ); |
| 1320 |
$link = ''; |
| 1321 |
|
| 1322 |
if ( $page_id && get_post_status( $page_id ) == 'publish' ) { |
| 1323 |
$permalink = get_permalink( $page_id ); |
| 1324 |
$link = apply_filters( 'learn-press/get-page-link', trailingslashit( $permalink ), $page_id, $key ); |
| 1325 |
} |
| 1326 |
|
| 1327 |
return $link; |
| 1328 |
} |
| 1329 |
|
| 1330 |
/** |
| 1331 |
* Get static page for LP page by name. |
| 1332 |
* |
| 1333 |
* @param string $key |
| 1334 |
* |
| 1335 |
* @return string |
| 1336 |
*/ |
| 1337 |
function learn_press_get_page_title( $key ) { |
| 1338 |
$page_id = LP_Settings::instance()->get( $key . '_page_id' ); |
| 1339 |
$title = ''; |
| 1340 |
|
| 1341 |
if ( $page_id && get_post_status( $page_id ) == 'publish' ) { |
| 1342 |
$title = apply_filters( 'learn-press/get-page-title', get_the_title( $page_id ), $page_id, $key ); |
| 1343 |
} |
| 1344 |
|
| 1345 |
return apply_filters( 'learn-press/get-page-' . $key . '-title', $title, $page_id ); |
| 1346 |
} |
| 1347 |
|
| 1348 |
/** |
| 1349 |
* get the ID of a course by order ID |
| 1350 |
* |
| 1351 |
* @param $order_id |
| 1352 |
* |
| 1353 |
* @return bool|mixed |
| 1354 |
*/ |
| 1355 |
function learn_press_get_course_by_order( $order_id ) { |
| 1356 |
$order_items = get_post_meta( $order_id, '_learn_press_order_items', true ); |
| 1357 |
|
| 1358 |
if ( $order_items && $order_items->products ) { |
| 1359 |
$array_keys = array_keys( $order_items->products ); |
| 1360 |
|
| 1361 |
return reset( $array_keys ); |
| 1362 |
} |
| 1363 |
|
| 1364 |
return false; |
| 1365 |
} |
| 1366 |
|
| 1367 |
/** |
| 1368 |
* Convert a number of seconds to weeks/days/hours. |
| 1369 |
* |
| 1370 |
* @param int $secs |
| 1371 |
* |
| 1372 |
* @return bool|string |
| 1373 |
*/ |
| 1374 |
function learn_press_seconds_to_weeks( int $secs = 0 ) { |
| 1375 |
$secs = (int) $secs; |
| 1376 |
|
| 1377 |
if ( 0 === $secs ) { |
| 1378 |
return false; |
| 1379 |
} |
| 1380 |
// variables for holding values. |
| 1381 |
$mins = 0; |
| 1382 |
$hours = 0; |
| 1383 |
$days = 0; |
| 1384 |
$weeks = 0; |
| 1385 |
// calculations. |
| 1386 |
if ( $secs >= 60 ) { |
| 1387 |
$mins = (int) ( $secs / 60 ); |
| 1388 |
$secs = $secs % 60; |
| 1389 |
} |
| 1390 |
if ( $mins >= 60 ) { |
| 1391 |
$hours = (int) ( $mins / 60 ); |
| 1392 |
$mins = $mins % 60; |
| 1393 |
} |
| 1394 |
if ( $hours >= 24 ) { |
| 1395 |
$days = (int) ( $hours / 24 ); |
| 1396 |
$hours = $hours % 24; |
| 1397 |
} |
| 1398 |
if ( $days >= 7 ) { |
| 1399 |
$weeks = (int) ( $days / 7 ); |
| 1400 |
$days = $days % 7; |
| 1401 |
} |
| 1402 |
// format result. |
| 1403 |
$result = ''; |
| 1404 |
if ( $weeks ) { |
| 1405 |
$result .= sprintf( _n( '%s week', '%s weeks', $weeks, 'learnpress' ), $weeks ) . ' '; |
| 1406 |
} |
| 1407 |
|
| 1408 |
if ( $days ) { |
| 1409 |
$result .= sprintf( _n( '%s day', '%s days', $days, 'learnpress' ), $days ) . ' '; |
| 1410 |
} |
| 1411 |
|
| 1412 |
if ( ! $weeks ) { |
| 1413 |
if ( $hours ) { |
| 1414 |
$result .= sprintf( _n( '%s hour', '%s hours', $hours, 'learnpress' ), $hours ) . ' '; |
| 1415 |
} |
| 1416 |
|
| 1417 |
if ( $mins ) { |
| 1418 |
$result .= sprintf( _n( '%s minute', '%s minutes', $mins, 'learnpress' ), $mins ) . ' '; |
| 1419 |
} |
| 1420 |
} |
| 1421 |
|
| 1422 |
$result = rtrim( $result ); |
| 1423 |
|
| 1424 |
return $result; |
| 1425 |
} |
| 1426 |
|
| 1427 |
add_filter( 'learn_press_course_lesson_permalink', 'learn_press_course_lesson_permalink_friendly', 10, 3 ); |
| 1428 |
function learn_press_course_lesson_permalink_friendly( $permalink, $lesson_id, $course_id ) { |
| 1429 |
if ( '' != get_option( 'permalink_structure' ) ) { |
| 1430 |
if ( preg_match( '!\?lesson=([^\?\&]*)!', $permalink, $matches ) ) { |
| 1431 |
$permalink = preg_replace( |
| 1432 |
'!/?\?lesson=([^\?\&]*)!', |
| 1433 |
'/' . basename( get_permalink( $matches[1] ) ), |
| 1434 |
untrailingslashit( $permalink ) |
| 1435 |
); |
| 1436 |
} |
| 1437 |
} |
| 1438 |
|
| 1439 |
return $permalink; |
| 1440 |
} |
| 1441 |
|
| 1442 |
/** |
| 1443 |
* @deprecated 4.1.7.3 |
| 1444 |
*/ |
| 1445 |
function learn_press_course_question_permalink_friendly( $permalink, $lesson_id, $course_id ) { |
| 1446 |
_deprecated_function( __FUNCTION__, '4.1.7.3' ); |
| 1447 |
if ( '' != get_option( 'permalink_structure' ) ) { |
| 1448 |
if ( preg_match( '!\?lesson=([^\?\&]*)!', $permalink, $matches ) ) { |
| 1449 |
$permalink = preg_replace( |
| 1450 |
'!/?\?lesson=([^\?\&]*)!', |
| 1451 |
'/' . basename( get_permalink( $matches[1] ) ), |
| 1452 |
untrailingslashit( $permalink ) |
| 1453 |
); |
| 1454 |
} |
| 1455 |
} |
| 1456 |
|
| 1457 |
return $permalink; |
| 1458 |
} |
| 1459 |
|
| 1460 |
function learn_press_user_maybe_is_a_teacher( $user = null ) { |
| 1461 |
if ( ! $user ) { |
| 1462 |
$user = learn_press_get_current_user(); |
| 1463 |
} elseif ( is_numeric( $user ) ) { |
| 1464 |
$user = learn_press_get_user( $user ); |
| 1465 |
} |
| 1466 |
if ( ! $user || $user instanceof LP_User_Guest ) { |
| 1467 |
return false; |
| 1468 |
} |
| 1469 |
|
| 1470 |
$role = $user->has_role( 'administrator' ) ? 'administrator' : false; |
| 1471 |
if ( ! $role ) { |
| 1472 |
$role = $user->has_role( 'lp_teacher' ) ? 'lp_teacher' : false; |
| 1473 |
} |
| 1474 |
|
| 1475 |
return apply_filters( 'learn-press/user/is-teacher', $role, $user->get_id() ); |
| 1476 |
} |
| 1477 |
|
| 1478 |
function learn_press_become_teacher_sent( $user_id = 0 ) { |
| 1479 |
if ( func_num_args() == 0 ) { |
| 1480 |
$user_id = get_current_user_id(); |
| 1481 |
} |
| 1482 |
|
| 1483 |
return 'yes' === get_user_meta( $user_id, '_requested_become_teacher', true ); |
| 1484 |
} |
| 1485 |
|
| 1486 |
function _learn_press_translate_user_roles( $translations, $text, $context, $domain ) { |
| 1487 |
$plugin_domain = 'learnpress'; |
| 1488 |
$roles = array( 'LP Instructor' ); |
| 1489 |
|
| 1490 |
if ( $context === 'User role' && in_array( $text, $roles ) && $domain !== $plugin_domain ) { |
| 1491 |
return translate_with_gettext_context( $text, $context, $plugin_domain ); |
| 1492 |
} |
| 1493 |
|
| 1494 |
return $translations; |
| 1495 |
} |
| 1496 |
|
| 1497 |
add_filter( 'gettext_with_context', '_learn_press_translate_user_roles', 10, 4 ); |
| 1498 |
|
| 1499 |
/** |
| 1500 |
* Modifies the statement $where to make the search works correct |
| 1501 |
* |
| 1502 |
* @param string |
| 1503 |
* |
| 1504 |
* @return string |
| 1505 |
* @deprecated 4.1.7.2 |
| 1506 |
*/ |
| 1507 |
//function learn_press_posts_where_statement_search( $where ) { |
| 1508 |
// // gets the global query var object |
| 1509 |
// global $wp_query, $wpdb; |
| 1510 |
// |
| 1511 |
// /** |
| 1512 |
// * Need to wrap this block into () in order to make it works correctly when filter by specific post type => maybe a bug :) |
| 1513 |
// * from => ( wp_2_posts.post_status = 'publish' OR wp_2_posts.post_status = 'private') OR wp_2_terms.name LIKE '%s%' |
| 1514 |
// * to => ( ( wp_2_posts.post_status = 'publish' OR wp_2_posts.post_status = 'private') OR wp_2_terms.name LIKE '%s%' ) |
| 1515 |
// */ |
| 1516 |
// $a = preg_match( '!(' . $wpdb->posts . '.post_status)!', $where ); |
| 1517 |
// $b = preg_match( '!(OR\s+' . $wpdb->terms . '.name LIKE \'%' . $wp_query->get( 's' ) . '%\')!', $where ); |
| 1518 |
// |
| 1519 |
// if ( $a && $b ) { |
| 1520 |
// // append ( to the start of the block |
| 1521 |
// $where = preg_replace( '!(' . $wpdb->posts . '.post_status)!', '( $1', $where, 1 ); |
| 1522 |
// |
| 1523 |
// // append ) to the end of the block |
| 1524 |
// $where = preg_replace( |
| 1525 |
// '!(OR\s+' . $wpdb->terms . '.name LIKE \'%' . $wp_query->get( 's' ) . '%\')!', |
| 1526 |
// '$1 )', |
| 1527 |
// $where |
| 1528 |
// ); |
| 1529 |
// } |
| 1530 |
// remove_filter( 'posts_where', 'learn_press_posts_where_statement_search', 99 ); |
| 1531 |
// |
| 1532 |
// return $where; |
| 1533 |
//} |
| 1534 |
|
| 1535 |
/** |
| 1536 |
* Filter post type for search function |
| 1537 |
* Only search lpr_course if see the param ref=course in request |
| 1538 |
* |
| 1539 |
* @param WP_Query $q |
| 1540 |
* @deprecated 4.1.7.2 |
| 1541 |
*/ |
| 1542 |
/*function learn_press_filter_search( $q ) { |
| 1543 |
if ( $q->is_main_query() && $q->is_search() && ( ! empty( $_REQUEST['ref'] ) && sanitize_text_field( $_REQUEST['ref'] ) == 'course' ) ) { |
| 1544 |
$q->set( 'post_type', 'lp_course' ); |
| 1545 |
|
| 1546 |
add_filter( 'posts_where', 'learn_press_posts_where_statement_search', 99 ); |
| 1547 |
remove_filter( 'pre_get_posts', 'learn_press_filter_search', 99 ); |
| 1548 |
} |
| 1549 |
}*/ |
| 1550 |
//add_filter( 'pre_get_posts', 'learn_press_filter_search', 99 ); |
| 1551 |
|
| 1552 |
if ( ! function_exists( 'learn_press_send_json' ) ) { |
| 1553 |
function learn_press_send_json( $data ) { |
| 1554 |
echo '<-- LP_AJAX_START -->'; |
| 1555 |
echo wp_json_encode( $data ); |
| 1556 |
echo '<-- LP_AJAX_END -->'; |
| 1557 |
die; |
| 1558 |
} |
| 1559 |
} |
| 1560 |
|
| 1561 |
/** |
| 1562 |
* Send json with success signal to browser. |
| 1563 |
* |
| 1564 |
* @param array|object|WP_Error $data |
| 1565 |
* |
| 1566 |
* @since 3.0.1 |
| 1567 |
*/ |
| 1568 |
function learn_press_send_json_error( $data = '' ) { |
| 1569 |
$response = array( 'success' => false ); |
| 1570 |
|
| 1571 |
if ( isset( $data ) ) { |
| 1572 |
if ( is_wp_error( $data ) ) { |
| 1573 |
$result = array(); |
| 1574 |
foreach ( $data->errors as $code => $messages ) { |
| 1575 |
foreach ( $messages as $message ) { |
| 1576 |
$result[] = array( |
| 1577 |
'code' => $code, |
| 1578 |
'message' => $message, |
| 1579 |
); |
| 1580 |
} |
| 1581 |
} |
| 1582 |
|
| 1583 |
$response['data'] = $result; |
| 1584 |
} else { |
| 1585 |
$response['data'] = $data; |
| 1586 |
} |
| 1587 |
} |
| 1588 |
|
| 1589 |
learn_press_send_json( $response ); |
| 1590 |
} |
| 1591 |
|
| 1592 |
/** |
| 1593 |
* Send json with error signal to browser. |
| 1594 |
* |
| 1595 |
* @param array|object|WP_Error $data |
| 1596 |
* |
| 1597 |
* @since 3.0.0 |
| 1598 |
*/ |
| 1599 |
function learn_press_send_json_success( $data = '' ) { |
| 1600 |
$response = array( 'success' => true ); |
| 1601 |
|
| 1602 |
if ( isset( $data ) ) { |
| 1603 |
$response['data'] = $data; |
| 1604 |
} |
| 1605 |
|
| 1606 |
learn_press_send_json( $response ); |
| 1607 |
} |
| 1608 |
|
| 1609 |
/** |
| 1610 |
* Check if ajax is calling then send json data. |
| 1611 |
* |
| 1612 |
* @param array $data |
| 1613 |
* @param mixed $callback |
| 1614 |
* |
| 1615 |
* @return bool |
| 1616 |
*/ |
| 1617 |
function learn_press_maybe_send_json( $data, $callback = null ) { |
| 1618 |
if ( learn_press_is_ajax() ) { |
| 1619 |
is_callable( $callback ) && call_user_func( $callback ); |
| 1620 |
$message = learn_press_get_messages( true ); |
| 1621 |
if ( empty( $data['message'] ) && $message ) { |
| 1622 |
$data['message'] = $message; |
| 1623 |
} |
| 1624 |
learn_press_send_json( $data ); |
| 1625 |
} |
| 1626 |
|
| 1627 |
return false; |
| 1628 |
} |
| 1629 |
|
| 1630 |
/** |
| 1631 |
* Get data from request. |
| 1632 |
* |
| 1633 |
* @param string $key |
| 1634 |
* @param mixed $default |
| 1635 |
* @param mixed $hash |
| 1636 |
* |
| 1637 |
* @return mixed |
| 1638 |
*/ |
| 1639 |
function learn_press_get_request( $key, $default = null, $hash = null ) { |
| 1640 |
$return = $default; |
| 1641 |
|
| 1642 |
if ( $hash ) { |
| 1643 |
if ( ! empty( $hash[ $key ] ) ) { |
| 1644 |
$return = $hash[ $key ]; |
| 1645 |
} |
| 1646 |
} else { |
| 1647 |
if ( ! empty( $_POST[ $key ] ) ) { |
| 1648 |
$return = LP_Helper::sanitize_params_submitted( $_POST[ $key ] ); |
| 1649 |
} elseif ( ! empty( $_GET[ $key ] ) ) { |
| 1650 |
$return = LP_Helper::sanitize_params_submitted( $_GET[ $key ] ); |
| 1651 |
} elseif ( ! empty( $_REQUEST[ $key ] ) ) { |
| 1652 |
$return = LP_Helper::sanitize_params_submitted( $_REQUEST[ $key ] ); |
| 1653 |
} |
| 1654 |
} |
| 1655 |
|
| 1656 |
return $return; |
| 1657 |
} |
| 1658 |
|
| 1659 |
/** |
| 1660 |
* @return mixed |
| 1661 |
*/ |
| 1662 |
function is_learnpress() { |
| 1663 |
return apply_filters( |
| 1664 |
'is_learnpress', |
| 1665 |
( learn_press_is_course_archive() || learn_press_is_course_taxonomy() || learn_press_is_course() || learn_press_is_quiz() || learn_press_is_search() ) ? true : false |
| 1666 |
); |
| 1667 |
} |
| 1668 |
|
| 1669 |
if ( ! function_exists( 'learn_press_is_search' ) ) { |
| 1670 |
function learn_press_is_search() { |
| 1671 |
return array_key_exists( 's', $_REQUEST ) && array_key_exists( 'ref', $_REQUEST ) && sanitize_text_field( $_REQUEST['ref'] ) == 'course'; |
| 1672 |
} |
| 1673 |
} |
| 1674 |
|
| 1675 |
if ( ! function_exists( 'learn_press_is_courses' ) ) { |
| 1676 |
function learn_press_is_courses() { |
| 1677 |
return learn_press_is_course_archive(); |
| 1678 |
} |
| 1679 |
} |
| 1680 |
|
| 1681 |
|
| 1682 |
if ( ! function_exists( 'learn_press_is_course_archive' ) ) { |
| 1683 |
function learn_press_is_course_archive() { |
| 1684 |
global $wp_query; |
| 1685 |
|
| 1686 |
$queried_object_id = ! empty( $wp_query->queried_object ) ? $wp_query->queried_object : 0; |
| 1687 |
$is_tag = defined( 'LEARNPRESS_IS_TAG' ) && LEARNPRESS_IS_TAG || is_tax( 'course_tag' ); |
| 1688 |
$is_category = defined( 'LEARNPRESS_IS_CATEGORY' ) && LEARNPRESS_IS_CATEGORY || is_tax( 'course_category' ); |
| 1689 |
$page_id = learn_press_get_page_id( 'courses' ); |
| 1690 |
|
| 1691 |
return ( $is_category || $is_tag ) || is_post_type_archive( 'lp_course' ) || ( $page_id && ( $queried_object_id && is_page( $page_id ) ) ); |
| 1692 |
} |
| 1693 |
} |
| 1694 |
|
| 1695 |
if ( ! function_exists( 'learn_press_is_course_tax' ) ) { |
| 1696 |
function learn_press_is_course_tax() { |
| 1697 |
return is_tax( get_object_taxonomies( LP_COURSE_CPT ) ); |
| 1698 |
} |
| 1699 |
} |
| 1700 |
|
| 1701 |
if ( ! function_exists( 'learn_press_is_course_taxonomy' ) ) { |
| 1702 |
function learn_press_is_course_taxonomy() { |
| 1703 |
return ( defined( 'LEARNPRESS_IS_TAX' ) && LEARNPRESS_IS_TAX ) || learn_press_is_course_tax(); |
| 1704 |
} |
| 1705 |
} |
| 1706 |
|
| 1707 |
|
| 1708 |
if ( ! function_exists( 'learn_press_is_course_category' ) ) { |
| 1709 |
function learn_press_is_course_category( $term = '' ) { |
| 1710 |
return ( defined( 'LEARNPRESS_IS_CATEGORY' ) && LEARNPRESS_IS_CATEGORY ) || is_tax( 'course_category', $term ); |
| 1711 |
} |
| 1712 |
} |
| 1713 |
|
| 1714 |
|
| 1715 |
if ( ! function_exists( 'learn_press_is_course_tag' ) ) { |
| 1716 |
function learn_press_is_course_tag( $term = '' ) { |
| 1717 |
return ( defined( 'LEARNPRESS_IS_TAG' ) && LEARNPRESS_IS_TAG ) || is_tax( 'course_tag', $term ); |
| 1718 |
} |
| 1719 |
} |
| 1720 |
|
| 1721 |
if ( ! function_exists( 'learn_press_is_course' ) ) { |
| 1722 |
function learn_press_is_course() { |
| 1723 |
/** |
| 1724 |
* @var WP_Query $wp_query |
| 1725 |
*/ |
| 1726 |
global $wp_query; |
| 1727 |
|
| 1728 |
if ( $wp_query->get_queried_object() ) { |
| 1729 |
return is_singular( array( LP_COURSE_CPT ) ); |
| 1730 |
} else { |
| 1731 |
return false; |
| 1732 |
} |
| 1733 |
} |
| 1734 |
} |
| 1735 |
|
| 1736 |
if ( ! function_exists( 'learn_press_is_lesson' ) ) { |
| 1737 |
function learn_press_is_lesson() { |
| 1738 |
return is_singular( array( LP_LESSON_CPT ) ); |
| 1739 |
} |
| 1740 |
} |
| 1741 |
|
| 1742 |
if ( ! function_exists( 'learn_press_is_quiz' ) ) { |
| 1743 |
function learn_press_is_quiz() { |
| 1744 |
return is_singular( array( LP_QUIZ_CPT ) ); |
| 1745 |
} |
| 1746 |
} |
| 1747 |
|
| 1748 |
function lp_content_has_shortcode( $tag = '' ) { |
| 1749 |
global $post; |
| 1750 |
|
| 1751 |
return is_singular() && is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, $tag ); |
| 1752 |
} |
| 1753 |
|
| 1754 |
/** |
| 1755 |
* Returns true when viewing profile page. |
| 1756 |
* |
| 1757 |
* @return bool |
| 1758 |
*/ |
| 1759 |
function learn_press_is_profile() { |
| 1760 |
$page_id = learn_press_get_page_id( 'profile' ); |
| 1761 |
|
| 1762 |
if ( $page_id && is_page( $page_id ) || lp_content_has_shortcode( 'learn_press_profile' ) ) { |
| 1763 |
return true; |
| 1764 |
} |
| 1765 |
|
| 1766 |
return apply_filters( 'learn-press/is-profile', false ); |
| 1767 |
} |
| 1768 |
|
| 1769 |
/** |
| 1770 |
* Return true if user is in checking out page |
| 1771 |
* |
| 1772 |
* @return bool |
| 1773 |
*/ |
| 1774 |
function learn_press_is_checkout() { |
| 1775 |
$page_id = learn_press_get_page_id( 'checkout' ); |
| 1776 |
|
| 1777 |
if ( $page_id && is_page( $page_id ) ) { |
| 1778 |
return true; |
| 1779 |
} |
| 1780 |
|
| 1781 |
return apply_filters( 'learn-press/is-checkout', false ); |
| 1782 |
} |
| 1783 |
|
| 1784 |
/** |
| 1785 |
* Return register permalink |
| 1786 |
* |
| 1787 |
* @return mixed |
| 1788 |
*/ |
| 1789 |
function learn_press_get_register_url() { |
| 1790 |
return apply_filters( 'learn_press_register_url', wp_registration_url() ); |
| 1791 |
} |
| 1792 |
|
| 1793 |
/** |
| 1794 |
* Add a new notice into queue |
| 1795 |
* |
| 1796 |
* @param string |
| 1797 |
* @param string |
| 1798 |
* |
| 1799 |
* @return mixed |
| 1800 |
*/ |
| 1801 |
function learn_press_add_notice( $message, $type = 'updated' ) { |
| 1802 |
LP_Admin_Notice::instance()->add( $message, $type ); |
| 1803 |
} |
| 1804 |
|
| 1805 |
/** |
| 1806 |
* Set user's cookie |
| 1807 |
* |
| 1808 |
* @param string $name |
| 1809 |
* @param mixed $value |
| 1810 |
* @param int $expire |
| 1811 |
* @param bool $httponly |
| 1812 |
* |
| 1813 |
* @editor tungnx |
| 1814 |
* @version 1.0.3 |
| 1815 |
*/ |
| 1816 |
function learn_press_setcookie( string $name = '', string $value = '', int $expire = 0, bool $httponly = true ) { |
| 1817 |
$secure = ( 'https' === parse_url( wp_login_url(), PHP_URL_SCHEME ) ); |
| 1818 |
|
| 1819 |
@setcookie( $name, $value, $expire, COOKIEPATH ?: '/', COOKIE_DOMAIN, $secure, $httponly ); |
| 1820 |
} |
| 1821 |
|
| 1822 |
/** |
| 1823 |
* Clear cookie |
| 1824 |
* |
| 1825 |
* @param string $name |
| 1826 |
*/ |
| 1827 |
function learn_press_remove_cookie( string $name = '' ) { |
| 1828 |
if ( ! empty( $name ) ) { |
| 1829 |
setcookie( $name, '', time() - YEAR_IN_SECONDS, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN ); |
| 1830 |
} |
| 1831 |
|
| 1832 |
if ( array_key_exists( $name, $_COOKIE ) ) { |
| 1833 |
unset( $_COOKIE[ $name ] ); |
| 1834 |
} |
| 1835 |
} |
| 1836 |
|
| 1837 |
/** |
| 1838 |
* Filter the login url so third-party can be customized |
| 1839 |
* |
| 1840 |
* @param string $redirect |
| 1841 |
* |
| 1842 |
* @return mixed |
| 1843 |
*/ |
| 1844 |
function learn_press_get_login_url( $redirect = null ) { |
| 1845 |
$url = wp_login_url( $redirect ); |
| 1846 |
$profile_page = learn_press_get_page_link( 'profile' ); |
| 1847 |
|
| 1848 |
if ( 'yes' === LP_Settings::instance()->get( 'enable_login_profile' ) && $profile_page ) { |
| 1849 |
$parse_url = parse_url( $url ); |
| 1850 |
$url = $profile_page . ( ! empty( $parse_url['query'] ) ? '?' . $parse_url['query'] : '' ); |
| 1851 |
} |
| 1852 |
|
| 1853 |
return apply_filters( 'learn-press/login-url', $url ); |
| 1854 |
} |
| 1855 |
|
| 1856 |
/** |
| 1857 |
* Add variable to an url by checking the permalink structure. |
| 1858 |
* |
| 1859 |
* @param string $name |
| 1860 |
* @param string $value |
| 1861 |
* @param string $url |
| 1862 |
* |
| 1863 |
* @return string |
| 1864 |
*/ |
| 1865 |
function learn_press_get_endpoint_url( $name, $value, $url ) { |
| 1866 |
if ( ! $url ) { |
| 1867 |
$url = get_permalink(); |
| 1868 |
} |
| 1869 |
|
| 1870 |
// Map endpoint to options |
| 1871 |
$name = isset( LearnPress::instance()->query_vars[ $name ] ) ? LearnPress::instance()->query_vars[ $name ] : $name; |
| 1872 |
|
| 1873 |
if ( get_option( 'permalink_structure' ) ) { |
| 1874 |
if ( strstr( $url, '?' ) ) { |
| 1875 |
$query_string = '?' . parse_url( $url, PHP_URL_QUERY ); |
| 1876 |
$url = current( explode( '?', $url ) ); |
| 1877 |
} else { |
| 1878 |
$query_string = ''; |
| 1879 |
} |
| 1880 |
$url = trailingslashit( $url ) . ( $name ? $name . '/' : '' ) . $value . $query_string; |
| 1881 |
|
| 1882 |
} else { |
| 1883 |
$url = esc_url_raw( add_query_arg( $name, $value, $url ) ); |
| 1884 |
} |
| 1885 |
|
| 1886 |
return apply_filters( 'learn_press_get_endpoint_url', esc_url_raw( $url ), $name, $value, $url ); |
| 1887 |
} |
| 1888 |
|
| 1889 |
/** |
| 1890 |
* Add all endpoints from settings to the pages. |
| 1891 |
*/ |
| 1892 |
function learn_press_add_endpoints() { |
| 1893 |
$settings = LP_Settings::instance(); |
| 1894 |
|
| 1895 |
$endpoints = $settings->get_checkout_endpoints(); |
| 1896 |
if ( $endpoints ) { |
| 1897 |
foreach ( $endpoints as $endpoint => $value ) { |
| 1898 |
LearnPress::instance()->query_vars[ $endpoint ] = $value; |
| 1899 |
add_rewrite_endpoint( $value, EP_PAGES ); |
| 1900 |
} |
| 1901 |
} |
| 1902 |
|
| 1903 |
$endpoints = $settings->get_profile_endpoints(); |
| 1904 |
if ( $endpoints ) { |
| 1905 |
foreach ( $endpoints as $endpoint => $value ) { |
| 1906 |
LearnPress::instance()->query_vars[ $endpoint ] = $value; |
| 1907 |
add_rewrite_endpoint( $value, EP_PAGES ); |
| 1908 |
} |
| 1909 |
} |
| 1910 |
|
| 1911 |
$endpoints = $settings->get( 'quiz_endpoints' ); |
| 1912 |
if ( $endpoints ) { |
| 1913 |
foreach ( $endpoints as $endpoint => $value ) { |
| 1914 |
$endpoint = preg_replace( '!_!', '-', $endpoint ); |
| 1915 |
LearnPress::instance()->query_vars[ $endpoint ] = $value; |
| 1916 |
add_rewrite_endpoint( |
| 1917 |
$value, /*EP_ROOT | */ |
| 1918 |
EP_PAGES |
| 1919 |
); |
| 1920 |
} |
| 1921 |
} |
| 1922 |
} |
| 1923 |
|
| 1924 |
add_action( 'init', 'learn_press_add_endpoints' ); |
| 1925 |
|
| 1926 |
function learn_press_is_yes( $value ) { |
| 1927 |
return ( $value === 1 ) || ( $value === '1' ) || ( $value == 'yes' ) || ( $value == true ) || ( $value == 'on' ); |
| 1928 |
} |
| 1929 |
|
| 1930 |
/** |
| 1931 |
* @param mixed $value |
| 1932 |
* |
| 1933 |
* @return bool |
| 1934 |
*/ |
| 1935 |
function _is_false_value( $value ) { |
| 1936 |
if ( is_numeric( $value ) ) { |
| 1937 |
return $value == 0; |
| 1938 |
} elseif ( is_string( $value ) ) { |
| 1939 |
return ( empty( $value ) || is_null( $value ) || in_array( $value, array( 'no', 'off', 'false' ) ) ); |
| 1940 |
} |
| 1941 |
|
| 1942 |
return ! ! $value; |
| 1943 |
} |
| 1944 |
|
| 1945 |
/** |
| 1946 |
* Map the query vars from LP to query vars of WP core |
| 1947 |
* when WP parse the requesting. |
| 1948 |
*/ |
| 1949 |
function learn_press_parse_request() { |
| 1950 |
global $wp; |
| 1951 |
|
| 1952 |
// Map query vars to their keys, or get them if endpoints are not supported |
| 1953 |
foreach ( LearnPress::instance()->query_vars as $key => $var ) { |
| 1954 |
if ( isset( $_GET[ $var ] ) ) { |
| 1955 |
$wp->query_vars[ $key ] = LP_Helper::sanitize_params_submitted( $_GET[ $var ] ?? '' ); |
| 1956 |
} elseif ( isset( $wp->query_vars[ $var ] ) ) { |
| 1957 |
$wp->query_vars[ $key ] = LP_Helper::sanitize_params_submitted( $wp->query_vars[ $var ] ?? '' ); |
| 1958 |
} |
| 1959 |
} |
| 1960 |
} |
| 1961 |
|
| 1962 |
add_action( 'parse_request', 'learn_press_parse_request' ); |
| 1963 |
|
| 1964 |
if ( ! function_exists( 'learn_press_reset_auto_increment' ) ) { |
| 1965 |
/** |
| 1966 |
* Reset AUTO INCREMENT of the table. |
| 1967 |
* |
| 1968 |
* @param $table |
| 1969 |
*/ |
| 1970 |
function learn_press_reset_auto_increment( $table ) { |
| 1971 |
global $wpdb; |
| 1972 |
$wpdb->query( $wpdb->prepare( "ALTER TABLE {$wpdb->prefix}$table AUTO_INCREMENT = %d", 1 ) ); |
| 1973 |
} |
| 1974 |
} |
| 1975 |
|
| 1976 |
/** |
| 1977 |
* @param string $handle |
| 1978 |
* @param bool $hash |
| 1979 |
* |
| 1980 |
* @return string |
| 1981 |
* @deprecated 4.1.7.2 |
| 1982 |
*/ |
| 1983 |
/*function learn_press_get_log_file_path( $handle, $hash = false ) { |
| 1984 |
if ( $hash ) { |
| 1985 |
$hash = '-' . sanitize_file_name( wp_hash( $handle ) ); |
| 1986 |
} |
| 1987 |
|
| 1988 |
return trailingslashit( LP_LOG_PATH ) . $handle . $hash . '.log'; |
| 1989 |
}*/ |
| 1990 |
|
| 1991 |
/** |
| 1992 |
* Get the cart object in checkout page |
| 1993 |
* |
| 1994 |
* @return LP_Cart |
| 1995 |
* @deprecated 4.2.0 |
| 1996 |
*/ |
| 1997 |
function learn_press_get_checkout_cart() { |
| 1998 |
_deprecated_function( __FUNCTION__, '4.2.0', 'LearnPress::instance()->cart' ); |
| 1999 |
return apply_filters( 'learn_press_checkout_cart', LearnPress::instance()->cart ); |
| 2000 |
} |
| 2001 |
|
| 2002 |
/*function learn_press_front_scripts() { |
| 2003 |
if ( is_admin() ) { |
| 2004 |
return; |
| 2005 |
} |
| 2006 |
$js = array( |
| 2007 |
'ajax' => admin_url( 'admin-ajax.php' ), |
| 2008 |
'plugin_url' => LearnPress::instance()->plugin_url(), |
| 2009 |
'siteurl' => home_url(), |
| 2010 |
'current_url' => learn_press_get_current_url(), |
| 2011 |
'localize' => array( |
| 2012 |
'button_ok' => __( 'OK', 'learnpress' ), |
| 2013 |
'button_cancel' => __( 'Cancel', 'learnpress' ), |
| 2014 |
'button_yes' => __( 'Yes', 'learnpress' ), |
| 2015 |
'button_no' => __( 'No', 'learnpress' ), |
| 2016 |
), |
| 2017 |
); |
| 2018 |
foreach ( $js as $k => $v ) { |
| 2019 |
LP_Assets::add_param( $k, $v, array( 'learn-press-single-course', 'learn-press-global' ), 'LP_Settings' ); |
| 2020 |
} |
| 2021 |
} |
| 2022 |
|
| 2023 |
add_action( 'wp_print_scripts', 'learn_press_front_scripts' );*/ |
| 2024 |
|
| 2025 |
function learn_press_user_time( $time, $format = 'timestamp' ) { |
| 2026 |
if ( is_string( $time ) ) { |
| 2027 |
$time = @strtotime( $time ); |
| 2028 |
} |
| 2029 |
$time = $time + ( get_option( 'gmt_offset' ) - $_COOKIE['timezone'] / 60 ) * HOUR_IN_SECONDS; |
| 2030 |
switch ( $format ) { |
| 2031 |
case 'timestamp': |
| 2032 |
return $time; |
| 2033 |
default: |
| 2034 |
return date( 'Y-m-d H:i:s', $time ); |
| 2035 |
} |
| 2036 |
} |
| 2037 |
|
| 2038 |
function learn_press_get_current_version() { |
| 2039 |
$data = get_plugin_data( LP_PLUGIN_FILE, $markup = true, $translate = true ); |
| 2040 |
|
| 2041 |
return $data['Version']; |
| 2042 |
} |
| 2043 |
|
| 2044 |
/** |
| 2045 |
* Get current tab is displaying in user profile. |
| 2046 |
* If there is no tab then get the first tab in |
| 2047 |
* the list of tabs. |
| 2048 |
* |
| 2049 |
* @param bool $default |
| 2050 |
* |
| 2051 |
* @return mixed|string |
| 2052 |
*/ |
| 2053 |
function learn_press_get_current_profile_tab( $default = true ) { |
| 2054 |
global $wp_query, $wp; |
| 2055 |
$current = ''; |
| 2056 |
|
| 2057 |
// Only load on profile page. |
| 2058 |
$page_profile_option = untrailingslashit( get_the_permalink( learn_press_get_page_id( 'profile' ) ) ); |
| 2059 |
$page_profile_option = str_replace( '/', '\/', $page_profile_option ); |
| 2060 |
$pattern = '/' . $page_profile_option . '/'; |
| 2061 |
if ( ! preg_match( $pattern, LP_Helper::getUrlCurrent() ) ) { |
| 2062 |
return false; |
| 2063 |
} |
| 2064 |
|
| 2065 |
if ( ! empty( $_REQUEST['tab'] ) ) { |
| 2066 |
$current = LP_Helper::sanitize_params_submitted( $_REQUEST['tab'] ); |
| 2067 |
} elseif ( ! empty( $wp_query->query_vars['tab'] ) ) { |
| 2068 |
$current = $wp_query->query_vars['tab']; |
| 2069 |
} elseif ( ! empty( $wp->query_vars['view'] ) ) { |
| 2070 |
$current = $wp->query_vars['view']; |
| 2071 |
} else { |
| 2072 |
$tabs = learn_press_get_user_profile_tabs(); |
| 2073 |
if ( $default && $tabs ) { |
| 2074 |
// Fixed for array_keys does not work with ArrayAccess instance |
| 2075 |
if ( $tabs instanceof LP_Profile_Tabs ) { |
| 2076 |
$tabs = $tabs->tabs(); |
| 2077 |
} |
| 2078 |
|
| 2079 |
$tab_keys = array_keys( $tabs ); |
| 2080 |
$current = reset( $tab_keys ); |
| 2081 |
} |
| 2082 |
} |
| 2083 |
|
| 2084 |
return $current; |
| 2085 |
} |
| 2086 |
|
| 2087 |
add_action( 'init', 'learn_press_get_current_profile_tab' ); |
| 2088 |
|
| 2089 |
function learn_press_profile_tab_exists( $tab ) { |
| 2090 |
$tabs = learn_press_get_user_profile_tabs(); |
| 2091 |
|
| 2092 |
if ( $tabs ) { |
| 2093 |
return ! empty( $tabs[ $tab ] ) ? true : false; |
| 2094 |
} |
| 2095 |
|
| 2096 |
return false; |
| 2097 |
} |
| 2098 |
|
| 2099 |
/** |
| 2100 |
* Replace the spacing with the + (plus) char. |
| 2101 |
* |
| 2102 |
* @param string $string |
| 2103 |
* |
| 2104 |
* @return string |
| 2105 |
* @deprecated 4.1.7.2 |
| 2106 |
*/ |
| 2107 |
/*function _learn_press_urlencode( $string ) { |
| 2108 |
return preg_replace( '/\s/', '+', $string ); |
| 2109 |
}*/ |
| 2110 |
|
| 2111 |
/** |
| 2112 |
* Point the archive post type link to course page if current |
| 2113 |
* post type is course and the page for displaying course is |
| 2114 |
* setup. |
| 2115 |
* |
| 2116 |
* @param string $link |
| 2117 |
* @param string $post_type |
| 2118 |
* |
| 2119 |
* @return string |
| 2120 |
* @deprecated 4.1.7.2 |
| 2121 |
*/ |
| 2122 |
/*function learn_press_post_type_archive_link( $link, $post_type ) { |
| 2123 |
if ( $post_type == LP_COURSE_CPT && learn_press_get_page_id( 'courses' ) ) { |
| 2124 |
$link = learn_press_get_page_link( 'courses' ); |
| 2125 |
} |
| 2126 |
|
| 2127 |
return $link; |
| 2128 |
}*/ |
| 2129 |
//add_filter( 'post_type_archive_link', 'learn_press_post_type_archive_link', 10, 2 ); |
| 2130 |
|
| 2131 |
function learn_press_single_term_title( $prefix = '', $display = true ) { |
| 2132 |
$term = get_queried_object(); |
| 2133 |
|
| 2134 |
if ( ! $term ) { |
| 2135 |
return ''; |
| 2136 |
} |
| 2137 |
|
| 2138 |
if ( learn_press_is_course_category() ) { |
| 2139 |
$term_name = apply_filters( 'single_course_category_title', $term->name ); |
| 2140 |
} elseif ( learn_press_is_course_tag() ) { |
| 2141 |
$term_name = apply_filters( 'single_course_tag_title', $term->name ); |
| 2142 |
} elseif ( learn_press_is_course_taxonomy() ) { |
| 2143 |
$term_name = apply_filters( 'single_course_term_title', $term->name ); |
| 2144 |
} else { |
| 2145 |
return single_term_title( $prefix, $display ); |
| 2146 |
} |
| 2147 |
|
| 2148 |
if ( empty( $term_name ) ) { |
| 2149 |
return single_term_title( $prefix, $display ); |
| 2150 |
} |
| 2151 |
|
| 2152 |
if ( $display ) { |
| 2153 |
echo wp_kses_post( $prefix . $term_name ); |
| 2154 |
} |
| 2155 |
|
| 2156 |
return $prefix . $term_name; |
| 2157 |
} |
| 2158 |
|
| 2159 |
/** |
| 2160 |
* Control the template file if user is searching course. |
| 2161 |
* Use the template of archive course to display the |
| 2162 |
* result if there is a flag in request to search course. |
| 2163 |
* |
| 2164 |
* @param string $template |
| 2165 |
* |
| 2166 |
* @return string |
| 2167 |
*/ |
| 2168 |
function learn_press_search_template( $template ) { |
| 2169 |
if ( ! empty( $_REQUEST['ref'] ) && sanitize_text_field( $_REQUEST['ref'] ) == 'course' ) { |
| 2170 |
$template = learn_press_locate_template( 'archive-course.php' ); |
| 2171 |
} |
| 2172 |
|
| 2173 |
return $template; |
| 2174 |
} |
| 2175 |
|
| 2176 |
/** |
| 2177 |
* Auto enroll user to a course after an order is completed |
| 2178 |
* if the option auto-enroll is turn on. |
| 2179 |
* |
| 2180 |
* @param int $order_id |
| 2181 |
* |
| 2182 |
* @return mixed |
| 2183 |
* @editor tungnx |
| 2184 |
*/ |
| 2185 |
function learn_press_auto_enroll_user_to_courses( $order_id ) { |
| 2186 |
_deprecated_function( __FUNCTION__, '4.1.3' ); |
| 2187 |
} |
| 2188 |
|
| 2189 |
// add_action( 'learn_press_order_status_completed', 'learn_press_auto_enroll_user_to_courses' ); |
| 2190 |
|
| 2191 |
/** |
| 2192 |
* Return true if enable cart |
| 2193 |
* |
| 2194 |
* @return bool |
| 2195 |
*/ |
| 2196 |
function learn_press_is_enable_cart() { |
| 2197 |
return defined( 'LP_ENABLE_CART' ) && LP_ENABLE_CART == true; |
| 2198 |
} |
| 2199 |
|
| 2200 |
/** |
| 2201 |
* Short way to get checkout object |
| 2202 |
* |
| 2203 |
* @param array |
| 2204 |
* |
| 2205 |
* @return LP_Checkout |
| 2206 |
*/ |
| 2207 |
function learn_press_get_checkout( $args = null ) { |
| 2208 |
$checkout = LP_Checkout::instance(); |
| 2209 |
|
| 2210 |
if ( is_array( $args ) ) { |
| 2211 |
foreach ( $args as $k => $v ) { |
| 2212 |
$checkout->{$k} = $v; |
| 2213 |
} |
| 2214 |
} |
| 2215 |
|
| 2216 |
return $checkout; |
| 2217 |
} |
| 2218 |
|
| 2219 |
if ( defined( 'LP_ENABLE_CART' ) && LP_ENABLE_CART ) { |
| 2220 |
add_filter( 'learn_press_checkout_settings', '_learn_press_cart_settings', 10, 2 ); |
| 2221 |
function _learn_press_cart_settings( $settings, $class ) { |
| 2222 |
$settings = array_merge( |
| 2223 |
$settings, |
| 2224 |
array( |
| 2225 |
array( |
| 2226 |
'title' => __( 'Cart', 'learnpress' ), |
| 2227 |
'type' => 'title', |
| 2228 |
), |
| 2229 |
array( |
| 2230 |
'title' => __( 'Enable cart', 'learnpress' ), |
| 2231 |
'desc' => __( |
| 2232 |
'Check this option to enable users to purchase multiple courses at one time.', |
| 2233 |
'learnpress' |
| 2234 |
), |
| 2235 |
'id' => $class->get_field_name( 'enable_cart' ), |
| 2236 |
'default' => 'yes', |
| 2237 |
'type' => 'checkbox', |
| 2238 |
), |
| 2239 |
array( |
| 2240 |
'title' => __( 'Add to cart redirect', 'learnpress' ), |
| 2241 |
'desc' => __( 'Redirect to checkout immediately after adding the course to the cart.', 'learnpress' ), |
| 2242 |
'id' => $class->get_field_name( 'redirect_after_add' ), |
| 2243 |
'default' => 'yes', |
| 2244 |
'type' => 'checkbox', |
| 2245 |
), |
| 2246 |
array( |
| 2247 |
'title' => __( 'AJAX add to cart', 'learnpress' ), |
| 2248 |
'desc' => __( 'Using AJAX to add the course to the cart.', 'learnpress' ), |
| 2249 |
'id' => $class->get_field_name( 'ajax_add_to_cart' ), |
| 2250 |
'default' => 'no', |
| 2251 |
'type' => 'checkbox', |
| 2252 |
), |
| 2253 |
array( |
| 2254 |
'title' => __( 'Cart page', 'learnpress' ), |
| 2255 |
'id' => $class->get_field_name( 'cart_page_id' ), |
| 2256 |
'default' => '', |
| 2257 |
'type' => 'pages-dropdown', |
| 2258 |
), |
| 2259 |
) |
| 2260 |
); |
| 2261 |
|
| 2262 |
return $settings; |
| 2263 |
} |
| 2264 |
} else { |
| 2265 |
add_filter( 'learn_press_enable_cart', '_learn_press_enable_cart', 1000 ); |
| 2266 |
function _learn_press_enable_cart( $r ) { |
| 2267 |
return false; |
| 2268 |
} |
| 2269 |
|
| 2270 |
add_filter( 'learn_press_get_template', '_learn_press_enroll_button', 1000, 5 ); |
| 2271 |
function _learn_press_enroll_button( $located, $template_name, $args, $template_path, $default_path ) { |
| 2272 |
if ( $template_name == 'single-course/enroll-button.php' ) { |
| 2273 |
$located = learn_press_locate_template( |
| 2274 |
'single-course/enroll-button-new.php', |
| 2275 |
$template_path, |
| 2276 |
$default_path |
| 2277 |
); |
| 2278 |
} |
| 2279 |
|
| 2280 |
return $located; |
| 2281 |
} |
| 2282 |
} |
| 2283 |
|
| 2284 |
/** |
| 2285 |
* Returns checkout url from setting |
| 2286 |
* |
| 2287 |
* @return string |
| 2288 |
*/ |
| 2289 |
function learn_press_get_checkout_url() { |
| 2290 |
$checkout_url = learn_press_get_page_link( 'checkout' ); |
| 2291 |
|
| 2292 |
return apply_filters( 'learn_press_get_checkout_url', $checkout_url ); |
| 2293 |
} |
| 2294 |
|
| 2295 |
/** |
| 2296 |
* @return string |
| 2297 |
*/ |
| 2298 |
function learn_press_checkout_needs_payment() { |
| 2299 |
return LearnPress::instance()->cart->needs_payment(); |
| 2300 |
} |
| 2301 |
|
| 2302 |
/** |
| 2303 |
* Return plugin basename |
| 2304 |
* |
| 2305 |
* @param string $filepath |
| 2306 |
* |
| 2307 |
* @return string |
| 2308 |
*/ |
| 2309 |
/* |
| 2310 |
function learn_press_plugin_basename( $filepath ) { |
| 2311 |
$file = str_replace( '\\', '/', $filepath ); |
| 2312 |
$file = preg_replace( '|/+|', '/', $file ); |
| 2313 |
$plugin_dir = str_replace( '\\', '/', WP_PLUGIN_DIR ); |
| 2314 |
$plugin_dir = preg_replace( '|/+|', '/', $plugin_dir ); |
| 2315 |
$mu_plugin_dir = str_replace( '\\', '/', WPMU_PLUGIN_DIR ); |
| 2316 |
$mu_plugin_dir = preg_replace( '|/+|', '/', $mu_plugin_dir ); |
| 2317 |
$sp_plugin_dir = dirname( $filepath ); |
| 2318 |
$sp_plugin_dir = dirname( $sp_plugin_dir ); |
| 2319 |
$sp_plugin_dir = str_replace( '\\', '/', $sp_plugin_dir ); |
| 2320 |
$sp_plugin_dir = preg_replace( '|/+|', '/', $sp_plugin_dir ); |
| 2321 |
|
| 2322 |
$file = preg_replace( |
| 2323 |
'#^' . preg_quote( $sp_plugin_dir, '#' ) . '/|^' . preg_quote( |
| 2324 |
$plugin_dir, |
| 2325 |
'#' |
| 2326 |
) . '/|^' . preg_quote( |
| 2327 |
$mu_plugin_dir, |
| 2328 |
'#' |
| 2329 |
) . '/#', |
| 2330 |
'', |
| 2331 |
$file |
| 2332 |
); |
| 2333 |
$file = trim( $file, '/' ); |
| 2334 |
|
| 2335 |
return strtolower( $file ); |
| 2336 |
}*/ |
| 2337 |
|
| 2338 |
/** |
| 2339 |
* Update log data for each LP version into wp option. |
| 2340 |
* |
| 2341 |
* @param string $version |
| 2342 |
* @param mixed $data |
| 2343 |
*/ |
| 2344 |
function learn_press_update_log( $version, $data ) { |
| 2345 |
$logs = get_option( 'learn_press_update_logs' ); |
| 2346 |
if ( ! $logs ) { |
| 2347 |
$logs = array( $version => $data ); |
| 2348 |
} else { |
| 2349 |
$logs[ $version ] = $data; |
| 2350 |
} |
| 2351 |
update_option( 'learn_press_update_logs', $logs ); |
| 2352 |
} |
| 2353 |
|
| 2354 |
/** |
| 2355 |
* Output variables to screen for debugging. |
| 2356 |
*/ |
| 2357 |
function learn_press_debug() { |
| 2358 |
$args = func_get_args(); |
| 2359 |
$debug = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); |
| 2360 |
|
| 2361 |
echo '<pre>'; |
| 2362 |
print_r( $debug ); |
| 2363 |
$arg = false; |
| 2364 |
|
| 2365 |
if ( $args ) { |
| 2366 |
foreach ( $args as $arg ) { |
| 2367 |
echo "\n======LearnPress Debug=======\n"; |
| 2368 |
print_r( $arg ); |
| 2369 |
echo "\n=============================\n"; |
| 2370 |
} |
| 2371 |
} |
| 2372 |
echo '</pre>'; |
| 2373 |
|
| 2374 |
if ( true === $arg ) { |
| 2375 |
die( __FUNCTION__ ); |
| 2376 |
} |
| 2377 |
} |
| 2378 |
|
| 2379 |
/** |
| 2380 |
* Get current time to user for calculate remaining time of quiz. |
| 2381 |
* |
| 2382 |
* @return int |
| 2383 |
* @deprecated 4.1.7.2 |
| 2384 |
*/ |
| 2385 |
/*function learn_press_get_current_time() { |
| 2386 |
$current_time = apply_filters( 'learn_press_get_current_time', 0 ); |
| 2387 |
|
| 2388 |
if ( $current_time > 0 ) { |
| 2389 |
return $current_time; |
| 2390 |
} |
| 2391 |
|
| 2392 |
$a = current_time( 'timestamp' ); |
| 2393 |
$b = time(); |
| 2394 |
$c = current_time( 'mysql' ); |
| 2395 |
$d = strtotime( $c ); |
| 2396 |
|
| 2397 |
if ( $d == $a ) { |
| 2398 |
return $a; |
| 2399 |
} else { |
| 2400 |
return $b; |
| 2401 |
} |
| 2402 |
}*/ |
| 2403 |
|
| 2404 |
function learn_press_get_requested_post_type() { |
| 2405 |
global $pagenow; |
| 2406 |
if ( $pagenow == 'post-new.php' && ! empty( $_REQUEST['post_type'] ) ) { |
| 2407 |
$post_type = LP_Helper::sanitize_params_submitted( $_REQUEST['post_type'] ); |
| 2408 |
} else { |
| 2409 |
$post_id = learn_press_get_post(); |
| 2410 |
$post_type = learn_press_get_post_type( $post_id ); |
| 2411 |
} |
| 2412 |
|
| 2413 |
return $post_type; |
| 2414 |
} |
| 2415 |
|
| 2416 |
/** |
| 2417 |
* Get human string from grade slug. |
| 2418 |
* |
| 2419 |
* @param string $slug |
| 2420 |
* |
| 2421 |
* @return string |
| 2422 |
*/ |
| 2423 |
function learn_press_get_graduation_text( $slug ) { |
| 2424 |
switch ( $slug ) { |
| 2425 |
case 'passed': |
| 2426 |
$text = esc_html__( 'Passed', 'learnpress' ); |
| 2427 |
break; |
| 2428 |
case 'failed': |
| 2429 |
$text = esc_html__( 'Failed', 'learnpress' ); |
| 2430 |
break; |
| 2431 |
case 'in-progress': |
| 2432 |
$text = esc_html__( 'In Progress', 'learnpress' ); |
| 2433 |
break; |
| 2434 |
default: |
| 2435 |
$text = $slug; |
| 2436 |
} |
| 2437 |
|
| 2438 |
return apply_filters( 'learn-press/get-graduation-text', $text, $slug ); |
| 2439 |
} |
| 2440 |
|
| 2441 |
if ( ! function_exists( 'learn_press_is_negative_value' ) ) { |
| 2442 |
function learn_press_is_negative_value( $value ) { |
| 2443 |
$return = in_array( $value, array( 'no', 'off', 'false', '0' ) ) || ! $value || $value == '' || $value == null; |
| 2444 |
|
| 2445 |
return $return; |
| 2446 |
} |
| 2447 |
} |
| 2448 |
|
| 2449 |
/** |
| 2450 |
* Filter to comment reply link to fix bug the link is invalid for |
| 2451 |
* lesson or quiz. |
| 2452 |
* |
| 2453 |
* @param string $link |
| 2454 |
* @param array $args |
| 2455 |
* @param WP_Comment $comment |
| 2456 |
* @param WP_Post $post |
| 2457 |
* |
| 2458 |
* @return string |
| 2459 |
*/ |
| 2460 |
function learn_press_comment_reply_link( $link, $args = array(), $comment = null, $post = null ) { |
| 2461 |
|
| 2462 |
$post_type = learn_press_get_post_type( $post ); |
| 2463 |
|
| 2464 |
if ( ! learn_press_is_support_course_item_type( $post_type ) ) { |
| 2465 |
return $link; |
| 2466 |
} |
| 2467 |
|
| 2468 |
$course_item = LP_Global::course_item(); |
| 2469 |
|
| 2470 |
if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) { |
| 2471 |
$link = sprintf( |
| 2472 |
'<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>', |
| 2473 |
esc_url_raw( wp_login_url( get_permalink() ) ), |
| 2474 |
$args['login_text'] |
| 2475 |
); |
| 2476 |
} elseif ( $course_item ) { |
| 2477 |
$onclick = sprintf( |
| 2478 |
'return addComment.moveForm( "%1$s-%2$s", "%2$s", "%3$s", "%4$s" )', |
| 2479 |
$args['add_below'], |
| 2480 |
$comment->comment_ID, |
| 2481 |
$args['respond_id'], |
| 2482 |
$post->ID |
| 2483 |
); |
| 2484 |
|
| 2485 |
$link = sprintf( |
| 2486 |
"<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s' aria-label='%s'>%s</a>", |
| 2487 |
esc_url_raw( |
| 2488 |
add_query_arg( |
| 2489 |
array( |
| 2490 |
'replytocom' => $comment->comment_ID, |
| 2491 |
), |
| 2492 |
$course_item->get_permalink() |
| 2493 |
) |
| 2494 |
) . '#' . $args['respond_id'], |
| 2495 |
$onclick, |
| 2496 |
esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ), |
| 2497 |
$args['reply_text'] |
| 2498 |
); |
| 2499 |
} |
| 2500 |
|
| 2501 |
return $link; |
| 2502 |
} |
| 2503 |
|
| 2504 |
add_filter( 'comment_reply_link', 'learn_press_comment_reply_link', 10, 4 ); |
| 2505 |
|
| 2506 |
/** |
| 2507 |
* Sanitize content of tooltip |
| 2508 |
* |
| 2509 |
* @param string $tooltip |
| 2510 |
* @param bool $html |
| 2511 |
* |
| 2512 |
* @return string |
| 2513 |
*/ |
| 2514 |
function learn_press_sanitize_tooltip( $tooltip, $html = false ) { |
| 2515 |
if ( $html ) { |
| 2516 |
$tooltip = htmlspecialchars( |
| 2517 |
wp_kses( |
| 2518 |
html_entity_decode( $tooltip ), |
| 2519 |
array( |
| 2520 |
'br' => array(), |
| 2521 |
'em' => array(), |
| 2522 |
'strong' => array(), |
| 2523 |
'small' => array(), |
| 2524 |
'span' => array(), |
| 2525 |
'ul' => array(), |
| 2526 |
'li' => array(), |
| 2527 |
'ol' => array(), |
| 2528 |
'p' => array(), |
| 2529 |
) |
| 2530 |
) |
| 2531 |
); |
| 2532 |
} else { |
| 2533 |
$tooltip = esc_attr( $tooltip ); |
| 2534 |
} |
| 2535 |
|
| 2536 |
return $tooltip; |
| 2537 |
} |
| 2538 |
|
| 2539 |
function learn_press_tooltip( $tooltip, $html = false ) { |
| 2540 |
$tooltip = learn_press_sanitize_tooltip( $tooltip, $html ); |
| 2541 |
echo '<span class="learn-press-tooltip" data-tooltip="' . esc_attr( $tooltip ) . '"></span>'; |
| 2542 |
} |
| 2543 |
|
| 2544 |
/** |
| 2545 |
* Get timezone offset from wp settings. |
| 2546 |
* |
| 2547 |
* @return float|int |
| 2548 |
* @since 3.0.0 |
| 2549 |
* @deprecated 4.1.7.2 |
| 2550 |
*/ |
| 2551 |
/*function learn_press_timezone_offset() { |
| 2552 |
if ( $tz = get_option( 'timezone_string' ) ) { |
| 2553 |
$timezone = new DateTimeZone( $tz ); |
| 2554 |
|
| 2555 |
return $timezone->getOffset( new DateTime( 'now' ) ); |
| 2556 |
} else { |
| 2557 |
return floatval( get_option( 'gmt_offset', 0 ) ) * HOUR_IN_SECONDS; |
| 2558 |
} |
| 2559 |
}*/ |
| 2560 |
|
| 2561 |
/** |
| 2562 |
* Get default static pages of LP. |
| 2563 |
* |
| 2564 |
* @return array |
| 2565 |
* |
| 2566 |
* @since 3.0.0 |
| 2567 |
*/ |
| 2568 |
function learn_press_static_page_ids() { |
| 2569 |
$pages = LP_Object_Cache::get( 'static-page-ids', 'learn-press' ); |
| 2570 |
|
| 2571 |
if ( false === $pages ) { |
| 2572 |
$pages = array( |
| 2573 |
'checkout' => learn_press_get_page_id( 'checkout' ), |
| 2574 |
'courses' => learn_press_get_page_id( 'courses' ), |
| 2575 |
'profile' => learn_press_get_page_id( 'profile' ), |
| 2576 |
'become_a_teacher' => learn_press_get_page_id( 'become_a_teacher' ), |
| 2577 |
); |
| 2578 |
|
| 2579 |
foreach ( $pages as $name => $id ) { |
| 2580 |
if ( ! get_post( $id ) ) { |
| 2581 |
$pages[ $name ] = 0; |
| 2582 |
} |
| 2583 |
} |
| 2584 |
|
| 2585 |
LP_Object_Cache::set( 'static-page-ids', $pages, 'learn-press' ); |
| 2586 |
} |
| 2587 |
|
| 2588 |
return apply_filters( 'learn-press/static-page-ids', $pages ); |
| 2589 |
} |
| 2590 |
|
| 2591 |
/** |
| 2592 |
* Get default static pages of LP. |
| 2593 |
* |
| 2594 |
* @param bool $name - Optional. TRUE will return name only. |
| 2595 |
* |
| 2596 |
* @return array |
| 2597 |
* |
| 2598 |
* @since 3.0.0 |
| 2599 |
*/ |
| 2600 |
function learn_press_static_pages( $name = false ) { |
| 2601 |
$pages = apply_filters( |
| 2602 |
'learn-press/static-pages', |
| 2603 |
array( |
| 2604 |
'checkout' => _x( 'Checkout', 'static-page-name', 'learnpress' ), |
| 2605 |
'courses' => _x( 'Courses', 'static-page-name', 'learnpress' ), |
| 2606 |
'profile' => _x( 'Profile', 'static-page-name', 'learnpress' ), |
| 2607 |
'become_a_teacher' => _x( 'Become a Teacher', 'static-page-name', 'learnpress' ), |
| 2608 |
) |
| 2609 |
); |
| 2610 |
|
| 2611 |
if ( $name ) { |
| 2612 |
return array_keys( $pages ); |
| 2613 |
} |
| 2614 |
|
| 2615 |
return $pages; |
| 2616 |
} |
| 2617 |
|
| 2618 |
/** |
| 2619 |
* Callback function for sorting to array|object by key|prop priority. |
| 2620 |
* |
| 2621 |
* @param array|object $a |
| 2622 |
* @param array|object $b |
| 2623 |
* |
| 2624 |
* @return int |
| 2625 |
* @since 3.0.0 |
| 2626 |
*/ |
| 2627 |
function learn_press_sort_list_by_priority_callback( $a, $b ) { |
| 2628 |
$a_priority = null; |
| 2629 |
$b_priority = null; |
| 2630 |
|
| 2631 |
if ( is_array( $a ) && array_key_exists( 'priority', $a ) ) { |
| 2632 |
$a_priority = $a['priority']; |
| 2633 |
} elseif ( is_object( $a ) ) { |
| 2634 |
if ( is_callable( array( $a, 'get_priority' ) ) ) { |
| 2635 |
$a_priority = $a->get_priority(); |
| 2636 |
} elseif ( property_exists( $a, 'priority' ) ) { |
| 2637 |
$a_priority = $a->priority; |
| 2638 |
} |
| 2639 |
} |
| 2640 |
|
| 2641 |
if ( is_array( $b ) && array_key_exists( 'priority', $b ) ) { |
| 2642 |
$b_priority = $b['priority']; |
| 2643 |
} elseif ( is_object( $b ) ) { |
| 2644 |
if ( is_callable( array( $b, 'get_priority' ) ) ) { |
| 2645 |
$b_priority = $b->get_priority(); |
| 2646 |
} elseif ( property_exists( $b, 'priority' ) ) { |
| 2647 |
$b_priority = $b->priority; |
| 2648 |
} |
| 2649 |
} |
| 2650 |
|
| 2651 |
if ( $a_priority === $b_priority ) { |
| 2652 |
return 0; |
| 2653 |
} |
| 2654 |
|
| 2655 |
return ( $a_priority < $b_priority ) ? - 1 : 1; |
| 2656 |
} |
| 2657 |
|
| 2658 |
/** |
| 2659 |
* Localize date with custom format. |
| 2660 |
* |
| 2661 |
* @param int|bool $timestamp |
| 2662 |
* @param string $format |
| 2663 |
* @param bool $gmt |
| 2664 |
* |
| 2665 |
* @return string |
| 2666 |
* @since 3.0.0 |
| 2667 |
*/ |
| 2668 |
function learn_press_date_i18n( $timestamp = 0, string $format = '', bool $gmt = false ): string { |
| 2669 |
if ( ! $format ) { |
| 2670 |
$format = get_option( 'date_format' ); |
| 2671 |
} |
| 2672 |
|
| 2673 |
$date_str = date_i18n( $format, $timestamp, $gmt ); |
| 2674 |
if ( ! is_string( $date_str ) ) { |
| 2675 |
$date_str = ''; |
| 2676 |
} |
| 2677 |
|
| 2678 |
return $date_str; |
| 2679 |
} |
| 2680 |
|
| 2681 |
/** |
| 2682 |
* Get item types of course support for blocking. Default is lp_lesson |
| 2683 |
* |
| 2684 |
* @return array |
| 2685 |
* @since 3.0.0 |
| 2686 |
*/ |
| 2687 |
function learn_press_get_block_course_item_types() { |
| 2688 |
return apply_filters( 'learn-press/block-course-item-types', array( LP_LESSON_CPT, LP_QUIZ_CPT ) ); |
| 2689 |
} |
| 2690 |
|
| 2691 |
/** |
| 2692 |
* Get post type of a post from cache. |
| 2693 |
* If there is no data stored in cache then |
| 2694 |
* get it from WP API. |
| 2695 |
* |
| 2696 |
* @param int|WP_Post $post |
| 2697 |
* |
| 2698 |
* @return string |
| 2699 |
* @since 3.1.0 |
| 2700 |
*/ |
| 2701 |
function learn_press_get_post_type( $post ) { |
| 2702 |
$post_types = LP_Object_Cache::get( 'post-types', 'learn-press' ); |
| 2703 |
|
| 2704 |
if ( false === $post_types ) { |
| 2705 |
$post_types = array(); |
| 2706 |
} |
| 2707 |
|
| 2708 |
if ( is_object( $post ) ) { |
| 2709 |
$post_id = $post->ID; |
| 2710 |
} else { |
| 2711 |
$post_id = absint( $post ); |
| 2712 |
} |
| 2713 |
|
| 2714 |
if ( empty( $post_types[ $post_id ] ) ) { |
| 2715 |
$post_type = get_post_type( $post_id ); |
| 2716 |
$post_types[ $post_id ] = $post_type; |
| 2717 |
LP_Object_Cache::set( 'post-types', $post_types, 'learn-press' ); |
| 2718 |
} else { |
| 2719 |
$post_type = $post_types[ $post_id ]; |
| 2720 |
} |
| 2721 |
|
| 2722 |
return $post_type; |
| 2723 |
} |
| 2724 |
|
| 2725 |
/** |
| 2726 |
* Add post type of a post into cache |
| 2727 |
* |
| 2728 |
* @param int|array $id |
| 2729 |
* @param string $type |
| 2730 |
* |
| 2731 |
* @since 3.1.0 |
| 2732 |
* @deprecated 4.1.7.2 |
| 2733 |
*/ |
| 2734 |
/*function learn_press_cache_add_post_type( $id, $type = '' ) { |
| 2735 |
if ( false === ( $post_types = LP_Object_Cache::get( 'post-types', 'learn-press' ) ) ) { |
| 2736 |
$post_types = array(); |
| 2737 |
} |
| 2738 |
|
| 2739 |
if ( func_num_args() == 1 && is_array( $id ) ) { |
| 2740 |
$post_types = $post_types + $id; |
| 2741 |
} else { |
| 2742 |
$post_types[ $id ] = $type; |
| 2743 |
} |
| 2744 |
|
| 2745 |
LP_Object_Cache::set( 'post-types', $post_types, 'learn-press' ); |
| 2746 |
}*/ |
| 2747 |
|
| 2748 |
/** |
| 2749 |
* @deprecated 4.1.7.2 |
| 2750 |
*/ |
| 2751 |
/*function learn_press_has_option( $name ) { |
| 2752 |
global $wpdb; |
| 2753 |
|
| 2754 |
$query = $wpdb->prepare( "SELECT option_id FROM {$wpdb->options} WHERE option_name = %s", $name ); |
| 2755 |
|
| 2756 |
return $wpdb->get_var( $query ) > 0; |
| 2757 |
}*/ |
| 2758 |
|
| 2759 |
/** |
| 2760 |
* Update option to enable shuffle themes for ad. |
| 2761 |
* |
| 2762 |
* @since 3.2.1 |
| 2763 |
*/ |
| 2764 |
function _learn_press_schedule_enable_shuffle_themes() { |
| 2765 |
update_option( 'learn_press_ad_shuffle_themes', 'yes' ); |
| 2766 |
} |
| 2767 |
|
| 2768 |
add_action( 'learn-press/schedule-enable-shuffle-themes', '_learn_press_schedule_enable_shuffle_themes' ); |
| 2769 |
|
| 2770 |
/** |
| 2771 |
* @deprecated 4.1.7.2 |
| 2772 |
*/ |
| 2773 |
/*function learn_press_show_log() { |
| 2774 |
if ( trim( LP_Request::get( 'show_log' ) ) === md5( AUTH_KEY ) ) { |
| 2775 |
call_user_func_array( 'learn_press_debug', func_get_args() ); |
| 2776 |
} |
| 2777 |
}*/ |
| 2778 |
|
| 2779 |
/** |
| 2780 |
* Return localize script data for admin. |
| 2781 |
* |
| 2782 |
* @return array |
| 2783 |
* @since 3.2.6 |
| 2784 |
* @version 1.0.1 |
| 2785 |
*/ |
| 2786 |
function learn_press_global_script_params(): array { |
| 2787 |
$localize = [ |
| 2788 |
'ajax' => admin_url( 'admin-ajax.php' ), |
| 2789 |
'plugin_url' => LearnPress::instance()->plugin_url(), |
| 2790 |
'siteurl' => home_url(), |
| 2791 |
'current_url' => learn_press_get_current_url(), |
| 2792 |
'theme' => get_stylesheet(), |
| 2793 |
'localize' => array( |
| 2794 |
'button_ok' => __( 'OK', 'learnpress' ), |
| 2795 |
'button_cancel' => __( 'Cancel', 'learnpress' ), |
| 2796 |
'button_yes' => __( 'Yes', 'learnpress' ), |
| 2797 |
'button_no' => __( 'No', 'learnpress' ), |
| 2798 |
), |
| 2799 |
'rest' => esc_url_raw( rest_url() ), |
| 2800 |
'nonce' => wp_create_nonce( 'wp_rest' ), |
| 2801 |
'is_admin' => current_user_can( ADMIN_ROLE ), |
| 2802 |
]; |
| 2803 |
|
| 2804 |
return apply_filters( 'lp/admin/localize/scripts', $localize ); |
| 2805 |
} |
| 2806 |
|
| 2807 |
/** |
| 2808 |
* Get url for setup cron job on server. |
| 2809 |
* |
| 2810 |
* @return string |
| 2811 |
* @since 3.3.0 |
| 2812 |
* @deprecated 4.1.7.2 |
| 2813 |
*/ |
| 2814 |
/*function learn_press_get_cron_url() { |
| 2815 |
$nonce = get_option( 'learnpress_cron_url_nonce' ); |
| 2816 |
|
| 2817 |
if ( ! $nonce ) { |
| 2818 |
$nonce = md5( microtime( true ) ); |
| 2819 |
update_option( 'learnpress_cron_url_nonce', $nonce ); |
| 2820 |
} |
| 2821 |
$url = add_query_arg( |
| 2822 |
array( |
| 2823 |
'lp-ajax' => 'cron', |
| 2824 |
'sid' => $nonce, |
| 2825 |
), |
| 2826 |
get_home_url() |
| 2827 |
); |
| 2828 |
|
| 2829 |
return $url; |
| 2830 |
}*/ |
| 2831 |
|
| 2832 |
/** |
| 2833 |
* Get courses expired. |
| 2834 |
* |
| 2835 |
* @return array |
| 2836 |
* @since 3.3.0 |
| 2837 |
* @deprecated 4.1.7.2 |
| 2838 |
*/ |
| 2839 |
/*function learn_press_get_expired_courses() { |
| 2840 |
global $wpdb; |
| 2841 |
|
| 2842 |
$query = $wpdb->prepare( |
| 2843 |
" |
| 2844 |
SELECT X.* |
| 2845 |
FROM( |
| 2846 |
SELECT ui.* |
| 2847 |
FROM {$wpdb->learnpress_user_items} ui |
| 2848 |
LEFT JOIN {$wpdb->learnpress_user_items} uix |
| 2849 |
ON ui.item_id = uix.item_id |
| 2850 |
AND ui.user_id = uix.user_id |
| 2851 |
AND ui.user_item_id < uix.user_item_id |
| 2852 |
WHERE uix.user_item_id IS NULL |
| 2853 |
) X |
| 2854 |
INNER JOIN {$wpdb->users} u ON u.ID = X.user_id |
| 2855 |
INNER JOIN {$wpdb->posts} p ON p.ID = X.item_id |
| 2856 |
WHERE X.item_type = %s |
| 2857 |
AND X.status = %s |
| 2858 |
#AND expiration_time_gmt <= UTC_TIMESTAMP() |
| 2859 |
AND expiration_time <= UTC_TIMESTAMP() |
| 2860 |
LIMIT 0, 10 |
| 2861 |
", |
| 2862 |
LP_COURSE_CPT, |
| 2863 |
'enrolled' |
| 2864 |
); |
| 2865 |
|
| 2866 |
}*/ |
| 2867 |
|
| 2868 |
/** |
| 2869 |
* Return list types of questions that support answer options. |
| 2870 |
* |
| 2871 |
* @return array |
| 2872 |
* @since 3.3.0 |
| 2873 |
*/ |
| 2874 |
function learn_press_get_question_support_answer_options() { |
| 2875 |
$questions = learn_press_get_question_support_feature( 'answer-options' ); |
| 2876 |
|
| 2877 |
return apply_filters( 'learn-press/questions-support-answer-options', $questions ); |
| 2878 |
} |
| 2879 |
|
| 2880 |
/** |
| 2881 |
* Return list types of question that support a feature. |
| 2882 |
* |
| 2883 |
* @param string $feature |
| 2884 |
* |
| 2885 |
* @return array |
| 2886 |
* @since 3.3.0 |
| 2887 |
*/ |
| 2888 |
function learn_press_get_question_support_feature( $feature ) { |
| 2889 |
$questions = array(); |
| 2890 |
$types = LP_Global::get_object_supports( 'question' ); |
| 2891 |
|
| 2892 |
if ( $types ) { |
| 2893 |
foreach ( $types as $type => $features ) { |
| 2894 |
if ( array_key_exists( $feature, $features ) ) { |
| 2895 |
$questions[] = $type; |
| 2896 |
} |
| 2897 |
} |
| 2898 |
} |
| 2899 |
|
| 2900 |
return $questions; |
| 2901 |
} |
| 2902 |
|
| 2903 |
/** |
| 2904 |
* Helper function to output html for rendering a 'circle progress bar' |
| 2905 |
* |
| 2906 |
* @param int $percent |
| 2907 |
* @param int $width |
| 2908 |
* @param int $border |
| 2909 |
* @param string $color |
| 2910 |
* |
| 2911 |
* @since 3.3.0 |
| 2912 |
* @deprecated 4.1.7.2 |
| 2913 |
*/ |
| 2914 |
/*function learn_press_circle_progress_html( $percent = 0, $width = 32, $border = 4, $color = '' ) { |
| 2915 |
$radius = $width / 2; |
| 2916 |
$r = ( $width - $border ) / 2; |
| 2917 |
$circumference = $r * 2 * pi(); |
| 2918 |
$offset = $circumference - $percent / 100 * $circumference; |
| 2919 |
|
| 2920 |
printf( |
| 2921 |
'<svg class="circle-progress-bar" width="%d" height="%d"> |
| 2922 |
<circle class="circle-progress-bar__circle" |
| 2923 |
stroke="%s" |
| 2924 |
stroke-width="%d" |
| 2925 |
style="stroke-dasharray:%s %s; stroke-dashoffset:%s;" |
| 2926 |
fill="transparent" |
| 2927 |
r="%d" cx="%d" cy="%d"></circle> |
| 2928 |
</svg>', |
| 2929 |
$width, |
| 2930 |
$width, |
| 2931 |
$color, |
| 2932 |
$border, |
| 2933 |
$circumference, |
| 2934 |
$circumference, |
| 2935 |
$offset, |
| 2936 |
$r, |
| 2937 |
$radius, |
| 2938 |
$radius |
| 2939 |
); |
| 2940 |
}*/ |
| 2941 |
|
| 2942 |
/** |
| 2943 |
* @deprecated 4.1.7.2 |
| 2944 |
*/ |
| 2945 |
/*function learn_press_is_page( $page_name ) { |
| 2946 |
$page_id = learn_press_get_page_id( $page_name ); |
| 2947 |
|
| 2948 |
return $page_id && is_page( $page_id ); |
| 2949 |
}*/ |
| 2950 |
|
| 2951 |
/** |
| 2952 |
* Get end-date from start date with a duration. |
| 2953 |
* |
| 2954 |
* @param string|int $duration |
| 2955 |
* @param string|int $start |
| 2956 |
* |
| 2957 |
* @return false|string |
| 2958 |
* @since 3.x.x |
| 2959 |
* @deprecated 4.1.7.2 |
| 2960 |
*/ |
| 2961 |
/*function learn_press_date_end_from( $duration, $start = '' ) { |
| 2962 |
$format = 'Y-m-d H:i:s'; |
| 2963 |
|
| 2964 |
if ( ! $start ) { |
| 2965 |
$start = time(); |
| 2966 |
} elseif ( ! is_numeric( $start ) ) { |
| 2967 |
$start = strtotime( $start ); |
| 2968 |
} |
| 2969 |
|
| 2970 |
// is LP duration format, e.g: 10 weeks |
| 2971 |
if ( preg_match( '/^[0-9]+ [a-z]+$/', $duration ) ) { |
| 2972 |
$duration = ( new LP_Duration( $duration ) )->get(); |
| 2973 |
} elseif ( ! is_numeric( $duration ) ) { |
| 2974 |
// 10 days 5 hours ... |
| 2975 |
$duration = strtotime( $duration, 0 ); |
| 2976 |
} |
| 2977 |
|
| 2978 |
return date( $format, $start + $duration ); |
| 2979 |
}*/ |
| 2980 |
|
| 2981 |
function learn_press_cookie_get( $name, $namespace = 'LP' ) { |
| 2982 |
if ( $namespace ) { |
| 2983 |
$cookie = ! empty( $_COOKIE[ $namespace ] ) ? (array) json_decode( LP_Helper::sanitize_params_submitted( stripslashes( $_COOKIE[ $namespace ] ), 'html' ) ) : array(); |
| 2984 |
} else { |
| 2985 |
$cookie = $_COOKIE; |
| 2986 |
} |
| 2987 |
|
| 2988 |
return $cookie[ $name ] ?? null; |
| 2989 |
} |
| 2990 |
|
| 2991 |
/** |
| 2992 |
* Get default methods to evaluate course results. |
| 2993 |
* |
| 2994 |
* @param string $return - Optional. 'keys' will return keys instead of all. |
| 2995 |
* |
| 2996 |
* @return array |
| 2997 |
* @since 3.x.x |
| 2998 |
*/ |
| 2999 |
function learn_press_course_evaluation_methods( $postid, $return = '', $final_quizz_passing = '' ) { |
| 3000 |
$course_tip = '<span class="learn-press-tip">%s</span>'; |
| 3001 |
$final_quiz_btn = '<a href="#" class="lp-metabox-get-final-quiz" data-postid="' . $postid . '" data-loading="' . esc_attr__( |
| 3002 |
'Loading...', |
| 3003 |
'learnpress' |
| 3004 |
) . '">' . esc_html__( 'Get A Passing Grade', 'learnpress' ) . '</a>'; |
| 3005 |
|
| 3006 |
$course_desc = array( |
| 3007 |
'evaluate_lesson' => sprintf( |
| 3008 |
'<p>%s<br/>%s</p>', |
| 3009 |
__( 'Evaluate by the number of completed lessons per the total number of lessons.', 'learnpress' ), |
| 3010 |
__( 'E.g: If a course has 10 lessons and a user completes 5 lessons, then the result is 5/10 (50%).', 'learnpress' ) |
| 3011 |
), |
| 3012 |
'evaluate_final_quiz' => __( |
| 3013 |
'Evaluate by the result of the final quiz in the course. You have to add a quiz at the end of the course.', |
| 3014 |
'learnpress' |
| 3015 |
), |
| 3016 |
'evaluate_quiz' => sprintf( |
| 3017 |
'<p>%s<br/>%s</p>', |
| 3018 |
__( 'Evaluate by the number of passed quizzes per the total number of quizzes.', 'learnpress' ), |
| 3019 |
__( |
| 3020 |
'E.g: If the course has 10 quizzes and the user passes 5 quizzes, then the result is 5/10 (50%).', |
| 3021 |
'learnpress' |
| 3022 |
) |
| 3023 |
), |
| 3024 |
'evaluate_questions' => sprintf( |
| 3025 |
'<p>%s<br/>%s</p>', |
| 3026 |
__( 'Evaluate by the number of correct answers per the total number of questions.', 'learnpress' ), |
| 3027 |
__( |
| 3028 |
'E.g: If the course has 10 questions and the user corrects 5 questions, then the result is 5/10 (50%).', |
| 3029 |
'learnpress' |
| 3030 |
) |
| 3031 |
), |
| 3032 |
'evaluate_mark' => __( 'Evaluate by the number of achieved scores per the total score of the questions.', 'learnpress' ), |
| 3033 |
); |
| 3034 |
|
| 3035 |
$methods = apply_filters( |
| 3036 |
'learnpress/course-evaluation/methods', |
| 3037 |
array( |
| 3038 |
'evaluate_lesson' => __( |
| 3039 |
'Evaluate via lessons', |
| 3040 |
'learnpress' |
| 3041 |
) . learn_press_quick_tip( $course_desc['evaluate_lesson'], false ), |
| 3042 |
'evaluate_final_quiz' => __( 'Evaluate via results of the final quiz', 'learnpress' ) . sprintf( |
| 3043 |
$course_tip, |
| 3044 |
$course_desc['evaluate_final_quiz'] |
| 3045 |
) . $final_quiz_btn . $final_quizz_passing, |
| 3046 |
'evaluate_quiz' => __( 'Evaluate via passed quizzes', 'learnpress' ) . sprintf( |
| 3047 |
$course_tip, |
| 3048 |
$course_desc['evaluate_quiz'] |
| 3049 |
), |
| 3050 |
'evaluate_questions' => __( 'Evaluate via questions', 'learnpress' ) . sprintf( |
| 3051 |
$course_tip, |
| 3052 |
$course_desc['evaluate_questions'] |
| 3053 |
), |
| 3054 |
'evaluate_mark' => __( 'Evaluate via mark', 'learnpress' ) . sprintf( |
| 3055 |
$course_tip, |
| 3056 |
$course_desc['evaluate_mark'] |
| 3057 |
), |
| 3058 |
) |
| 3059 |
); |
| 3060 |
|
| 3061 |
return apply_filters( |
| 3062 |
'learn-press/course-evaluation-methods', |
| 3063 |
$return === 'keys' ? array_keys( $methods ) : $methods, |
| 3064 |
$return |
| 3065 |
); |
| 3066 |
} |
| 3067 |
|
| 3068 |
/** |
| 3069 |
* Convert time from GMT to local. |
| 3070 |
* |
| 3071 |
* @param string|int|LP_Datetime $gmt_time |
| 3072 |
* @param string $format |
| 3073 |
* |
| 3074 |
* @return false|int|string |
| 3075 |
* @since 4.0.0 |
| 3076 |
* @deprecated 4.1.7.2 |
| 3077 |
*/ |
| 3078 |
/*function learn_press_time_from_gmt( $gmt_time, $format = 'Y-m-d H:i:s' ) { |
| 3079 |
if ( is_string( $gmt_time ) ) { |
| 3080 |
$gmt_time = strtotime( $gmt_time ); |
| 3081 |
} elseif ( $gmt_time instanceof LP_Datetime ) { |
| 3082 |
$gmt_time = strtotime( $gmt_time . '' ); |
| 3083 |
} |
| 3084 |
|
| 3085 |
$current_time = $gmt_time + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS; |
| 3086 |
|
| 3087 |
if ( $format ) { |
| 3088 |
return date( $format, $current_time ); |
| 3089 |
} |
| 3090 |
|
| 3091 |
return $current_time; |
| 3092 |
}*/ |
| 3093 |
|
| 3094 |
/** |
| 3095 |
* Get max retrying quiz allowed. |
| 3096 |
* |
| 3097 |
* @param int $quiz_id |
| 3098 |
* @param int $course_id |
| 3099 |
* |
| 3100 |
* @return int |
| 3101 |
* @since 4.0.0 |
| 3102 |
*/ |
| 3103 |
function learn_press_get_quiz_max_retrying( $quiz_id = 0, $course_id = 0 ) { |
| 3104 |
return apply_filters( 'learn-press/max-retry-quiz-allowed', 1, $quiz_id, $course_id ); |
| 3105 |
} |
| 3106 |
|
| 3107 |
/** |
| 3108 |
* Get max retrying course allowed. |
| 3109 |
* |
| 3110 |
* @param int $course_id |
| 3111 |
* |
| 3112 |
* @return int |
| 3113 |
* @since 4.0.0 |
| 3114 |
* @deprecated 4.1.7.2 |
| 3115 |
*/ |
| 3116 |
/*function learn_press_get_course_max_retrying( $course_id ) { |
| 3117 |
return apply_filters( 'learn-press/max-retry-course-allowed', 1, $course_id ); |
| 3118 |
}*/ |
| 3119 |
|
| 3120 |
/** |
| 3121 |
* Get slug for status of course/lesson/quiz if user |
| 3122 |
* completed/finished and graduation is passed. |
| 3123 |
* |
| 3124 |
* @param string $type |
| 3125 |
* |
| 3126 |
* @return string |
| 3127 |
* @since 4.0.0 |
| 3128 |
*/ |
| 3129 |
function learn_press_user_item_in_progress_slug( $type = '' ) { |
| 3130 |
return apply_filters( 'learn-press/user-item-in-progress-slug', 'in-progress', $type ); |
| 3131 |
} |
| 3132 |
|
| 3133 |
/** |
| 3134 |
* Get slug for status of course/lesson/quiz if user |
| 3135 |
* completed/finished and result is under-evaluation |
| 3136 |
* |
| 3137 |
* @param string $item - Optional. Type of item |
| 3138 |
* |
| 3139 |
* @return string |
| 3140 |
* @since 4.0.0 |
| 3141 |
*/ |
| 3142 |
function learn_press_user_item_under_evaluation_slug( $item = '' ) { |
| 3143 |
return apply_filters( 'learn-press/user-item-under-evaluation-slug', 'in-progress', $item ); |
| 3144 |
} |
| 3145 |
|
| 3146 |
function learn_press_is_enrolled_slug( $slug ) { |
| 3147 |
return in_array( |
| 3148 |
$slug, |
| 3149 |
array( |
| 3150 |
'in-progress', |
| 3151 |
'enrolled', |
| 3152 |
) |
| 3153 |
); |
| 3154 |
} |
| 3155 |
|
| 3156 |
/** |
| 3157 |
* @return array |
| 3158 |
* @since 4.0.0 |
| 3159 |
*/ |
| 3160 |
function lp_item_course_class( $class = array() ) { |
| 3161 |
$classes = array_merge( |
| 3162 |
$class, |
| 3163 |
array( 'learn-press-courses' ) |
| 3164 |
); |
| 3165 |
echo 'class="' . esc_attr( implode( ' ', apply_filters( 'lp_item_course_class', $classes ) ) ) . '"'; |
| 3166 |
} |
| 3167 |
|
| 3168 |
//require_once dirname( __FILE__ ) . '/lp-custom-hooks.php'; |
| 3169 |
|
| 3170 |
|
| 3171 |
/** |
| 3172 |
* Disable auto update |
| 3173 |
* |
| 3174 |
* @param $update |
| 3175 |
* @param $item |
| 3176 |
* |
| 3177 |
* @return false |
| 3178 |
* @author hungkv |
| 3179 |
*/ |
| 3180 |
/*function learnpress_disable_auto_update( $update, $item ) { |
| 3181 |
$plugins = array( // Plugins to auto-update |
| 3182 |
'learnpress', |
| 3183 |
); |
| 3184 |
// Auto-update specified plugins |
| 3185 |
if ( in_array( $item->slug, $plugins ) ) { |
| 3186 |
return false; |
| 3187 |
} |
| 3188 |
} |
| 3189 |
add_filter( 'auto_update_plugin', 'learnpress_disable_auto_update', 10, 2 );*/ |
| 3190 |
|
| 3191 |
add_action( |
| 3192 |
'in_plugin_update_message-learnpress/learnpress.php', |
| 3193 |
function ( $plugin_data ) { |
| 3194 |
if ( version_compare( $plugin_data['new_version'], LEARNPRESS_VERSION, '<=' ) ) { |
| 3195 |
return; |
| 3196 |
} |
| 3197 |
?> |
| 3198 |
<hr/> |
| 3199 |
<h3> |
| 3200 |
<?php echo esc_html__( 'Heads up! Please backup before upgrading!', 'learnpress' ); ?> |
| 3201 |
</h3> |
| 3202 |
<div> |
| 3203 |
<?php echo esc_html__( 'The latest update includes some substantial changes across different areas of the plugin. We highly recommend you backup your site before upgrading, and make sure you first update in a staging environment', 'learnpress' ); ?> |
| 3204 |
</div> |
| 3205 |
<?php |
| 3206 |
} |
| 3207 |
); |
| 3208 |
|
| 3209 |
// If profile content don't have shortcode profile. |
| 3210 |
function lp_add_shortcode_profile() { |
| 3211 |
global $post; |
| 3212 |
|
| 3213 |
if ( learn_press_is_profile() && is_object( $post ) ) { |
| 3214 |
if ( ! has_shortcode( $post->post_content, 'learn_press_profile' ) ) { |
| 3215 |
$post->post_content .= '<!-- wp:shortcode -->[' . apply_filters( 'learn-press/shortcode/profile/tag', 'learn_press_profile' ) . ']<!-- /wp:shortcode -->'; |
| 3216 |
} |
| 3217 |
|
| 3218 |
wp_update_post( $post ); |
| 3219 |
} |
| 3220 |
} |
| 3221 |
|
| 3222 |
add_action( 'template_redirect', 'lp_add_shortcode_profile' ); |
| 3223 |
|
| 3224 |
/** |
| 3225 |
* If Elementor Pro set Theme builder type "Archive", will not show content on page "Archive course" |
| 3226 |
* |
| 3227 |
* @editor tungnx |
| 3228 |
* @author nhamdv |
| 3229 |
* |
| 3230 |
* @since 4.0.6 |
| 3231 |
* @version 1.0.1 |
| 3232 |
*/ |
| 3233 |
add_filter( |
| 3234 |
'elementor/theme/get_location_templates/template_id', |
| 3235 |
function( $theme_template_id ) { |
| 3236 |
$elementor_template_type = get_post_meta( $theme_template_id, '_elementor_template_type', true ); |
| 3237 |
|
| 3238 |
if ( in_array( $elementor_template_type, array( 'archive' ) ) ) { |
| 3239 |
if ( LP_PAGE_COURSES === LP_Page_Controller::page_current() && class_exists( 'ElementorPro\Modules\ThemeBuilder\Conditions\Archive' ) ) { |
| 3240 |
return false; |
| 3241 |
} |
| 3242 |
} |
| 3243 |
|
| 3244 |
return $theme_template_id; |
| 3245 |
} |
| 3246 |
); |
| 3247 |
|