PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.3.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.3.9
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 / abstracts / abstract-shortcode-courses.php

abstract-shortcode-courses.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.3.9, at inc/abstracts/abstract-shortcode-courses.php

145 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Abstract Shortcode Courses.
4 *
5 * @author ThimPress
6 * @category Abstract
7 * @package Learnpress/Classes
8 * @version 3.0.0
9 * @extends LP_Abstract_Shortcode
10 */
11
12 defined( 'ABSPATH' ) || exit();
13
14 if ( ! class_exists( 'LP_Abstract_Shortcode_Courses' ) ) {
15
16 /**
17 * Class LP_Abstract_Shortcode
18 *
19 * Abstract class for shortcodes
20 *
21 * @since 3.0.0
22 */
23 abstract class LP_Abstract_Shortcode_Courses extends LP_Abstract_Shortcode {
24
25 /**
26 * @var null
27 */
28 protected $curd = null;
29
30 /**
31 * @var null
32 */
33 protected $courses = null;
34
35 /**
36 * @var WP_Query
37 */
38 protected $_query = null;
39
40 /**
41 * LP_Abstract_Shortcode_Courses constructor.
42 *
43 * @param mixed $atts
44 */
45 public function __construct( $atts = '' ) {
46 parent::__construct( $atts );
47
48 // course curd
49 $this->curd = new LP_Course_CURD();
50
51 // shortcode atts
52 $this->_atts = wp_parse_args( $this->_atts, $this->get_atts() );
53 }
54
55 /**
56 * Query course
57 *
58 * @return mixed
59 */
60 abstract function query_courses();
61
62 /**
63 * Get shortcode atts.
64 *
65 * @return array
66 * @editor tungnx
67 */
68 public function get_atts() {
69 $atts = parent::get_atts();
70
71 $atts = wp_parse_args(
72 $atts,
73 array(
74 'limit' => 5,
75 'order_by' => 'post_date',
76 'order' => 'DESC',
77 )
78 );
79
80 $order_by = $atts['order_by'];
81 $order = $atts['order'];
82
83 $arr_orders_by = array( 'post_date', 'post_title', 'post_status', 'comment_count' );
84 if ( ! in_array( $order_by, $arr_orders_by ) || ! in_array( 'post_' . $order_by, $arr_orders_by ) ) {
85 $atts['order_by'] = 'post_date';
86 } else {
87 if ( $order_by !== 'comment_count' ) {
88 $atts['order_by'] = 'post_' . $order_by;
89 }
90 }
91
92 $arr_orders = array( 'DESC', 'ASC' );
93 $order = strtoupper( $order );
94
95 if ( ! in_array( $order, $arr_orders ) ) {
96 $atts['order'] = 'DESC';
97 }
98
99 return $atts;
100 }
101
102 /**
103 * Output shortcode.
104 */
105 public function output() {
106 ob_start();
107
108 $this->query_courses();
109 $this->output_courses();
110
111 return ob_get_clean();
112 }
113
114 /**
115 * Loop course.
116 * @editor tungnx
117 */
118 public function output_courses() {
119 $attrs = $this->get_atts();
120
121 wp_enqueue_style( 'learnpress' );
122 //wp_enqueue_script( 'lp-courses' );
123
124 $post_ids = $this->_query;
125
126 if ( ! $post_ids ) {
127 $post_ids = array();
128 }
129
130 $query = new LP_Query_Course( array( 'post__in' => $post_ids ) );
131 $args = $query->get_wp_query_vars();
132
133 $query = new WP_Query( $args );
134
135 $args_template = array( 'query' => $query );
136
137 if ( ! empty( $attrs['title'] ) ) {
138 $args_template['title'] = $attrs['title'];
139 }
140
141 learn_press_get_template( 'shortcode/list-courses', $args_template );
142 }
143 }
144 }
145