| @@ -1,42 +1,27 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | /** |
| 3 | - * Course Widget Register | |
| 4 | + * Widget class | |
| 4 | 5 | * |
| 6 | + * @author: themeum | |
| 7 | + * @author_uri: https://themeum.com | |
| 5 | 8 | * @package Tutor |
| 6 | - * @author Themeum <support@themeum.com> | |
| 7 | - * @link https://themeum.com | |
| 8 | - * @since 1.3.1 | |
| 9 | + * @since v.1.3.1 | |
| 9 | 10 | */ |
| 10 | 11 | |
| 11 | 12 | namespace TUTOR; |
| 12 | 13 | |
| 13 | -use Tutor\Models\CourseModel; | |
| 14 | - | |
| 15 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 14 | +if ( ! defined( 'ABSPATH' ) ) | |
| 16 | 15 | exit; |
| 17 | -} | |
| 18 | 16 | |
| 19 | -/** | |
| 20 | - * Course Widget Class | |
| 21 | - * | |
| 22 | - * @since 1.3.1 | |
| 23 | - */ | |
| 24 | 17 | class Course_Widget extends \WP_Widget { |
| 25 | - | |
| 26 | - /** | |
| 27 | - * Constructor | |
| 28 | - * | |
| 29 | - * @since 1.3.1 | |
| 30 | - * @return void | |
| 31 | - */ | |
| 32 | - public function __construct() { | |
| 18 | + | |
| 19 | + function __construct() { | |
| 33 | 20 | 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 | - ) | |
| 21 | + 'tutor_course_widget', // Base ID | |
| 22 | + esc_html__( 'Tutor Course', 'tutor' ), // Name | |
| 23 | + array( 'description' => esc_html__( 'Display courses wherever widget support is available.', 'tutor' ), ) // Args | |
| 39 | 24 | ); |
| 40 | 25 | } |
| 41 | 26 | |
| 42 | 27 | /** |
| @@ -41,71 +26,54 @@ | ||
| 41 | 26 | |
| 42 | 27 | /** |
| 43 | 28 | * Front-end display of widget. |
| 44 | 29 | * |
| 45 | - * @since 1.3.1 | |
| 46 | 30 | * @see WP_Widget::widget() |
| 47 | 31 | * |
| 48 | 32 | * @param array $args Widget arguments. |
| 49 | 33 | * @param array $instance Saved values from database. |
| 50 | - * | |
| 51 | - * @return void | |
| 52 | 34 | */ |
| 53 | 35 | 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 | - ); | |
| 36 | + echo $args['before_widget']; | |
| 67 | 37 | 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() ) ); | |
| 38 | + echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title']; | |
| 71 | 39 | } |
| 72 | 40 | |
| 73 | 41 | $course_post_type = tutor()->course_post_type; |
| 74 | 42 | |
| 75 | 43 | $form_args = $instance; |
| 76 | - unset( $form_args['title'] ); | |
| 44 | + unset($form_args['title']); | |
| 77 | 45 | |
| 78 | 46 | $default_args = array( |
| 79 | - 'post_type' => $course_post_type, | |
| 80 | - 'post_status' => 'publish', | |
| 47 | + 'post_type' => $course_post_type, | |
| 48 | + 'post_status' => 'publish', | |
| 81 | 49 | |
| 82 | - 'id' => '', | |
| 83 | - 'exclude_ids' => '', | |
| 84 | - 'category' => '', | |
| 50 | + 'id' => '', | |
| 51 | + 'exclude_ids' => '', | |
| 52 | + 'category' => '', | |
| 85 | 53 | |
| 86 | - 'orderby' => 'ID', | |
| 87 | - 'order' => 'DESC', | |
| 88 | - 'count' => '6', | |
| 54 | + 'orderby' => 'ID', | |
| 55 | + 'order' => 'DESC', | |
| 56 | + 'count' => '6', | |
| 89 | 57 | ); |
| 90 | 58 | |
| 91 | - $a = array_merge( $default_args, $form_args ); | |
| 59 | + $a = array_merge($default_args, $form_args); | |
| 92 | 60 | |
| 93 | - if ( ! empty( $a['id'] ) ) { | |
| 94 | - $ids = (array) explode( ',', $a['id'] ); | |
| 61 | + if ( ! empty($a['id'])){ | |
| 62 | + $ids = (array) explode(',', $a['id']); | |
| 95 | 63 | $a['post__in'] = $ids; |
| 96 | 64 | } |
| 97 | 65 | |
| 98 | - if ( ! empty( $a['exclude_ids'] ) ) { | |
| 99 | - $exclude_ids = (array) explode( ',', $a['exclude_ids'] ); | |
| 66 | + if ( ! empty($a['exclude_ids'])){ | |
| 67 | + $exclude_ids = (array) explode(',', $a['exclude_ids']); | |
| 100 | 68 | $a['post__not_in'] = $exclude_ids; |
| 101 | 69 | } |
| 102 | - if ( ! empty( $a['category'] ) ) { | |
| 103 | - $category = (array) explode( ',', $a['category'] ); | |
| 70 | + if ( ! empty($a['category'])){ | |
| 71 | + $category = (array) explode(',', $a['category']); | |
| 104 | 72 | |
| 105 | 73 | $a['tax_query'] = array( |
| 106 | 74 | array( |
| 107 | - 'taxonomy' => CourseModel::COURSE_CATEGORY, | |
| 75 | + 'taxonomy' => 'course-category', | |
| 108 | 76 | 'field' => 'term_id', |
| 109 | 77 | 'terms' => $category, |
| 110 | 78 | 'operator' => 'IN', |
| 111 | 79 | ), |
| @@ -113,112 +81,92 @@ | ||
| 113 | 81 | } |
| 114 | 82 | $a['posts_per_page'] = (int) $a['count']; |
| 115 | 83 | |
| 116 | 84 | wp_reset_query(); |
| 117 | - query_posts( $a ); | |
| 85 | + query_posts($a); | |
| 118 | 86 | ob_start(); |
| 119 | - tutor_load_template( 'widget.courses' ); | |
| 87 | + tutor_load_template('widget.courses'); | |
| 120 | 88 | $output = ob_get_clean(); |
| 121 | 89 | wp_reset_query(); |
| 122 | 90 | |
| 123 | - echo wp_kses_post( $output ); | |
| 124 | 91 | |
| 125 | - echo wp_kses( | |
| 126 | - $args['after_widget'], | |
| 127 | - array( | |
| 128 | - 'section' => array(), | |
| 129 | - 'div' => array(), | |
| 130 | - ) | |
| 131 | - ); | |
| 92 | + echo $output; | |
| 93 | + | |
| 94 | + echo $args['after_widget']; | |
| 132 | 95 | } |
| 133 | 96 | |
| 134 | 97 | /** |
| 135 | 98 | * Back-end widget form. |
| 136 | 99 | * |
| 137 | - * @since 1.3.1 | |
| 138 | 100 | * @see WP_Widget::form() |
| 139 | 101 | * |
| 140 | 102 | * @param array $instance Previously saved values from database. |
| 141 | - * @return void | |
| 142 | 103 | */ |
| 143 | 104 | public function form( $instance ) { |
| 144 | - $title = ! empty( $instance['title'] ) ? $instance['title'] : esc_html__( 'New title', 'tutor' ); | |
| 145 | - $id = ! empty( $instance['id'] ) ? $instance['id'] : ''; | |
| 105 | + $title = ! empty( $instance['title'] ) ? $instance['title'] : esc_html__( 'New title', 'tutor' ); | |
| 106 | + $id = ! empty( $instance['id'] ) ? $instance['id'] : ''; | |
| 146 | 107 | $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'; | |
| 108 | + $category = ! empty( $instance['category'] ) ? $instance['category'] : ''; | |
| 109 | + $orderby = ! empty( $instance['orderby'] ) ? $instance['orderby'] : ''; | |
| 110 | + $order = ! empty( $instance['order'] ) ? $instance['order'] : ''; | |
| 111 | + $count = ! empty( $instance['count'] ) ? $instance['count'] : '6'; | |
| 151 | 112 | ?> |
| 152 | 113 | <p> |
| 153 | - <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"> | |
| 154 | - <?php esc_html_e( 'Title', 'tutor' ); ?>: | |
| 155 | - </label> | |
| 114 | + <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_attr_e( 'Title:', 'tutor' ); ?></label> | |
| 156 | 115 | <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 | 116 | </p> |
| 158 | 117 | |
| 159 | 118 | <p> |
| 160 | - <label for="<?php echo esc_attr( $this->get_field_id( 'id' ) ); ?>"> | |
| 161 | - <?php esc_html_e( 'ID', 'tutor' ); ?>: | |
| 162 | - </label> | |
| 119 | + <label for="<?php echo esc_attr( $this->get_field_id( 'id' ) ); ?>"><?php esc_attr_e( 'ID:', 'tutor' ); ?></label> | |
| 163 | 120 | <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> | |
| 121 | + <span style="color: #AAAAAA"><?php _e('Place single course id or comma (,) separated course ids', 'tutor'); ?></span> | |
| 167 | 122 | </p> |
| 168 | 123 | |
| 169 | 124 | <p> |
| 170 | 125 | <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> | |
| 126 | + <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'exclude_ids' ) ); ?>" name="<?php echo esc_attr( | |
| 127 | + $this->get_field_name( 'exclude_ids' ) ); ?>" type="text" value="<?php echo esc_attr( $exclude_ids ); ?>"> <br /> | |
| 128 | + <span style="color: #AAAAAA"><?php _e('Place comma (,) separated courses ids which you like to exclude from the query', 'tutor'); | |
| 129 | + ?></span> | |
| 175 | 130 | </p> |
| 176 | 131 | |
| 177 | 132 | <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> | |
| 133 | + <label for="<?php echo esc_attr( $this->get_field_id( 'category' ) ); ?>"><?php esc_attr_e( 'Category:', 'tutor' ); ?></label> | |
| 134 | + <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'category' ) ); ?>" name="<?php echo esc_attr( | |
| 135 | + $this->get_field_name( 'category' ) ); ?>" type="text" value="<?php echo esc_attr( $category ); ?>"> <br /> | |
| 136 | + <span style="color: #AAAAAA"><?php _e('Place comma (,) separated category ids', 'tutor'); | |
| 137 | + ?></span> | |
| 185 | 138 | </p> |
| 186 | 139 | |
| 187 | 140 | <p> |
| 188 | - <label for="<?php echo esc_attr( $this->get_field_id( 'orderby' ) ); ?>"> | |
| 189 | - <?php esc_html_e( 'OrderBy', 'tutor' ); ?> | |
| 190 | - </label> | |
| 141 | + <label for="<?php echo esc_attr( $this->get_field_id( 'orderby' ) ); ?>"><?php esc_attr_e( 'OrderBy', 'tutor' ); ?></label> | |
| 191 | 142 | |
| 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> | |
| 143 | + <select class="widefat" name="<?php echo esc_attr($this->get_field_name( 'orderby' ) ); ?>" > | |
| 144 | + <option value="ID" <?php selected('ID', $orderby) ?> >ID</option> | |
| 145 | + <option value="title" <?php selected('title', $orderby) ?> >title</option> | |
| 146 | + <option value="rand" <?php selected('rand', $orderby) ?> >rand</option> | |
| 147 | + <option value="date" <?php selected('date', $orderby) ?> >date</option> | |
| 148 | + <option value="menu_order" <?php selected('menu_order', $orderby) ?> >menu_order</option> | |
| 149 | + <option value="post__in" <?php selected('post__in', $orderby) ?> >post__in</option> | |
| 199 | 150 | </select> <br /> |
| 200 | 151 | </p> |
| 201 | 152 | |
| 202 | 153 | <p> |
| 203 | - <label for="<?php echo esc_attr( $this->get_field_id( 'order' ) ); ?>"> | |
| 204 | - <?php esc_html_e( 'Order', 'tutor' ); ?> | |
| 205 | - </label> | |
| 154 | + <label for="<?php echo esc_attr( $this->get_field_id( 'order' ) ); ?>"><?php esc_attr_e( 'order', 'tutor' ); ?></label> | |
| 206 | 155 | |
| 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> | |
| 156 | + <select class="widefat" name="<?php echo esc_attr($this->get_field_name( 'order' ) ); ?>" > | |
| 157 | + <option value="DESC" <?php selected('DESC', $order) ?> >DESC</option> | |
| 158 | + <option value="ASC" <?php selected('ASC', $order) ?> >ASC</option> | |
| 210 | 159 | </select> <br /> |
| 211 | 160 | </p> |
| 212 | 161 | |
| 213 | 162 | <p> |
| 214 | 163 | <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> | |
| 164 | + <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'count' ) ); ?>" name="<?php echo esc_attr( | |
| 165 | + $this->get_field_name( 'count' ) ); ?>" type="number" value="<?php echo esc_attr( $count ); ?>"> <br /> | |
| 166 | + <span style="color: #AAAAAA"><?php _e('Total results you like to show', 'tutor'); ?></span> | |
| 219 | 167 | </p> |
| 220 | - | |
| 168 | + | |
| 221 | 169 | <?php |
| 222 | 170 | } |
| 223 | 171 | |
| 224 | 172 | /** |
| @@ -223,9 +171,8 @@ | ||
| 223 | 171 | |
| 224 | 172 | /** |
| 225 | 173 | * Sanitize widget form values as they are saved. |
| 226 | 174 | * |
| 227 | - * @since 1.3.1 | |
| 228 | 175 | * @see WP_Widget::update() |
| 229 | 176 | * |
| 230 | 177 | * @param array $new_instance Values just sent to be saved. |
| 231 | 178 | * @param array $old_instance Previously saved values from database. |
| @@ -232,16 +179,19 @@ | ||
| 232 | 179 | * |
| 233 | 180 | * @return array Updated safe values to be saved. |
| 234 | 181 | */ |
| 235 | 182 | 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'] ) : ''; | |
| 183 | + $instance = array(); | |
| 184 | + $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? sanitize_text_field( $new_instance['title'] ) : ''; | |
| 185 | + $instance['id'] = ( ! empty( $new_instance['id'] ) ) ? sanitize_text_field( $new_instance['id'] ) : ''; | |
| 186 | + $instance['exclude_ids'] = ( ! empty( $new_instance['exclude_ids'] ) ) ? sanitize_text_field( $new_instance['exclude_ids'] ) : ''; | |
| 187 | + $instance['category'] = ( ! empty( $new_instance['category'] ) ) ? sanitize_text_field( $new_instance['category'] ) : ''; | |
| 188 | + $instance['orderby'] = ( ! empty( $new_instance['orderby'] ) ) ? sanitize_text_field( $new_instance['orderby'] ) : ''; | |
| 189 | + $instance['order'] = ( ! empty( $new_instance['order'] ) ) ? sanitize_text_field( $new_instance['order'] ) : ''; | |
| 190 | + $instance['count'] = ( ! empty( $new_instance['count'] ) ) ? sanitize_text_field( $new_instance['count'] ) : ''; | |
| 244 | 191 | |
| 245 | 192 | return $instance; |
| 246 | 193 | } |
| 247 | -} | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | +} | |