PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.3.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.3.8
4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 4.2.1 All 138 releases
learnpress / inc / admin / lp-admin-functions.php

lp-admin-functions.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.3.8, at inc/admin/lp-admin-functions.php

2,228 lines 58.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Common functions used for admin
4 *
5 * @package LearnPress
6 * @author ThimPress
7 * @version 1.0
8 */
9
10 /**
11 * Prevent loading this file directly
12 */
13 defined( 'ABSPATH' ) || exit();
14
15 if ( ! function_exists( 'learn_press_add_row_action_link' ) ) {
16 /**
17 * Setup action links to the admin course, lesson, quiz, question. e.g: Add Duplicate link, hide View link for lesson, quiz so on.
18 *
19 * @param $actions
20 *
21 * @return mixed
22 */
23 function learn_press_add_row_action_link( $actions ) {
24
25 global $post;
26
27 if ( LP_COURSE_CPT == $post->post_type ) {
28 $duplicate_link = '#';
29 $duplicate_link = array(
30 array(
31 'link' => $duplicate_link,
32 'title' => _x( 'Duplicate', 'copy course', 'learnpress' ),
33 'class' => 'lp-duplicate-post lp-duplicate-course',
34 'data' => $post->ID,
35 ),
36 );
37
38 $links = apply_filters( 'learn_press_row_action_links', $duplicate_link );
39
40 if ( count( $links ) > 1 ) {
41 $drop_down = array( '<ul class="lpr-row-action-dropdown">' );
42
43 foreach ( $links as $link ) {
44 $drop_down[] = '<li>' . sprintf(
45 '<a href="%s" class="%s" data-post-id="%s">%s</a>',
46 $link['link'],
47 $link['class'],
48 $link['data'],
49 $link['title']
50 ) . '</li>';
51 }
52
53 $drop_down[] = '</ul>';
54 $link = sprintf(
55 '<div class="lpr-row-actions"><a href="%s">%s</a>%s</div>',
56 'javascript: void(0);',
57 __( 'Course', 'learnpress' ),
58 join( "\n", $drop_down )
59 );
60
61 } else {
62 $link = array_shift( $links );
63 $link = sprintf(
64 '<a href="%s" class="%s" data-post-id="%s">%s</a>',
65 $link['link'],
66 $link['class'],
67 $link['data'],
68 $link['title']
69 );
70 }
71
72 $actions['lp-duplicate-row-action'] = $link;
73
74 } elseif ( LP_QUIZ_CPT === $post->post_type ) {
75 unset( $actions['view'] );
76 $link = sprintf(
77 '<a href="#" class="lp-duplicate-post lp-duplicate-quiz" data-post-id="%s">%s</a>',
78 $post->ID,
79 _x( 'Duplicate', 'copy quiz', 'learnpress' )
80 );
81 $actions['lp-duplicate-row-action'] = $link;
82
83 } elseif ( LP_QUESTION_CPT === $post->post_type ) {
84 unset( $actions['view'] );
85 $link = sprintf(
86 '<a href="#" class="lp-duplicate-post lp-duplicate-question" data-post-id="%s">%s</a>',
87 $post->ID,
88 _x( 'Duplicate', 'copy question', 'learnpress' )
89 );
90 $actions['lp-duplicate-row-action'] = $link;
91
92 } elseif ( LP_LESSON_CPT === $post->post_type ) {
93 unset( $actions['view'] );
94 $link = sprintf(
95 '<a href="#" class="lp-duplicate-post lp-duplicate-lesson" data-post-id="%s">%s</a>',
96 $post->ID,
97 _x( 'Duplicate', 'copy lesson', 'learnpress' )
98 );
99 $actions['lp-duplicate-row-action'] = $link;
100 }
101
102 return apply_filters( 'learn-press/row-action-links', $actions );
103 }
104
105 add_filter( 'post_row_actions', 'learn_press_add_row_action_link' );
106 add_filter( 'page_row_actions', 'learn_press_add_row_action_link' );
107 }
108
109 /*function learn_press_is_hidden_post_box( $id, $user_id = 0 ) {
110 if ( ! $user_id ) {
111 $user_id = get_current_user_id();
112 }
113
114 $data = learn_press_get_user_option( 'post-closed-box' );
115 if ( ! $data ) {
116 $data = array();
117 }
118
119 return false !== array_search( $id, $data );
120 }*/
121
122 /**
123 * List all pages as a dropdown with "Add New Page" option
124 *
125 * @param $name
126 * @param bool|false $selected
127 * @param array $args
128 *
129 * @return mixed|string
130 */
131 function learn_press_pages_dropdown( $name, $selected = false, $args = array() ) {
132 $id = null;
133 $class = null;
134 $css = null;
135 $before = array(
136 'add_new_page' => __( '[ Add a new page ]', 'learnpress' ),
137 );
138 $after = null;
139 $echo = true;
140 $allow_create = true;
141
142 if ( func_num_args() == 1 && is_array( $name ) ) {
143 $args = $name;
144 }
145
146 is_array( $args ) && extract( $args );
147
148 if ( empty( $id ) ) {
149 $id = $name;
150 }
151
152 $class .= 'list-pages lp-list-pages lp-tom-select';
153
154 $args = array(
155 'name' => $name,
156 'id' => $id,
157 'sort_column' => 'menu_order',
158 'sort_order' => 'ASC',
159 'show_option_none' => __( 'Select Page', 'learnpress' ),
160 'class' => $class,
161 'echo' => false,
162 'selected' => $selected,
163 'allow_create' => true,
164 );
165 $output = wp_dropdown_pages( $args );
166 $replace = '';
167
168 if ( $class ) {
169 $replace .= ' class="' . $class . '"';
170 }
171
172 if ( $css ) {
173 $replace .= ' style="' . $css . '"';
174 }
175
176 $replace .= ' data-selected="' . $selected . '"';
177 $replace .= " data-placeholder='" . __( 'Select a page&hellip;', 'learnpress' ) . "' id=";
178 $output = '<div class="list-pages-wrapper">' . str_replace( ' id=', $replace, $output );
179
180 if ( $before ) {
181 $before_output = array();
182
183 foreach ( $before as $v => $l ) {
184 $before_output[] = sprintf( '<option value="%s">%s</option>', $v, $l );
185 }
186
187 $before_output = join( "\n", $before_output );
188 $output = preg_replace(
189 '!(<option class=".*" value="[0-9]+".*>.*</option>)!',
190 $before_output . "\n$1",
191 $output,
192 1
193 );
194 }
195
196 $output = str_replace( '<option class="level-0" value="00000">#0 (no title)</option>', '', $output );
197
198 if ( $selected && get_post_status( $selected ) !== 'publish' ) {
199 $selected = 0;
200 }
201
202 if ( $allow_create ) {
203 ob_start(); ?>
204
205 <?php echo esc_html( _x( 'or', 'dropdown pages', 'learnpress' ) ); ?>
206
207 <button class="button button-quick-add-page" data-id="<?php echo esc_attr( $id ); ?>" type="button">
208 <?php esc_html_e( 'Create new', 'learnpress' ); ?>
209 </button>
210 <?php echo '</div>'; ?>
211
212 <p class="quick-add-page-inline <?php echo esc_attr( $id ); ?> hide-if-js">
213 <input type="text" placeholder="<?php esc_attr_e( 'New page title', 'learnpress' ); ?>"/>
214 <button class="button" type="button">
215 <?php esc_html_e( 'Ok [Enter]', 'learnpress' ); ?>
216 </button>
217 <a href=""><?php esc_html_e( 'Cancel [ESC]', 'learnpress' ); ?></a>
218 </p>
219
220 <p class="quick-add-page-actions <?php echo esc_attr( $id ); ?><?php echo esc_attr( $selected ? '' : ' hide-if-js' ); ?>">
221 <a class="edit-page" href="<?php echo get_edit_post_link( $selected ); ?>"
222 target="_blank"><?php esc_html_e( 'Edit page', 'learnpress' ); ?></a>
223 &#124;
224 <a class="view-page" href="<?php echo get_permalink( $selected ); ?>"
225 target="_blank"><?php esc_html_e( 'View page', 'learnpress' ); ?></a>
226 </p>
227 <!-- Not use input on here, will be not save value -->
228 <div class="field_name" name="<?php echo esc_attr( $id ); ?>"></div>
229
230 <?php
231 $output .= ob_get_clean();
232 } else {
233 $output .= '</div>';
234 }
235
236 $output = sprintf( '<div class="learn-press-dropdown-pages">%s</div>', $output );
237
238 if ( $echo ) {
239 $allowed_html = wp_kses_allowed_html( 'post' );
240 $allowed_html['select'] = [
241 'name' => [],
242 'class' => [],
243 ];
244 $allowed_html['option'] = [
245 'value' => [],
246 'selected' => [],
247 'class' => [],
248 ];
249 $allowed_html['input'] = [
250 'type' => [],
251 'placeholder' => [],
252 'name' => [],
253 'class' => [],
254 ];
255 $allowed_html['div'] = [
256 'name' => [],
257 'class' => [],
258 ];
259
260 echo wp_kses( $output, $allowed_html );
261 }
262
263 return $output;
264 }
265
266 /**
267 * List all registered question types into dropdown
268 *
269 * @param array
270 *
271 * @return string
272 */
273 function learn_press_dropdown_question_types( $args = array() ) {
274 $args = wp_parse_args(
275 $args,
276 array(
277 'name' => 'learn-press-dropdown-question-types',
278 'id' => '',
279 'class' => '',
280 'selected' => '',
281 'echo' => true,
282 )
283 );
284
285 if ( ! $args['id'] ) {
286 $args['id'] = $args['name'];
287 }
288
289 $args['class'] = 'lp-dropdown-question-types' . ( $args['class'] ? ' ' . $args['class'] : '' );
290 $types = learn_press_question_types();
291 $output = sprintf(
292 '<select name="%s" id="%s" class="%s"%s>',
293 $args['name'],
294 $args['id'],
295 $args['class'],
296 $args['selected'] ? 'data-selected="' . $args['selected'] . '"' : ''
297 );
298
299 foreach ( $types as $slug => $name ) {
300 $output .= sprintf(
301 '<option value="%s"%s>%s</option>',
302 $slug,
303 selected( $slug == $args['selected'], true, false ),
304 $name
305 );
306 }
307
308 $output .= '</select>';
309
310 if ( $args['echo'] ) {
311 echo wp_kses_post( $output );
312 }
313
314 return $output;
315 }
316
317 /**
318 * List all registered question types into dropdown
319 *
320 * @param array $args
321 * @param LP_Question $question
322 *
323 * @return string
324 */
325 function learn_press_field_question_duration( $args = array(), $question = null ) {
326 global $post;
327
328 $duration_type = get_post_meta( $post->ID, '_lp_duration_type', true );
329 $value = get_post_meta( $question->id, '_question_duration', true );
330
331 $wrap_class = 'learn-press-question-duration';
332
333 if ( 'questions_duration' !== $duration_type ) {
334 $wrap_class .= ' hide';
335 }
336
337 $args = wp_parse_args(
338 $args,
339 array(
340 'name' => 'learn_press_question[' . $question->id . '][duration]',
341 'id' => 'learn-press-question-duration-' . $question->id,
342 'class' => 'learn-press-question-duration',
343 'selected' => '',
344 'echo' => true,
345 'value' => 0,
346 'step' => 1,
347 'min' => 0,
348 'placeholder' => __( 'Minutes', 'learnpress' ),
349 )
350 );
351
352 $args['value'] = $value;
353
354 if ( ! $args['id'] ) {
355 $args['id'] = $args['name'];
356 }
357
358 return '<span class="' . esc_attr( $wrap_class ) . '">' . sprintf(
359 '<input type="number" class="%s" name="%s" id="%s" value="%s" step="%s" min="%s" max="%s" placeholder="%s"/>',
360 $args['class'],
361 $args['name'],
362 empty( $args['clone'] ) ? $args['id'] : '',
363 $args['value'],
364 $args['step'],
365 $args['min'],
366 ! empty( $args['max'] ) ? $args['max'] : '',
367 $args['placeholder']
368 ) . $args['placeholder'] . '</span>';
369 }
370
371 /**
372 * Displays email formats support into a dropdown
373 *
374 * @param array $args
375 *
376 * @return string
377 * @deprecated 4.2.6.9.3
378 */
379 /*function learn_press_email_formats_dropdown( $args = array() ) {
380 $args = wp_parse_args(
381 $args,
382 array(
383 'name' => 'learn-press-dropdown-email-formats',
384 'id' => '',
385 'class' => '',
386 'selected' => '',
387 'option_none' => '',
388 'echo' => true,
389 )
390 );
391
392 $formats = array(
393 'plain_text' => __( 'Plain Text', 'learnpress' ),
394 'html' => __( 'HTML', 'learnpress' ),
395 );
396
397 if ( empty( $args['id'] ) ) {
398 $args['id'] = sanitize_file_name( $args['name'] );
399 }
400
401 $output = sprintf( '<select name="%s" id="%s" class="%s" %s>', $args['name'], $args['id'], $args['class'], '' );
402
403 if ( $args['option_none'] ) {
404 if ( is_array( $args['option_none'] ) ) {
405 $text = reset( $args['option_none'] );
406 $value = key( $args['option_none'] );
407 } else {
408 $text = $args['option_none'];
409 $value = '';
410 }
411
412 $output .= sprintf( '<option value="%s">%s</option>', $value, $text );
413 }
414
415 foreach ( $formats as $name => $text ) {
416 $output .= sprintf(
417 '<option value="%s" %s>%s</option>',
418 $name,
419 selected( $args['selected'] == $name, true, false ),
420 $text
421 ) . "\n";
422 }
423 $output .= '</select>';
424
425 if ( $args['echo'] ) {
426 echo wp_kses_post( $output );
427 }
428
429 return $output;
430 }*/
431
432 /**
433 * Return array of email formats.
434 *
435 * @return mixed
436 */
437 function learn_press_email_formats() {
438 $formats = array(
439 'plain' => esc_html__( 'Plain Text', 'learnpress' ),
440 'html' => esc_html__( 'HTML', 'learnpress' ),
441 );
442
443 return apply_filters( 'learn-press/email-formats', $formats );
444 }
445
446 function learn_press_trim_content( $content, $count = 0 ) {
447 $content = preg_replace( '/(?<=\S,)(?=\S)/', ' ', $content );
448 $content = str_replace( "\n", ' ', $content );
449 $content = explode( ' ', $content );
450
451 $count = $count > 0 ? $count : sizeof( $content ) - 1;
452 $full = $count >= sizeof( $content ) - 1;
453
454 $content = array_slice( $content, 0, $count );
455 $content = implode( ' ', $content );
456
457 if ( ! $full ) {
458 $content .= '...';
459 }
460
461 return $content;
462 }
463
464 /**
465 * Get list of themes that support LearnPress.
466 *
467 * @return mixed
468 */
469 function learn_press_get_education_themes() {
470
471 // New theme can be added here
472 return apply_filters(
473 'learn-press/education-themes',
474 array(
475 '23451388' => 'kindergarten',
476 '22773871' => 'ivy-school',
477 '20370918' => 'wordpress-lms',
478 '14058034' => 'eduma',
479 '17097658' => 'coach',
480 '11797847' => 'lms',
481 )
482 );
483 }
484
485 if ( ! function_exists( 'learn_press_get_item_referral' ) ) {
486 /**
487 * Set item link referral.
488 *
489 * @param int|string $item_id
490 *
491 * @return string
492 */
493 function learn_press_get_item_referral( $item_id ) {
494 $affiliate_links = array(
495 14058034 => 'https://1.envato.market/G5Ook', // Eduma
496 22773871 => 'https://1.envato.market/akrzZ', // Ivy-school
497 20370918 => 'https://1.envato.market/13Zkd', // Course Builder LMS
498 17097658 => 'https://1.envato.market/Xq2Ra', // Coach
499 23451388 => 'https://1.envato.market/oWov9', // StarKid
500 11797847 => 'https://1.envato.market/zknvM', // Epsilon
501 13321455 => 'https://1.envato.market/G5Rkk', // Sailing
502 19029758 => 'https://1.envato.market/mAYdZ', // Travel Tour Booking
503 12124219 => 'https://1.envato.market/qJYdO', // Resca
504 18828322 => 'https://1.envato.market/VW2K3', // LuxStay
505 8254575 => 'https://1.envato.market/xWYdO', // Squareroot
506 13782850 => 'https://1.envato.market/Qo71z',
507 14025178 => 'https://1.envato.market/9R0oQ',
508 17739078 => 'https://1.envato.market/jkYda',
509 16210005 => 'https://1.envato.market/56oJD',
510 11733602 => 'https://1.envato.market/keYdv',
511 13513609 => 'https://1.envato.market/aq7dQ',
512 19693761 => 'https://1.envato.market/A976D',
513 12532973 => 'https://1.envato.market/Ge79B',
514 19305239 => 'https://1.envato.market/10JAB',
515 23716060 => 'https://1.envato.market/ZO7WW',
516 20466233 => 'https://1.envato.market/gjYd0',
517 21070438 => 'https://1.envato.market/xPz65',
518 20794183 => 'https://1.envato.market/o1YdY',
519 20979215 => 'https://1.envato.market/03R5V',
520 11151269 => 'https://1.envato.market/Br7L4',
521 8905392 => 'https://1.envato.market/zEYd7',
522 23168294 => 'https://1.envato.market/Wn7on',
523 17719422 => 'https://1.envato.market/0WVaL',
524 21680592 => 'https://1.envato.market/qqO6y',
525 );
526
527 return $affiliate_links[ $item_id ] ?? 'https://themeforest.net/user/thimpress/portfolio/';
528 }
529 }
530
531 /**
532 * Count number of orders between to dates
533 *
534 * @param string
535 * @param int
536 *
537 * @return int
538 */
539 function learn_press_get_order_by_time( $by, $time ) {
540 global $wpdb;
541
542 $user_id = get_current_user_id();
543
544 $y = gmdate( 'Y', $time );
545 $m = gmdate( 'm', $time );
546 $d = gmdate( 'd', $time );
547
548 switch ( $by ) {
549 case 'days':
550 $orders = $wpdb->get_var(
551 $wpdb->prepare(
552 "SELECT COUNT(*)
553 FROM $wpdb->posts AS p
554 INNER JOIN $wpdb->postmeta AS m ON p.ID = m.post_id
555 WHERE p.post_author = %d
556 AND p.post_type = %s
557 AND p.post_status = %s
558 AND m.meta_key = %s
559 AND m.meta_value = %s
560 AND YEAR(p.post_date) = %s AND MONTH(p.post_date) = %s AND DAY(p.post_date) = %s",
561 $user_id,
562 LP_ORDER_CPT,
563 'publish',
564 '_learn_press_transaction_status',
565 'completed',
566 $y,
567 $m,
568 $d
569 )
570 );
571 break;
572 case 'months':
573 $orders = $wpdb->get_var(
574 $wpdb->prepare(
575 "SELECT COUNT(*)
576 FROM $wpdb->posts AS p
577 INNER JOIN $wpdb->postmeta AS m ON p.ID = m.post_id
578 WHERE p.post_author = %d
579 AND p.post_type = %s
580 AND p.post_status = %s
581 AND m.meta_key = %s
582 AND m.meta_value = %s
583 AND YEAR(p.post_date) = %s AND MONTH(p.post_date) = %s",
584 $user_id,
585 LP_ORDER_CPT,
586 'publish',
587 '_learn_press_transaction_status',
588 'completed',
589 $y,
590 $m
591 )
592 );
593 break;
594 }
595
596 return $orders;
597 }
598
599 /**
600 * Count number of orders by status
601 *
602 * @param string Status of the orders
603 *
604 * @return int
605 */
606 function learn_press_get_courses_by_status( $status ) {
607 global $wpdb;
608
609 $user_id = get_current_user_id();
610
611 $courses = $wpdb->get_var(
612 $wpdb->prepare(
613 "SELECT COUNT(*)
614 FROM $wpdb->posts
615 WHERE post_author = %d
616 AND post_type = %s
617 AND post_status = %s",
618 $user_id,
619 LP_COURSE_CPT,
620 $status
621 )
622 );
623
624 return $courses;
625 }
626
627 /**
628 * Count number of orders by price
629 *
630 * @param string
631 *
632 * @return int
633 * @deprecated 4.2.6.9.3
634 */
635 /*function learn_press_get_courses_by_price( $fee ) {
636 global $wpdb;
637
638 $user_id = get_current_user_id();
639
640 $courses = $wpdb->get_var(
641 $wpdb->prepare(
642 "SELECT COUNT(*)
643 FROM $wpdb->posts AS p
644 INNER JOIN $wpdb->postmeta AS m ON p.ID = m.post_id
645 WHERE p.post_author = %d
646 AND p.post_type = %s
647 AND p.post_status IN (%s, %s)
648 AND m.meta_key = %s
649 AND m.meta_value = %s",
650 $user_id,
651 LP_COURSE_CPT,
652 'publish',
653 'pending',
654 '_lpr_course_payment',
655 $fee
656 )
657 );
658
659 return $courses;
660 }*/
661
662 /**
663 * Get data about students to render in chart
664 *
665 * @param null $from
666 * @param null $by
667 * @param float $time_ago
668 *
669 * @return array
670 * @deprecated 4.2.6.9.3
671 */
672 /*function learn_press_get_chart_students( $from = null, $by = null, $time_ago = 0 ) {
673 $labels = array();
674 $datasets = array();
675
676 if ( is_null( $from ) ) {
677 $from = current_time( 'mysql', 1 );
678 }
679
680 if ( is_null( $by ) ) {
681 $by = 'days';
682 }
683
684 switch ( $by ) {
685 case 'days':
686 $date_format = 'M d';
687 break;
688 case 'months':
689 $date_format = 'M Y';
690 break;
691 case 'years':
692 $date_format = 'Y';
693 break;
694 }
695
696 for ( $i = - $time_ago + 1; $i <= 0; $i ++ ) {
697 $labels[] = gmdate( $date_format, strtotime( "$i $by", strtotime( $from ) ) );
698 $datasets[0]['data'][] = learn_press_get_order_by_time( $by, strtotime( "$i $by", strtotime( $from ) ) );
699 }
700
701 $colors = learn_press_get_admin_colors();
702 $datasets[0]['fillColor'] = 'rgba(255,255,255,0.1)';
703 $datasets[0]['strokeColor'] = $colors[0];
704 $datasets[0]['pointColor'] = $colors[0];
705 $datasets[0]['pointStrokeColor'] = $colors[2];
706 $datasets[0]['pointHighlightFill'] = $colors[2];
707 $datasets[0]['pointHighlightStroke'] = $colors[0];
708
709 return array(
710 'labels' => $labels,
711 'datasets' => $datasets,
712 );
713 }*/
714
715 /**
716 * Get data about students to render in chart
717 *
718 * @param null $from
719 * @param null $by
720 * @param float $time_ago
721 *
722 * @return array
723 * @deprecated 4.2.6.9.3
724 */
725 /*function learn_press_get_chart_users( $from = null, $by = null, $time_ago = 0 ) {
726 global $wpdb;
727
728 $labels = array();
729 $datasets = array();
730
731 if ( is_null( $from ) ) {
732 $from = current_time( 'mysql', 1 );
733 }
734
735 if ( is_null( $by ) ) {
736 $by = 'days';
737 }
738
739 $results = array(
740 'all' => array(),
741 'instructors' => array(),
742 );
743
744 $from_time = is_numeric( $from ) ? $from : strtotime( $from );
745
746 switch ( $by ) {
747 case 'days':
748 $date_format = 'M d Y';
749 $_from = - $time_ago + 1;
750 $_from = gmdate( 'Y-m-d', strtotime( "{$_from} {$by}", $from_time ) );
751 $_to = date( 'Y-m-d', $from_time );
752 $_sql_format = '%Y-%m-%d';
753 $_key_format = 'Y-m-d';
754 break;
755 case 'months':
756 $date_format = 'M Y';
757 $_from = - $time_ago + 1;
758 $_from = date( 'Y-m-01', strtotime( "{$_from} {$by}", $from_time ) );
759 $days = date( 't', mktime( 0, 0, 0, date( 'm', $from_time ), 1, date( 'Y', $from_time ) ) );
760 $_to = date( 'Y-m-' . $days, $from_time );
761 $_sql_format = '%Y-%m';
762 $_key_format = 'Y-m';
763 break;
764 case 'years':
765 $date_format = 'Y';
766 $_from = - $time_ago + 1;
767 $_from = date( 'Y-01-01', strtotime( "{$_from} {$by}", $from_time ) );
768 $days = date( 't', mktime( 0, 0, 0, date( 'm', $from_time ), 1, date( 'Y', $from_time ) ) );
769 $_to = date( 'Y-12-' . $days, $from_time );
770 $_sql_format = '%Y';
771 $_key_format = 'Y';
772
773 break;
774 }
775 $query = $wpdb->prepare(
776 "
777 SELECT count(u.ID) as c, DATE_FORMAT( u.user_registered, %s) as d
778 FROM {$wpdb->users} u
779 WHERE 1
780 GROUP BY d
781 HAVING d BETWEEN %s AND %s
782 ORDER BY d ASC
783 ",
784 $_sql_format,
785 $_from,
786 $_to
787 );
788
789 if ( $_results = $wpdb->get_results( $query ) ) {
790 foreach ( $_results as $k => $v ) {
791 $results['all'][ $v->d ] = $v;
792 }
793 }
794
795 $query = $wpdb->prepare(
796 "
797 SELECT count(u.ID) as c, DATE_FORMAT( u.user_registered, %s) as d
798 FROM {$wpdb->users} u
799 INNER JOIN {$wpdb->usermeta} um ON um.user_id = u.ID AND um.meta_key = %s AND ( um.meta_value LIKE %s OR um.meta_value LIKE %s )
800 WHERE 1
801 GROUP BY d
802 HAVING d BETWEEN %s AND %s
803 ORDER BY d ASC
804 ",
805 $_sql_format,
806 'wp_capabilities',
807 '%' . $wpdb->esc_like( 's:13:"administrator"' ) . '%',
808 '%' . $wpdb->esc_like( 's:10:"lp_teacher"' ) . '%',
809 $_from,
810 $_to
811 );
812
813 if ( $_results = $wpdb->get_results( $query ) ) {
814 foreach ( $_results as $k => $v ) {
815 $results['instructors'][ $v->d ] = $v;
816 }
817 }
818
819 for ( $i = - $time_ago + 1; $i <= 0; $i ++ ) {
820 $date = strtotime( "$i $by", $from_time );
821 $labels[] = date( $date_format, $date );
822 $key = date( $_key_format, $date );
823
824 $all = ! empty( $results['all'][ $key ] ) ? $results['all'][ $key ]->c : 0;
825 $instructors = ! empty( $results['instructors'][ $key ] ) ? $results['instructors'][ $key ]->c : 0;
826
827 $datasets[0]['data'][] = $all;
828 $datasets[1]['data'][] = $instructors;
829 $datasets[2]['data'][] = $all - $instructors;
830 }
831
832 $dataset_params = array(
833 array(
834 'color1' => 'rgba(47, 167, 255, %s)',
835 'color2' => '#FFF',
836 'label' => __( 'All', 'learnpress' ),
837 ),
838 array(
839 'color1' => 'rgba(212, 208, 203, %s)',
840 'color2' => '#FFF',
841 'label' => __( 'Instructors', 'learnpress' ),
842 ),
843 array(
844 'color1' => 'rgba(234, 199, 155, %s)',
845 'color2' => '#FFF',
846 'label' => __( 'Students', 'learnpress' ),
847 ),
848 );
849
850 foreach ( $dataset_params as $k => $v ) {
851 $datasets[ $k ]['fillColor'] = sprintf( $v['color1'], '0.2' );
852 $datasets[ $k ]['strokeColor'] = sprintf( $v['color1'], '1' );
853 $datasets[ $k ]['pointColor'] = sprintf( $v['color1'], '1' );
854 $datasets[ $k ]['pointStrokeColor'] = $v['color2'];
855 $datasets[ $k ]['pointHighlightFill'] = $v['color2'];
856 $datasets[ $k ]['pointHighlightStroke'] = sprintf( $v['color1'], '1' );
857 $datasets[ $k ]['label'] = $v['label'];
858 }
859
860 return array(
861 'labels' => $labels,
862 'datasets' => $datasets,
863 'sql' => $query,
864 );
865 }*/
866
867
868 /**
869 * Get data about students to render in chart
870 *
871 * @param null $from
872 * @param null $by
873 * @param float $time_ago
874 *
875 * @return array
876 * @deprecated 4.2.6.9.3
877 */
878 /*function learn_press_get_chart_courses( $from = null, $by = null, $time_ago = 0 ) {
879 global $wpdb;
880
881 $labels = array();
882 $datasets = array();
883
884 if ( is_null( $from ) ) {
885 $from = current_time( 'mysql', 1 );
886 }
887
888 if ( is_null( $by ) ) {
889 $by = 'days';
890 }
891
892 $results = array(
893 'all' => array(),
894 'public' => array(),
895 'pending' => array(),
896 'free' => array(),
897 'paid' => array(),
898 );
899
900 $from_time = is_numeric( $from ) ? $from : strtotime( $from );
901
902 switch ( $by ) {
903 case 'days':
904 $date_format = 'M d Y';
905 $_from = - $time_ago + 1;
906 $_from = date( 'Y-m-d', strtotime( "{$_from} {$by}", $from_time ) );
907 $_to = date( 'Y-m-d', $from_time );
908 $_sql_format = '%Y-%m-%d';
909 $_key_format = 'Y-m-d';
910 break;
911 case 'months':
912 $date_format = 'M Y';
913 $_from = - $time_ago + 1;
914 $_from = date( 'Y-m-01', strtotime( "{$_from} {$by}", $from_time ) );
915 $days = date( 't', mktime( 0, 0, 0, date( 'm', $from_time ), 1, date( 'Y', $from_time ) ) );
916 $_to = date( 'Y-m-' . $days, $from_time );
917 $_sql_format = '%Y-%m';
918 $_key_format = 'Y-m';
919 break;
920 case 'years':
921 $date_format = 'Y';
922 $_from = - $time_ago + 1;
923 $_from = date( 'Y-01-01', strtotime( "{$_from} {$by}", $from_time ) );
924 $days = date( 't', mktime( 0, 0, 0, date( 'm', $from_time ), 1, date( 'Y', $from_time ) ) );
925 $_to = date( 'Y-12-' . $days, $from_time );
926 $_sql_format = '%Y';
927 $_key_format = 'Y';
928
929 break;
930 }
931
932 $query_where = '';
933
934 if ( current_user_can( LP_TEACHER_ROLE ) ) {
935 $user_id = learn_press_get_current_user_id();
936 $query_where .= $wpdb->prepare( ' AND c.post_author=%d ', $user_id );
937 }
938
939 $query = $wpdb->prepare(
940 "
941 SELECT count(c.ID) as c, DATE_FORMAT( c.post_date, %s) as d
942 FROM {$wpdb->posts} c
943 WHERE 1
944 {$query_where}
945 AND c.post_status IN('publish', 'pending') AND c.post_type = %s
946 GROUP BY d
947 HAVING d BETWEEN %s AND %s
948 ORDER BY d ASC
949 ",
950 $_sql_format,
951 'lp_course',
952 $_from,
953 $_to
954 );
955 if ( $_results = $wpdb->get_results( $query ) ) {
956 foreach ( $_results as $k => $v ) {
957 $results['all'][ $v->d ] = $v;
958 }
959 }
960 $query = $wpdb->prepare(
961 "
962 SELECT count(c.ID) as c, DATE_FORMAT( c.post_date, %s) as d
963 FROM {$wpdb->posts} c
964 WHERE 1
965 {$query_where}
966 AND c.post_status = %s AND c.post_type = %s
967 GROUP BY d
968 HAVING d BETWEEN %s AND %s
969 ORDER BY d ASC
970 ",
971 $_sql_format,
972 'publish',
973 'lp_course',
974 $_from,
975 $_to
976 );
977
978 $_results = $wpdb->get_results( $query );
979 if ( $_results ) {
980 foreach ( $_results as $k => $v ) {
981 $results['publish'][ $v->d ] = $v;
982 }
983 }
984
985 $query = $wpdb->prepare(
986 "
987 SELECT count(c.ID) as c, DATE_FORMAT( c.post_date, %s) as d
988 FROM {$wpdb->posts} c
989 INNER JOIN {$wpdb->postmeta} cm ON cm.post_id = c.ID
990 WHERE 1
991 {$query_where}
992 AND c.post_status = %s AND c.post_type = %s
993 GROUP BY d
994 HAVING d BETWEEN %s AND %s
995 ORDER BY d ASC
996 ",
997 $_sql_format,
998 'publish',
999 'lp_course',
1000 $_from,
1001 $_to
1002 );
1003
1004 $_results = $wpdb->get_results( $query );
1005 if ( $_results ) {
1006 foreach ( $_results as $k => $v ) {
1007 $results['paid'][ $v->d ] = $v;
1008 }
1009 }
1010
1011 for ( $i = - $time_ago + 1; $i <= 0; $i ++ ) {
1012 $date = strtotime( "$i $by", $from_time );
1013 $labels[] = date( $date_format, $date );
1014 $key = date( $_key_format, $date );
1015
1016 $all = ! empty( $results['all'][ $key ] ) ? $results['all'][ $key ]->c : 0;
1017 $publish = ! empty( $results['publish'][ $key ] ) ? $results['publish'][ $key ]->c : 0;
1018 $paid = ! empty( $results['paid'][ $key ] ) ? $results['paid'][ $key ]->c : 0;
1019
1020 $datasets[0]['data'][] = $all;
1021 $datasets[1]['data'][] = $publish;
1022 $datasets[2]['data'][] = $all - $publish;
1023 $datasets[3]['data'][] = $paid;
1024 $datasets[4]['data'][] = $all - $paid;
1025 }
1026
1027 $dataset_params = array(
1028 array(
1029 'color1' => 'rgba(47, 167, 255, %s)',
1030 'color2' => '#FFF',
1031 'label' => __( 'All', 'learnpress' ),
1032 ),
1033 array(
1034 'color1' => 'rgba(212, 208, 203, %s)',
1035 'color2' => '#FFF',
1036 'label' => __( 'Publish', 'learnpress' ),
1037 ),
1038 array(
1039 'color1' => 'rgba(234, 199, 155, %s)',
1040 'color2' => '#FFF',
1041 'label' => __( 'Pending', 'learnpress' ),
1042 ),
1043 array(
1044 'color1' => 'rgba(234, 199, 155, %s)',
1045 'color2' => '#FFF',
1046 'label' => __( 'Paid', 'learnpress' ),
1047 ),
1048 array(
1049 'color1' => 'rgba(234, 199, 155, %s)',
1050 'color2' => '#FFF',
1051 'label' => __( 'Free', 'learnpress' ),
1052 ),
1053 );
1054
1055 foreach ( $dataset_params as $k => $v ) {
1056 $datasets[ $k ]['fillColor'] = sprintf( $v['color1'], '0.2' );
1057 $datasets[ $k ]['strokeColor'] = sprintf( $v['color1'], '1' );
1058 $datasets[ $k ]['pointColor'] = sprintf( $v['color1'], '1' );
1059 $datasets[ $k ]['pointStrokeColor'] = $v['color2'];
1060 $datasets[ $k ]['pointHighlightFill'] = $v['color2'];
1061 $datasets[ $k ]['pointHighlightStroke'] = sprintf( $v['color1'], '1' );
1062 $datasets[ $k ]['label'] = $v['label'];
1063 }
1064
1065 return array(
1066 'labels' => $labels,
1067 'datasets' => $datasets,
1068 'sql' => $query,
1069 );
1070 }*/
1071
1072
1073 /**
1074 * Get data about students to render in chart
1075 *
1076 * @param null $from
1077 * @param null $by
1078 * @param float $time_ago
1079 *
1080 * @return array
1081 * @deprecated 4.2.6.9.3
1082 */
1083 /*function learn_press_get_chart_orders( $from = null, $by = null, $time_ago = 0 ) {
1084 global $wpdb;
1085 $sql_join = '';
1086
1087 $report_sales_by = learn_press_get_request( 'report_sales_by' );
1088 $course_id = learn_press_get_request( 'course_id' );
1089 $cat_id = learn_press_get_request( 'cat_id' );
1090
1091 $labels = array();
1092 $datasets = array();
1093 if ( is_null( $from ) ) {
1094 $from = current_time( 'mysql', 1 );
1095 }
1096 if ( is_null( $by ) ) {
1097 $by = 'days';
1098 }
1099 $results = array(
1100 'all' => array(),
1101 'completed' => array(),
1102 'pending' => array(),
1103 );
1104 $from_time = is_numeric( $from ) ? $from : strtotime( $from );
1105
1106 switch ( $by ) {
1107 case 'days':
1108 $date_format = 'M d Y';
1109 $_from = - $time_ago + 1;
1110 $_from = date( 'Y-m-d', strtotime( "{$_from} {$by}", $from_time ) );
1111 $_to = date( 'Y-m-d', $from_time );
1112 $_sql_format = '%Y-%m-%d';
1113 $_key_format = 'Y-m-d';
1114 break;
1115 case 'months':
1116 $date_format = 'M Y';
1117 $_from = - $time_ago + 1;
1118 $_from = date( 'Y-m-01', strtotime( "{$_from} {$by}", $from_time ) );
1119 $days = date( 't', mktime( 0, 0, 0, date( 'm', $from_time ), 1, date( 'Y', $from_time ) ) );
1120 $_to = date( 'Y-m-' . $days, $from_time );
1121 $_sql_format = '%Y-%m';
1122 $_key_format = 'Y-m';
1123 break;
1124 case 'years':
1125 $date_format = 'Y';
1126 $_from = - $time_ago + 1;
1127 $_from = date( 'Y-01-01', strtotime( "{$_from} {$by}", $from_time ) );
1128 $days = date( 't', mktime( 0, 0, 0, date( 'm', $from_time ), 1, date( 'Y', $from_time ) ) );
1129 $_to = date( 'Y-12-' . $days, $from_time );
1130 $_sql_format = '%Y';
1131 $_key_format = 'Y';
1132
1133 break;
1134 }
1135
1136 $query_join = '';
1137 $query_where = '';
1138 $sql_join = '';
1139 if ( 'course' === $report_sales_by ) {
1140 $sql_join .= " INNER JOIN `{$wpdb->prefix}learnpress_order_items` `lpoi` "
1141 . ' ON o.ID=lpoi.order_id '
1142 . " INNER JOIN {$wpdb->prefix}learnpress_order_itemmeta loim "
1143 . ' ON lpoi.order_item_id=loim.learnpress_order_item_id '
1144 . " AND loim.meta_key='_course_id' "
1145 . ' AND CAST(loim.meta_value AS SIGNED)=%d ';
1146 if ( current_user_can( LP_TEACHER_ROLE ) ) {
1147 $user_id = learn_press_get_current_user_id();
1148 $sql_join .= $wpdb->prepare(
1149 ' AND CAST(loim.meta_value AS SIGNED) IN '
1150 . ' ( '
1151 . " SELECT ID FROM {$wpdb->posts} p WHERE p.ID = CAST(loim.meta_value AS SIGNED) AND `post_author`=" . intval( $user_id )
1152 . ' ) '
1153 );
1154 }
1155 $query_join .= $wpdb->prepare( $sql_join, $course_id );
1156
1157 } elseif ( 'category' === $report_sales_by ) {
1158 $sql_join .= " INNER JOIN `{$wpdb->prefix}learnpress_order_items` `lpoi` "
1159 . ' ON o.ID=lpoi.order_id '
1160 . " INNER JOIN {$wpdb->prefix}learnpress_order_itemmeta loim "
1161 . ' ON lpoi.order_item_id=loim.learnpress_order_item_id '
1162 . " AND loim.meta_key='_course_id' "
1163 . ' AND CAST(loim.meta_value AS SIGNED) IN('
1164 // sub query
1165 . ' SELECT tr.object_id '
1166 . " FROM {$wpdb->prefix}term_taxonomy tt INNER JOIN {$wpdb->prefix}term_relationships tr "
1167 . " ON tt.term_taxonomy_id = tr.term_taxonomy_id AND tt.taxonomy='course_category' "
1168 . ' WHERE tt.term_id=%d)';
1169 $query_join .= $wpdb->prepare( $sql_join, $cat_id );
1170 }
1171 if ( current_user_can( LP_TEACHER_ROLE ) ) {
1172 $user_id = learn_press_get_current_user_id();
1173 $query_where .= $wpdb->prepare(
1174 " AND o.ID IN( SELECT oi.order_id
1175 FROM lptest.{$wpdb->prefix}learnpress_order_items oi
1176 inner join {$wpdb->prefix}learnpress_order_itemmeta oim
1177 on oi.order_item_id = oim.learnpress_order_item_id
1178 and oim.meta_key='_course_id'
1179 and cast(oim.meta_value as SIGNED) IN (
1180 SELECT sp.ID FROM {$wpdb->prefix}posts sp WHERE sp.post_author=%d and sp.ID=cast(oim.meta_value as SIGNED)
1181 )
1182 ) ",
1183 $user_id
1184 );
1185 }
1186
1187 $query = $wpdb->prepare(
1188 "
1189 SELECT count(o.ID) as c, DATE_FORMAT( o.post_date, %s) as d
1190 FROM {$wpdb->posts} o {$query_join}
1191 WHERE 1 {$query_where}
1192 AND o.post_status IN('lp-completed') AND o.post_type = %s
1193 GROUP BY d
1194 HAVING d BETWEEN %s AND %s
1195 ORDER BY d ASC
1196 ",
1197 $_sql_format,
1198 'lp_order',
1199 $_from,
1200 $_to
1201 );
1202
1203 if ( $_results = $wpdb->get_results( $query ) ) {
1204 foreach ( $_results as $k => $v ) {
1205 $results['completed'][ $v->d ] = $v;
1206 }
1207 }
1208
1209 $query = $wpdb->prepare(
1210 "
1211 SELECT count(o.ID) as c, DATE_FORMAT( o.post_date, %s) as d
1212 FROM {$wpdb->posts} o {$query_join}
1213 WHERE 1 {$query_where}
1214 AND o.post_status IN('lp-pending', 'lp-processing') AND o.post_type = %s
1215 GROUP BY d
1216 HAVING d BETWEEN %s AND %s
1217 ORDER BY d ASC
1218 ",
1219 $_sql_format,
1220 'lp_order',
1221 $_from,
1222 $_to
1223 );
1224
1225 if ( $_results = $wpdb->get_results( $query ) ) {
1226 foreach ( $_results as $k => $v ) {
1227 $results['pending'][ $v->d ] = $v;
1228 }
1229 }
1230
1231 for ( $i = - $time_ago + 1; $i <= 0; $i ++ ) {
1232 $date = strtotime( "$i $by", $from_time );
1233 $labels[] = date( $date_format, $date );
1234 $key = date( $_key_format, $date );
1235
1236 $completed = ! empty( $results['completed'][ $key ] ) ? $results['completed'][ $key ]->c : 0;
1237 $pending = ! empty( $results['pending'][ $key ] ) ? $results['pending'][ $key ]->c : 0;
1238 $all = $completed + $pending;
1239
1240 $datasets[0]['data'][] = $all;
1241 $datasets[1]['data'][] = $completed;
1242 $datasets[2]['data'][] = $pending;
1243 }
1244
1245 $dataset_params = array(
1246 array(
1247 'color1' => 'rgba(47, 167, 255, %s)',
1248 'color2' => '#FFF',
1249 'label' => __( 'All', 'learnpress' ),
1250 ),
1251 array(
1252 'color1' => 'rgba(212, 208, 203, %s)',
1253 'color2' => '#FFF',
1254 'label' => __( 'Completed', 'learnpress' ),
1255 ),
1256 array(
1257 'color1' => 'rgba(234, 199, 155, %s)',
1258 'color2' => '#FFF',
1259 'label' => __( 'Pending', 'learnpress' ),
1260 ),
1261 );
1262
1263 foreach ( $dataset_params as $k => $v ) {
1264 $datasets[ $k ]['fillColor'] = sprintf( $v['color1'], '0.2' );
1265 $datasets[ $k ]['strokeColor'] = sprintf( $v['color1'], '1' );
1266 $datasets[ $k ]['pointColor'] = sprintf( $v['color1'], '1' );
1267 $datasets[ $k ]['pointStrokeColor'] = $v['color2'];
1268 $datasets[ $k ]['pointHighlightFill'] = $v['color2'];
1269 $datasets[ $k ]['pointHighlightStroke'] = sprintf( $v['color1'], '1' );
1270 $datasets[ $k ]['label'] = $v['label'];
1271 }
1272
1273 return array(
1274 'labels' => $labels,
1275 'datasets' => $datasets,
1276 'sql' => $query,
1277 );
1278 }*/
1279
1280 /**
1281 * Get data about courses to render in the chart
1282 *
1283 * @return array
1284 * @deprecated 4.2.6.9.3
1285 */
1286 /*function learn_press_get_chart_courses2() {
1287 $labels = array(
1288 __( 'Pending Courses/Publish Courses', 'learnpress' ),
1289 __( 'Free Courses/Paid Courses', 'learnpress' ),
1290 );
1291
1292 $datasets = array();
1293 $datasets[0]['data'] = array(
1294 learn_press_get_courses_by_status( 'pending' ),
1295 learn_press_get_courses_by_price( 'free' ),
1296 );
1297
1298 $datasets[1]['data'] = array(
1299 learn_press_get_courses_by_status( 'publish' ),
1300 learn_press_get_courses_by_price( 'not_free' ),
1301 );
1302
1303 $colors = learn_press_get_admin_colors();
1304 $datasets[0]['fillColor'] = $colors[1];
1305 $datasets[0]['strokeColor'] = $colors[1];
1306 $datasets[1]['fillColor'] = $colors[3];
1307 $datasets[1]['strokeColor'] = $colors[3];
1308
1309 return array(
1310 'labels' => $labels,
1311 'datasets' => $datasets,
1312 );
1313 }*/
1314
1315 /**
1316 * Get colors setting up by admin user
1317 *
1318 * @return array
1319 */
1320 function learn_press_get_admin_colors() {
1321 $admin_color = get_user_meta( get_current_user_id(), 'admin_color', true );
1322 global $_wp_admin_css_colors;
1323 $colors = array();
1324
1325 if ( ! empty( $_wp_admin_css_colors[ $admin_color ]->colors ) ) {
1326 $colors = $_wp_admin_css_colors[ $admin_color ]->colors;
1327 }
1328
1329 if ( empty( $colors[0] ) ) {
1330 $colors[0] = '#000000';
1331 }
1332
1333 if ( empty( $colors[2] ) ) {
1334 $colors[2] = '#00FF00';
1335 }
1336
1337 return $colors;
1338 }
1339
1340 /**
1341 * Convert an array to json format and print out to browser
1342 *
1343 * @param array $chart
1344 */
1345 function learn_press_process_chart( $chart = array() ) {
1346 $data = json_encode(
1347 array(
1348 'labels' => $chart['labels'],
1349 'datasets' => $chart['datasets'],
1350 )
1351 );
1352 echo wp_kses_post( $data );
1353 }
1354
1355 /**
1356 * Print out the configuration for admin chart
1357 */
1358 function learn_press_config_chart() {
1359 $colors = learn_press_get_admin_colors();
1360
1361 $config = array(
1362 'scaleShowGridLines' => true,
1363 'scaleGridLineColor' => '#777',
1364 'scaleGridLineWidth' => 0.3,
1365 'scaleFontColor' => '#444',
1366 'scaleLineColor' => $colors[0],
1367 'bezierCurve' => true,
1368 'bezierCurveTension' => 0.2,
1369 'pointDotRadius' => 5,
1370 'pointDotStrokeWidth' => 5,
1371 'pointHitDetectionRadius' => 20,
1372 'datasetStroke' => true,
1373 'responsive' => true,
1374 'tooltipFillColor' => $colors[2],
1375 'tooltipFontColor' => '#eee',
1376 'tooltipCornerRadius' => 0,
1377 'tooltipYPadding' => 10,
1378 'tooltipXPadding' => 10,
1379 'barDatasetSpacing' => 10,
1380 'barValueSpacing' => 200,
1381
1382 );
1383
1384 echo json_encode( $config );
1385 }
1386
1387 function set_post_order_in_admin( $wp_query ) {
1388 global $pagenow;
1389
1390 if ( isset( $_GET['post_type'] ) ) {
1391 $post_type = LP_Helper::sanitize_params_submitted( $_GET['post_type'] );
1392 } else {
1393 $post_type = '';
1394 }
1395
1396 if ( is_admin() && 'edit.php' == $pagenow && $post_type == LP_COURSE_CPT && ! isset( $_GET['orderby'] ) ) {
1397 $wp_query->set( 'orderby', 'date' );
1398 $wp_query->set( 'order', 'DSC' );
1399 }
1400 }
1401
1402 // add_filter( 'pre_get_posts', 'set_post_order_in_admin' );
1403
1404 function learn_press_copy_post_meta( $from_id, $to_id ) {
1405 global $wpdb;
1406
1407 $course_meta = $wpdb->get_results(
1408 $wpdb->prepare( "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id = %d", $from_id )
1409 );
1410
1411 if ( count( $course_meta ) != 0 ) {
1412 $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
1413 $sql_query_sel = array();
1414
1415 foreach ( $course_meta as $meta ) {
1416 $meta_key = $meta->meta_key;
1417 $meta_value = addslashes( $meta->meta_value );
1418
1419 $sql_query_sel[] = "SELECT {$to_id}, '$meta_key', '$meta_value'";
1420 }
1421
1422 $sql_query .= implode( ' UNION ALL ', $sql_query_sel );
1423 $wpdb->query( $sql_query );
1424 }
1425 }
1426
1427 /**
1428 * Check to see if a plugin is already installed or not
1429 *
1430 * @param $plugin
1431 *
1432 * @return bool
1433 */
1434 function learn_press_is_plugin_install( $plugin ) {
1435 $installed_plugins = get_plugins();
1436
1437 return isset( $installed_plugins[ $plugin ] );
1438 }
1439
1440 /**
1441 * Get plugin file that contains the information from slug
1442 *
1443 * @param $slug
1444 *
1445 * @return mixed
1446 */
1447 function learn_press_plugin_basename_from_slug( $slug ) {
1448 $keys = array_keys( get_plugins() );
1449
1450 foreach ( $keys as $key ) {
1451 if ( preg_match( '|^' . $slug . '/|', $key ) ) {
1452 return $key;
1453 }
1454 }
1455
1456 return $slug;
1457 }
1458
1459 function _learn_press_reset_course_data() {
1460 if ( empty( $_REQUEST['reset-course-data'] ) ) {
1461 return false;
1462 }
1463
1464 learn_press_reset_course_data( intval( $_REQUEST['reset-course-data'] ) );
1465
1466 wp_redirect( esc_url_raw( remove_query_arg( 'reset-course-data' ) ) );
1467 }
1468
1469 add_action( 'init', '_learn_press_reset_course_data' );
1470
1471 function learn_press_admin_section_loop_item_class( $item, $section ) {
1472 $classes = array(
1473 'lp-section-item',
1474 );
1475
1476 $classes[] = 'lp-item-' . $item->post_type;
1477
1478 if ( ! absint( $item->ID ) ) {
1479 $classes[] = 'lp-item-empty lp-item-new focus';
1480 }
1481
1482 $classes = apply_filters( 'learn_press_section_loop_item_class', $classes, $item, $section );
1483
1484 if ( $classes ) {
1485 echo 'class="' . join( ' ', $classes ) . '"';
1486 }
1487
1488 return $classes;
1489 }
1490
1491 function learn_press_disable_checked_ontop( $args ) {
1492
1493 if ( 'course_category' == $args['taxonomy'] ) {
1494 $args['checked_ontop'] = false;
1495 }
1496
1497 return $args;
1498 }
1499
1500 add_filter( 'wp_terms_checklist_args', 'learn_press_disable_checked_ontop' );
1501
1502 function learn_press_get_screens() {
1503 $screen_id = sanitize_title( __( 'LearnPress', 'learnpress' ) );
1504
1505 $screens = array(
1506 'toplevel_page_' . $screen_id,
1507 $screen_id . '_page_learn-press-statistics',
1508 $screen_id . '_page_learn-press-addons',
1509 $screen_id . '_page_learn-press-settings',
1510 $screen_id . '_page_learn-press-tools',
1511 );
1512
1513 foreach ( array( LP_COURSE_CPT, LP_LESSON_CPT, LP_QUIZ_CPT, LP_QUESTION_CPT, LP_ORDER_CPT ) as $post_type ) {
1514 $screens[] = 'edit-' . $post_type;
1515 $screens[] = $post_type;
1516 }
1517
1518 return apply_filters( 'learn_press_screen_ids', $screens );
1519 }
1520
1521 function learn_press_is_post_type_screen( $post_type, $union = 'OR' ) {
1522 if ( is_array( $post_type ) ) {
1523 $return = null;
1524
1525 foreach ( $post_type as $_post_type ) {
1526 $check = learn_press_is_post_type_screen( $_post_type );
1527
1528 if ( $union == 'OR' && $check ) {
1529 return true;
1530 }
1531
1532 if ( $return == null ) {
1533 $return = $check;
1534 } else {
1535 $return = $return && $check;
1536 }
1537
1538 if ( $union !== 'OR' ) {
1539 return $return;
1540 }
1541 }
1542
1543 return $return;
1544 }
1545
1546 $screen = get_current_screen();
1547
1548 if ( ! $screen ) {
1549 return;
1550 }
1551
1552 $screen_id = $screen->id;
1553
1554 return in_array( $screen_id, array( $post_type, "edit-{$post_type}" ) );
1555 }
1556
1557 function learn_press_get_notice_dismiss( $context, $type = 'transient' ) {
1558 if ( $type == 'transient' ) {
1559 return get_transient( 'learn_press_dismiss_notice_' . $context );
1560 }
1561
1562 return get_option( 'learn_press_dismiss_notice_' . $context );
1563 }
1564
1565 if ( ! function_exists( 'learn_press_course_insert_section' ) ) {
1566 function learn_press_course_insert_section( $section = array() ) {
1567 global $wpdb;
1568
1569 $section = wp_parse_args(
1570 $section,
1571 array(
1572 'section_name' => '',
1573 'section_course_id' => 0,
1574 'section_order' => 0,
1575 'section_description' => '',
1576 )
1577 );
1578
1579 $section = stripslashes_deep( $section );
1580
1581 extract( $section );
1582
1583 $insert_data = compact( 'section_name', 'section_course_id', 'section_order', 'section_description' );
1584
1585 $wpdb->insert(
1586 $wpdb->learnpress_sections,
1587 $insert_data,
1588 array( '%s', '%d', '%d' )
1589 );
1590
1591 return $wpdb->insert_id;
1592 }
1593 }
1594
1595 if ( ! function_exists( 'learn_press_course_insert_section_item' ) ) {
1596 function learn_press_course_insert_section_item( $item_data = array() ) {
1597 global $wpdb;
1598
1599 $wpdb->insert(
1600 $wpdb->learnpress_section_items,
1601 array(
1602 'section_id' => $item_data['section_id'],
1603 'item_id' => $item_data['item_id'],
1604 'item_order' => $item_data['item_order'],
1605 'item_type' => $item_data['item_type'],
1606 ),
1607 array(
1608 '%d',
1609 '%d',
1610 '%d',
1611 '%s',
1612 )
1613 );
1614
1615 return $wpdb->insert_id;
1616 }
1617 }
1618
1619 if ( ! function_exists( 'learn_press_duplicate_post' ) ) {
1620 /**
1621 * Duplicate post.
1622 *
1623 * @param null $post_id
1624 * @param array $args
1625 * @param bool $meta
1626 *
1627 * @return bool|mixed
1628 * @since 3.0.0
1629 */
1630 function learn_press_duplicate_post( $post_id = null, $args = array(), $meta = true ) {
1631 $post = get_post( $post_id );
1632
1633 if ( ! $post ) {
1634 return false;
1635 }
1636
1637 $default = array(
1638 'comment_status' => $post->comment_status,
1639 'ping_status' => $post->ping_status,
1640 'post_author' => get_current_user_id(),
1641 'post_content' => $post->post_content,
1642 'post_excerpt' => $post->post_excerpt,
1643 'post_parent' => $post->post_parent,
1644 'post_password' => $post->post_password,
1645 'post_status' => 'draft',
1646 'post_title' => sprintf(
1647 '%1$s (%2$s)',
1648 $post->post_title,
1649 _x( 'Copy', 'Duplicate item title suffix', 'learnpress' )
1650 ),
1651 'post_type' => $post->post_type,
1652 'to_ping' => $post->to_ping,
1653 'menu_order' => $post->menu_order,
1654 'exclude_meta' => array(),
1655 );
1656
1657 $args = wp_parse_args( $args, $default );
1658 $exclude_meta = array();
1659
1660 if ( ! empty( $args['exclude_meta'] ) ) {
1661 $exclude_meta = $args['exclude_meta'];
1662 unset( $args['exclude_meta'] );
1663 }
1664
1665 $new_post_id = wp_insert_post( $args );
1666
1667 if ( ! is_wp_error( $new_post_id ) && $meta ) {
1668 learn_press_duplicate_post_meta( $post_id, $new_post_id, $exclude_meta );
1669
1670 $taxonomies = get_object_taxonomies( $post->post_type );
1671
1672 foreach ( $taxonomies as $taxonomy ) {
1673 $post_terms = wp_get_object_terms( $post_id, $taxonomy, array( 'fields' => 'slugs' ) );
1674 wp_set_object_terms( $new_post_id, $post_terms, $taxonomy, false );
1675 }
1676 }
1677
1678 return apply_filters( 'learn_press_duplicate_post', $new_post_id, $post_id );
1679 }
1680 }
1681
1682 /**
1683 * Duplicate post meta.
1684 *
1685 * @editor tungnx
1686 * @sicne 3.0.0
1687 * @version 4.0.1
1688 */
1689 if ( ! function_exists( 'learn_press_duplicate_post_meta' ) ) {
1690 function learn_press_duplicate_post_meta( $old_post_id, $new_post_id, $excerpt = array() ) {
1691 $lp_db = LP_Database::getInstance();
1692
1693 try {
1694 $excerpt = array_merge( array( '_edit_lock', '_edit_last' ), $excerpt );
1695 $excerpt_name_keys = implode( "','", $excerpt );
1696 $sql_query = $lp_db->wpdb->prepare(
1697 "INSERT INTO $lp_db->tb_postmeta (post_id, meta_key, meta_value)
1698 SELECT %d, pmc.meta_key, pmc.meta_value
1699 FROM $lp_db->tb_postmeta AS pmc
1700 WHERE post_id = %d
1701 AND meta_key not in ('{$excerpt_name_keys}')
1702 ",
1703 $new_post_id,
1704 $old_post_id
1705 );
1706
1707 $lp_db->check_execute_has_error();
1708
1709 $lp_db->wpdb->query( $sql_query );
1710 } catch ( Throwable $e ) {
1711 error_log( $e->getMessage() );
1712 }
1713 }
1714 }
1715
1716 if ( ! function_exists( 'learn_press_sort_questions' ) ) {
1717 function learn_press_sort_questions( $types ) {
1718 $user_id = get_current_user_id();
1719 $question_types = get_user_meta( $user_id, '_learn_press_memorize_question_types', true );
1720
1721 if ( ! empty( $question_types ) ) {
1722 $sort = array();
1723 arsort( $types );
1724 $new_types = array();
1725 $ktypes = array_keys( $types );
1726
1727 for ( $i = 0; $i < count( $ktypes ) - 1; $i ++ ) {
1728 $max = $i;
1729
1730 if ( ! isset( $question_types[ $ktypes[ $i ] ] ) ) {
1731 $question_types[ $ktypes[ $i ] ] = 0;
1732 }
1733
1734 for ( $j = $i + 1; $j < count( $ktypes ); $j ++ ) {
1735 if ( isset( $question_types[ $ktypes[ $j ] ], $question_types[ $ktypes[ $max ] ] )
1736 && $question_types[ $ktypes[ $j ] ] > $question_types[ $ktypes[ $max ] ]
1737 ) {
1738 $max = $j;
1739 }
1740 }
1741
1742 $tmp = $ktypes[ $i ];
1743 $ktypes[ $i ] = $ktypes[ $max ];
1744 $ktypes[ $max ] = $tmp;
1745 }
1746
1747 $ktypes = array_flip( $ktypes );
1748 $types = array_merge( $ktypes, $types );
1749 }
1750
1751 return $types;
1752 }
1753 }
1754
1755 if ( ! function_exists( 'learn_press_duplicate_question' ) ) {
1756 function learn_press_duplicate_question( $question_id = null, $quiz_id = null, $args = array() ) {
1757 if ( ! $question_id || ! get_post( $question_id ) ) {
1758 return new WP_Error( sprintf( __( 'Question id %s does not exist.', 'learnpress' ), $question_id ) );
1759 }
1760
1761 if ( $quiz_id && ! get_post( $quiz_id ) ) {
1762 return new WP_Error( sprintf( __( 'Quiz id %s does not exist.', 'learnpress' ), $quiz_id ) );
1763 }
1764
1765 global $wpdb;
1766 $new_question_id = learn_press_duplicate_post( $question_id, $args );
1767
1768 if ( $quiz_id ) {
1769 $sql = $wpdb->prepare(
1770 "
1771 SELECT * FROM $wpdb->learnpress_quiz_questions WHERE quiz_id = %d AND question_id = %d
1772 ",
1773 $quiz_id,
1774 $question_id
1775 );
1776
1777 $quiz_question_data = $wpdb->get_row( $sql );
1778 $max_order = $wpdb->get_var(
1779 $wpdb->prepare(
1780 "SELECT max(question_order) FROM {$wpdb->prefix}learnpress_quiz_questions WHERE quiz_id = %d",
1781 $quiz_id
1782 )
1783 );
1784
1785 if ( $quiz_question_data ) {
1786 $wpdb->insert(
1787 $wpdb->learnpress_quiz_questions,
1788 array(
1789 'quiz_id' => $quiz_id,
1790 'question_id' => $new_question_id,
1791 'question_order' => $max_order + 1,
1792 'params' => $quiz_question_data->params,
1793 ),
1794 array(
1795 '%d',
1796 '%d',
1797 '%d',
1798 '%s',
1799 )
1800 );
1801 }
1802 }
1803
1804 $sql = $wpdb->prepare(
1805 "
1806 SELECT * FROM $wpdb->learnpress_question_answers WHERE question_id = %d
1807 ",
1808 $question_id
1809 );
1810
1811 $question_answers = $wpdb->get_results( $sql );
1812
1813 if ( $question_answers ) {
1814 foreach ( $question_answers as $q_a ) {
1815 $wpdb->insert(
1816 $wpdb->learnpress_question_answers,
1817 array(
1818 'question_id' => $new_question_id,
1819 'title' => $q_a->title,
1820 'value' => $q_a->value,
1821 'is_true' => $q_a->is_true,
1822 'order' => $q_a->order,
1823 ),
1824 array(
1825 '%d',
1826 '%s',
1827 '%s',
1828 )
1829 );
1830 }
1831 }
1832
1833 return $new_question_id;
1834 }
1835 }
1836
1837 if ( ! function_exists( 'learn_press_duplicate_quiz' ) ) {
1838
1839 function learn_press_duplicate_quiz( $quiz_id = null, $args = array() ) {
1840 global $wpdb;
1841
1842 $new_quiz_id = learn_press_duplicate_post( $quiz_id, $args, true );
1843 $quiz = LP_Quiz::get_quiz( $quiz_id );
1844 if ( ! $quiz ) {
1845 return 0;
1846 }
1847
1848 $questions = $quiz->get_question_ids();
1849
1850 if ( $questions ) {
1851 foreach ( $questions as $question_id ) {
1852 $new_question_id = learn_press_duplicate_post( $question_id );
1853
1854 $sql = $wpdb->prepare(
1855 "
1856 SELECT * FROM $wpdb->learnpress_quiz_questions WHERE quiz_id = %d AND question_id = %d
1857 ",
1858 $quiz_id,
1859 $question_id
1860 );
1861
1862 $quiz_question_data = $wpdb->get_row( $sql );
1863
1864 if ( $quiz_question_data ) {
1865 $wpdb->insert(
1866 $wpdb->learnpress_quiz_questions,
1867 array(
1868 'quiz_id' => $new_quiz_id,
1869 'question_id' => $new_question_id,
1870 'question_order' => $quiz_question_data->question_order,
1871 'params' => $quiz_question_data->params,
1872 ),
1873 array(
1874 '%d',
1875 '%d',
1876 '%d',
1877 '%s',
1878 )
1879 );
1880 }
1881
1882 $sql = $wpdb->prepare(
1883 "
1884 SELECT * FROM $wpdb->learnpress_question_answers WHERE question_id = %d
1885 ",
1886 $question_id
1887 );
1888
1889 $question_answers = $wpdb->get_results( $sql );
1890 if ( $question_answers ) {
1891 foreach ( $question_answers as $q_a ) {
1892 $wpdb->insert(
1893 $wpdb->learnpress_question_answers,
1894 array(
1895 'question_id' => $new_question_id,
1896 'title' => $q_a->title,
1897 'value' => $q_a->value,
1898 'is_true' => $q_a->is_true,
1899 'order' => $q_a->order,
1900 ),
1901 array(
1902 '%d',
1903 '%s',
1904 '%s',
1905 )
1906 );
1907 }
1908 }
1909 }
1910 }
1911
1912 return $new_quiz_id;
1913 }
1914 }
1915
1916 /**
1917 * Get general data to render in chart
1918 *
1919 * @param null $from
1920 * @param null $by
1921 * @param float $time_ago
1922 *
1923 * @return array
1924 */
1925 function learn_press_get_chart_general( $from = null, $by = null, $time_ago = 0 ) {
1926 global $wpdb;
1927
1928 $labels = array();
1929 $datasets = array();
1930
1931 if ( is_null( $from ) ) {
1932 $from = current_time( 'mysql', 1 );
1933 }
1934
1935 if ( is_null( $by ) ) {
1936 $by = 'days';
1937 }
1938
1939 $results = array(
1940 'all' => array(),
1941 'public' => array(),
1942 'pending' => array(),
1943 'free' => array(),
1944 'paid' => array(),
1945 );
1946
1947 $results = array(
1948 'course' => array(),
1949 'lesson' => array(),
1950 'quiz' => array(),
1951 'student' => array(),
1952 'teacher' => array(),
1953 'revenue' => array(),
1954 );
1955
1956 $from_time = is_numeric( $from ) ? $from : strtotime( $from );
1957 $_from = '';
1958 $_to = '';
1959 $_sql_format = '';
1960 $date_format = '';
1961
1962 switch ( $by ) {
1963 case 'days':
1964 $date_format = 'M d Y';
1965 $_from = - $time_ago + 1;
1966 $_from = date( 'Y-m-d', strtotime( "{$_from} {$by}", $from_time ) );
1967 $_to = date( 'Y-m-d', $from_time );
1968 $_sql_format = '%Y-%m-%d';
1969 $_key_format = 'Y-m-d';
1970 break;
1971
1972 case 'months':
1973 $date_format = 'M Y';
1974 $_from = - $time_ago + 1;
1975 $_from = date( 'Y-m-01', strtotime( "{$_from} {$by}", $from_time ) );
1976 $days = date( 't', mktime( 0, 0, 0, date( 'm', $from_time ), 1, date( 'Y', $from_time ) ) );
1977 $_to = date( 'Y-m-' . $days, $from_time );
1978 $_sql_format = '%Y-%m';
1979 $_key_format = 'Y-m';
1980 break;
1981
1982 case 'years':
1983 $date_format = 'Y';
1984 $_from = - $time_ago + 1;
1985 $_from = date( 'Y-01-01', strtotime( "{$_from} {$by}", $from_time ) );
1986 $days = date( 't', mktime( 0, 0, 0, date( 'm', $from_time ), 1, date( 'Y', $from_time ) ) );
1987 $_to = date( 'Y-12-' . $days, $from_time );
1988 $_sql_format = '%Y';
1989 $_key_format = 'Y';
1990 break;
1991
1992 }
1993
1994 $query_where = '';
1995 if ( current_user_can( LP_TEACHER_ROLE ) ) {
1996 $user_id = learn_press_get_current_user_id();
1997 $query_where .= $wpdb->prepare( ' AND c.post_author=%d ', $user_id );
1998 }
1999
2000 $query = $wpdb->prepare(
2001 "
2002 SELECT count(c.ID) as c, DATE_FORMAT( c.post_date, %s) as d
2003 FROM {$wpdb->posts} c
2004 WHERE 1
2005 {$query_where}
2006 AND c.post_status IN('publish', 'pending') AND c.post_type = %s
2007 GROUP BY d
2008 HAVING d BETWEEN %s AND %s
2009 ORDER BY d ASC
2010 ",
2011 $_sql_format,
2012 'lp_course',
2013 $_from,
2014 $_to
2015 );
2016
2017 if ( $_results = $wpdb->get_results( $query ) ) {
2018 foreach ( $_results as $k => $v ) {
2019 $results['all'][ $v->d ] = $v;
2020 }
2021 }
2022
2023 $query = $wpdb->prepare(
2024 "
2025 SELECT count(c.ID) as c, DATE_FORMAT( c.post_date, %s) as d
2026 FROM {$wpdb->posts} c
2027 WHERE 1
2028 {$query_where}
2029 AND c.post_status = %s AND c.post_type = %s
2030 GROUP BY d
2031 HAVING d BETWEEN %s AND %s
2032 ORDER BY d ASC
2033 ",
2034 $_sql_format,
2035 'publish',
2036 'lp_course',
2037 $_from,
2038 $_to
2039 );
2040
2041 if ( $_results = $wpdb->get_results( $query ) ) {
2042 foreach ( $_results as $k => $v ) {
2043 $results['publish'][ $v->d ] = $v;
2044 }
2045 }
2046
2047 $query = $wpdb->prepare(
2048 "
2049 SELECT count(c.ID) as c, DATE_FORMAT( c.post_date, %s) as d
2050 FROM {$wpdb->posts} c
2051 INNER JOIN {$wpdb->postmeta} cm ON cm.post_id = c.ID
2052 WHERE 1
2053 {$query_where}
2054 AND c.post_status = %s AND c.post_type = %s
2055 GROUP BY d
2056 HAVING d BETWEEN %s AND %s
2057 ORDER BY d ASC
2058 ",
2059 $_sql_format,
2060 'publish',
2061 'lp_course',
2062 $_from,
2063 $_to
2064 );
2065
2066 if ( $_results = $wpdb->get_results( $query ) ) {
2067 foreach ( $_results as $k => $v ) {
2068 $results['paid'][ $v->d ] = $v;
2069 }
2070 }
2071
2072 for ( $i = - $time_ago + 1; $i <= 0; $i ++ ) {
2073 $date = strtotime( "$i $by", $from_time );
2074 $labels[] = date( $date_format, $date );
2075 $key = date( $_key_format, $date );
2076
2077 $all = ! empty( $results['all'][ $key ] ) ? $results['all'][ $key ]->c : 0;
2078 $publish = ! empty( $results['publish'][ $key ] ) ? $results['publish'][ $key ]->c : 0;
2079 $paid = ! empty( $results['paid'][ $key ] ) ? $results['paid'][ $key ]->c : 0;
2080
2081 $datasets[0]['data'][] = $all;
2082 $datasets[1]['data'][] = $publish;
2083 $datasets[2]['data'][] = $all - $publish;
2084 $datasets[3]['data'][] = $paid;
2085 $datasets[4]['data'][] = $all - $paid;
2086 }
2087
2088 $dataset_params = array(
2089 array(
2090 'color1' => 'rgba(47, 167, 255, %s)',
2091 'color2' => '#FFF',
2092 'label' => __( 'All', 'learnpress' ),
2093 ),
2094 array(
2095 'color1' => 'rgba(212, 208, 203, %s)',
2096 'color2' => '#FFF',
2097 'label' => __( 'Publish', 'learnpress' ),
2098 ),
2099 array(
2100 'color1' => 'rgba(234, 199, 155, %s)',
2101 'color2' => '#FFF',
2102 'label' => __( 'Pending', 'learnpress' ),
2103 ),
2104 array(
2105 'color1' => 'rgba(234, 199, 155, %s)',
2106 'color2' => '#FFF',
2107 'label' => __( 'Paid', 'learnpress' ),
2108 ),
2109 array(
2110 'color1' => 'rgba(234, 199, 155, %s)',
2111 'color2' => '#FFF',
2112 'label' => __( 'Free', 'learnpress' ),
2113 ),
2114 );
2115
2116 foreach ( $dataset_params as $k => $v ) {
2117 $datasets[ $k ]['fillColor'] = sprintf( $v['color1'], '0.2' );
2118 $datasets[ $k ]['strokeColor'] = sprintf( $v['color1'], '1' );
2119 $datasets[ $k ]['pointColor'] = sprintf( $v['color1'], '1' );
2120 $datasets[ $k ]['pointStrokeColor'] = $v['color2'];
2121 $datasets[ $k ]['pointHighlightFill'] = $v['color2'];
2122 $datasets[ $k ]['pointHighlightStroke'] = sprintf( $v['color1'], '1' );
2123 $datasets[ $k ]['label'] = $v['label'];
2124 }
2125
2126 return array(
2127 'labels' => $labels,
2128 'datasets' => $datasets,
2129 'sql' => $query,
2130 );
2131 }
2132
2133 function learn_press_get_default_section( $section = null ) {
2134 if ( ! $section ) {
2135 $section = new stdClass();
2136 }
2137 foreach (
2138 array(
2139 'section_id' => null,
2140 'section_name' => '',
2141 'section_course_id' => null,
2142 'section_order' => null,
2143 'section_description' => '',
2144 ) as $k => $v
2145 ) {
2146 if ( ! property_exists( $section, $k ) ) {
2147 $section->{$k} = $v;
2148 }
2149 }
2150
2151 return $section;
2152 }
2153
2154 /**
2155 * Display time fields for a post in editing mode.
2156 *
2157 * @param int $edit
2158 * @param int $for_post
2159 * @param int $tab_index
2160 * @param int $multi
2161 */
2162 function learn_press_touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) {
2163 global $wp_locale;
2164 $post = get_post();
2165
2166 if ( $for_post ) {
2167 $edit = ! ( in_array(
2168 $post->post_status,
2169 array(
2170 'draft',
2171 'pending',
2172 )
2173 ) && ( ! $post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) );
2174 }
2175
2176 $tab_index_attribute = '';
2177 if ( (int) $tab_index > 0 ) {
2178 $tab_index_attribute = " tabindex=\"$tab_index\"";
2179 }
2180
2181 $time_adj = current_time( 'timestamp' );
2182 $post_date = ( $for_post ) ? $post->post_date : get_comment()->comment_date;
2183 $jj = ( $edit ) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj );
2184 $mm = ( $edit ) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj );
2185 $aa = ( $edit ) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj );
2186 $hh = ( $edit ) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj );
2187 $mn = ( $edit ) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj );
2188 $ss = ( $edit ) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj );
2189
2190 $cur_jj = gmdate( 'd', $time_adj );
2191 $cur_mm = gmdate( 'm', $time_adj );
2192 $cur_aa = gmdate( 'Y', $time_adj );
2193 $cur_hh = gmdate( 'H', $time_adj );
2194 $cur_mn = gmdate( 'i', $time_adj );
2195
2196 $map = array(
2197 'mm' => array( $mm, $cur_mm ),
2198 'jj' => array( $jj, $cur_jj ),
2199 'aa' => array( $aa, $cur_aa ),
2200 'hh' => array( $hh, $cur_hh ),
2201 'mn' => array( $mn, $cur_mn ),
2202 );
2203
2204 foreach ( $map as $timeunit => $value ) {
2205 list( $unit, $curr ) = $value;
2206
2207 echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $unit . '" />' . "\n";
2208 $cur_timeunit = 'cur_' . $timeunit;
2209 echo '<input type="hidden" id="' . $cur_timeunit . '" name="' . $cur_timeunit . '" value="' . $curr . '" />' . "\n";
2210 }
2211 }
2212
2213 /**
2214 * Return id of current screen.
2215 *
2216 * @return bool|string
2217 * @since 3.2.6
2218 */
2219 function learn_press_get_screen_id() {
2220 _deprecated_function( __METHOD__, '4.2.3.6' );
2221 $screen = get_current_screen();
2222 $screen_id = $screen ? $screen->id : false;
2223
2224 return $screen_id;
2225 }
2226
2227 require_once 'class-lp-post-type-actions.php';
2228