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.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / classes / Course_Widget.php
tutor / classes Last commit date
Addons.php 1 year ago Admin.php 1 year ago Ajax.php 1 year ago Announcements.php 1 year ago Assets.php 1 year ago Backend_Page_Trait.php 1 year ago BaseController.php 1 year ago Course.php 1 year ago Course_Embed.php 3 years ago Course_Filter.php 1 year ago Course_List.php 1 year ago Course_Settings_Tabs.php 1 year ago Course_Widget.php 1 year ago Custom_Validation.php 3 years ago Dashboard.php 1 year ago Earnings.php 1 year ago FormHandler.php 2 years ago Frontend.php 1 year ago Gutenberg.php 1 year ago Input.php 1 year ago Instructor.php 1 year ago Instructors_List.php 1 year ago Lesson.php 1 year ago Options_V2.php 1 year ago Permalink.php 2 years ago Post_types.php 1 year ago Private_Course_Access.php 1 year ago Q_And_A.php 1 year ago Question_Answers_List.php 3 years ago Quiz.php 1 year ago QuizBuilder.php 1 year ago Quiz_Attempts_List.php 1 year ago RestAPI.php 2 years ago Reviews.php 3 years ago Rewrite_Rules.php 2 years ago Shortcode.php 1 year ago Singleton.php 1 year ago Student.php 1 year ago Students_List.php 3 years ago Taxonomies.php 3 years ago Template.php 1 year ago Theme_Compatibility.php 3 years ago Tools.php 1 year ago Tools_V2.php 1 year ago Tutor.php 1 year ago TutorEDD.php 1 year ago Tutor_Base.php 2 years ago Tutor_Setup.php 1 year ago Upgrader.php 1 year ago User.php 1 year ago Utils.php 1 year ago Video_Stream.php 3 years ago WhatsNew.php 2 years ago Withdraw.php 1 year ago Withdraw_Requests_List.php 1 year ago WooCommerce.php 1 year ago
Course_Widget.php
246 lines
1 <?php
2 /**
3 * Course Widget Register
4 *
5 * @package Tutor
6 * @author Themeum <support@themeum.com>
7 * @link https://themeum.com
8 * @since 1.3.1
9 */
10
11 namespace TUTOR;
12
13 use Tutor\Models\CourseModel;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 /**
20 * Course Widget Class
21 *
22 * @since 1.3.1
23 */
24 class Course_Widget extends \WP_Widget {
25
26 /**
27 * Constructor
28 *
29 * @since 1.3.1
30 * @return void
31 */
32 public function __construct() {
33 parent::__construct(
34 'tutor_course_widget', // Base ID.
35 esc_html__( 'Tutor Course', 'tutor' ), // Name.
36 array( 'description' => esc_html__( 'Display courses wherever widget support is available.', 'tutor' ) ) // Args.
37 );
38 }
39
40 /**
41 * Front-end display of widget.
42 *
43 * @since 1.3.1
44 * @see WP_Widget::widget()
45 *
46 * @param array $args Widget arguments.
47 * @param array $instance Saved values from database.
48 *
49 * @return void
50 */
51 public function widget( $args, $instance ) {
52 echo wp_kses(
53 $args['before_widget'],
54 array(
55 'section' => array(
56 'id' => true,
57 'class' => true,
58 ),
59 'div' => array(
60 'id' => true,
61 'class' => true,
62 ),
63 )
64 );
65 if ( ! empty( $instance['title'] ) ) {
66 echo wp_kses( $args['before_title'], array( 'h2' => array( 'class' => true ) ) );
67 echo esc_html( apply_filters( 'widget_title', $instance['title'] ) );
68 echo wp_kses( $args['after_title'], array( 'h2' => array() ) );
69 }
70
71 $course_post_type = tutor()->course_post_type;
72
73 $form_args = $instance;
74 unset( $form_args['title'] );
75
76 $default_args = array(
77 'post_type' => $course_post_type,
78 'post_status' => 'publish',
79
80 'id' => '',
81 'exclude_ids' => '',
82 'category' => '',
83
84 'orderby' => 'ID',
85 'order' => 'DESC',
86 'count' => '6',
87 );
88
89 $a = array_merge( $default_args, $form_args );
90
91 if ( ! empty( $a['id'] ) ) {
92 $ids = (array) explode( ',', $a['id'] );
93 $a['post__in'] = $ids;
94 }
95
96 if ( ! empty( $a['exclude_ids'] ) ) {
97 $exclude_ids = (array) explode( ',', $a['exclude_ids'] );
98 $a['post__not_in'] = $exclude_ids;
99 }
100 if ( ! empty( $a['category'] ) ) {
101 $category = (array) explode( ',', $a['category'] );
102
103 $a['tax_query'] = array(
104 array(
105 'taxonomy' => CourseModel::COURSE_CATEGORY,
106 'field' => 'term_id',
107 'terms' => $category,
108 'operator' => 'IN',
109 ),
110 );
111 }
112 $a['posts_per_page'] = (int) $a['count'];
113
114 wp_reset_query();
115 query_posts( $a );
116 ob_start();
117 tutor_load_template( 'widget.courses' );
118 $output = ob_get_clean();
119 wp_reset_query();
120
121 echo wp_kses_post( $output );
122
123 echo wp_kses(
124 $args['after_widget'],
125 array(
126 'section' => array(),
127 'div' => array(),
128 )
129 );
130 }
131
132 /**
133 * Back-end widget form.
134 *
135 * @since 1.3.1
136 * @see WP_Widget::form()
137 *
138 * @param array $instance Previously saved values from database.
139 * @return void
140 */
141 public function form( $instance ) {
142 $title = ! empty( $instance['title'] ) ? $instance['title'] : esc_html__( 'New title', 'tutor' );
143 $id = ! empty( $instance['id'] ) ? $instance['id'] : '';
144 $exclude_ids = ! empty( $instance['exclude_ids'] ) ? $instance['exclude_ids'] : '';
145 $category = ! empty( $instance['category'] ) ? $instance['category'] : '';
146 $orderby = ! empty( $instance['orderby'] ) ? $instance['orderby'] : '';
147 $order = ! empty( $instance['order'] ) ? $instance['order'] : '';
148 $count = ! empty( $instance['count'] ) ? $instance['count'] : '6';
149 ?>
150 <p>
151 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
152 <?php esc_html_e( 'Title', 'tutor' ); ?>:
153 </label>
154 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
155 </p>
156
157 <p>
158 <label for="<?php echo esc_attr( $this->get_field_id( 'id' ) ); ?>">
159 <?php esc_html_e( 'ID', 'tutor' ); ?>:
160 </label>
161 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'id' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'id' ) ); ?>" type="text" value="<?php echo esc_attr( $id ); ?>"> <br />
162 <span style="color: #AAAAAA">
163 <?php esc_html_e( 'Place single course id or comma (,) separated course ids', 'tutor' ); ?>
164 </span>
165 </p>
166
167 <p>
168 <label for="<?php echo esc_attr( $this->get_field_id( 'exclude_ids' ) ); ?>"><?php esc_attr_e( 'Exclude IDS:', 'tutor' ); ?></label>
169 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'exclude_ids' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'exclude_ids' ) ); ?>" type="text" value="<?php echo esc_attr( $exclude_ids ); ?>"> <br />
170 <span style="color: #AAAAAA">
171 <?php esc_html_e( 'Place comma (,) separated courses ids which you like to exclude from the query', 'tutor' ); ?>
172 </span>
173 </p>
174
175 <p>
176 <label for="<?php echo esc_attr( $this->get_field_id( 'category' ) ); ?>">
177 <?php esc_html_e( 'Category', 'tutor' ); ?>:
178 </label>
179 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'category' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'category' ) ); ?>" type="text" value="<?php echo esc_attr( $category ); ?>"> <br />
180 <span style="color: #AAAAAA">
181 <?php esc_html_e( 'Place comma (,) separated category ids', 'tutor' ); ?>
182 </span>
183 </p>
184
185 <p>
186 <label for="<?php echo esc_attr( $this->get_field_id( 'orderby' ) ); ?>">
187 <?php esc_html_e( 'OrderBy', 'tutor' ); ?>
188 </label>
189
190 <select class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'orderby' ) ); ?>" >
191 <option value="ID" <?php selected( 'ID', $orderby ); ?> >ID</option>
192 <option value="title" <?php selected( 'title', $orderby ); ?> >title</option>
193 <option value="rand" <?php selected( 'rand', $orderby ); ?> >rand</option>
194 <option value="date" <?php selected( 'date', $orderby ); ?> >date</option>
195 <option value="menu_order" <?php selected( 'menu_order', $orderby ); ?> >menu_order</option>
196 <option value="post__in" <?php selected( 'post__in', $orderby ); ?> >post__in</option>
197 </select> <br />
198 </p>
199
200 <p>
201 <label for="<?php echo esc_attr( $this->get_field_id( 'order' ) ); ?>">
202 <?php esc_html_e( 'Order', 'tutor' ); ?>
203 </label>
204
205 <select class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'order' ) ); ?>" >
206 <option value="DESC" <?php selected( 'DESC', $order ); ?> >DESC</option>
207 <option value="ASC" <?php selected( 'ASC', $order ); ?> >ASC</option>
208 </select> <br />
209 </p>
210
211 <p>
212 <label for="<?php echo esc_attr( $this->get_field_id( 'count' ) ); ?>"><?php esc_attr_e( 'Count:', 'tutor' ); ?></label>
213 <input class="widefat tutor-form-number-verify" id="<?php echo esc_attr( $this->get_field_id( 'count' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'count' ) ); ?>" type="number" value="<?php echo esc_attr( $count ); ?>" min="1"> <br />
214 <span style="color: #AAAAAA">
215 <?php esc_html_e( 'Total results you like to show', 'tutor' ); ?>
216 </span>
217 </p>
218
219 <?php
220 }
221
222 /**
223 * Sanitize widget form values as they are saved.
224 *
225 * @since 1.3.1
226 * @see WP_Widget::update()
227 *
228 * @param array $new_instance Values just sent to be saved.
229 * @param array $old_instance Previously saved values from database.
230 *
231 * @return array Updated safe values to be saved.
232 */
233 public function update( $new_instance, $old_instance ) {
234 $instance = array();
235 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? sanitize_text_field( $new_instance['title'] ) : '';
236 $instance['id'] = ( ! empty( $new_instance['id'] ) ) ? sanitize_text_field( $new_instance['id'] ) : '';
237 $instance['exclude_ids'] = ( ! empty( $new_instance['exclude_ids'] ) ) ? sanitize_text_field( $new_instance['exclude_ids'] ) : '';
238 $instance['category'] = ( ! empty( $new_instance['category'] ) ) ? sanitize_text_field( $new_instance['category'] ) : '';
239 $instance['orderby'] = ( ! empty( $new_instance['orderby'] ) ) ? sanitize_text_field( $new_instance['orderby'] ) : '';
240 $instance['order'] = ( ! empty( $new_instance['order'] ) ) ? sanitize_text_field( $new_instance['order'] ) : '';
241 $instance['count'] = ( ! empty( $new_instance['count'] ) ) ? sanitize_text_field( $new_instance['count'] ) : '';
242
243 return $instance;
244 }
245 }
246