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