1 | <?php |
||
2 | /** |
||
3 | * LSX Team Widget Class |
||
4 | * |
||
5 | * @package LSX Team |
||
6 | * @author LightSpeed |
||
7 | * @license GPL3 |
||
8 | * @link |
||
9 | * @copyright 2016 LightSpeed |
||
10 | */ |
||
11 | class LSX_Team_Widget extends WP_Widget { |
||
12 | |||
13 | public function __construct() { |
||
14 | $widget_ops = array( |
||
15 | 'classname' => 'lsx-team', |
||
16 | ); |
||
17 | |||
18 | parent::__construct( 'LSX_Team_Widget', esc_html__( 'LSX Team Members', 'lsx-team' ), $widget_ops ); |
||
19 | } |
||
20 | |||
21 | public function widget( $args, $instance ) { |
||
22 | extract( $args ); |
||
23 | |||
24 | $title = $instance['title']; |
||
25 | $title_link = $instance['title_link']; |
||
26 | $tagline = $instance['tagline']; |
||
27 | $columns = $instance['columns']; |
||
28 | $orderby = $instance['orderby']; |
||
29 | $order = $instance['order']; |
||
30 | $role = $instance['role']; |
||
31 | $limit = $instance['limit']; |
||
32 | $include = $instance['include']; |
||
33 | $display = $instance['display']; |
||
34 | $size = $instance['size']; |
||
35 | $show_link = $instance['show_link']; |
||
36 | $show_image = $instance['show_image']; |
||
37 | $show_roles = $instance['show_roles']; |
||
38 | $show_job_title = $instance['show_job_title']; |
||
39 | $show_desc = $instance['show_desc']; |
||
40 | $show_social = $instance['show_social']; |
||
41 | $button_text = $instance['button_text']; |
||
42 | $carousel = $instance['carousel']; |
||
43 | $featured = $instance['featured']; |
||
44 | |||
45 | // If limit not set, display 99 posts |
||
46 | if ( empty( $limit ) ) { |
||
47 | $limit = '99'; |
||
48 | } |
||
49 | |||
50 | // If specific posts included, display 99 posts |
||
51 | if ( ! empty( $include ) ) { |
||
52 | $limit = '99'; |
||
53 | } |
||
54 | |||
55 | // Disregard specific ID setting if specific role is defined |
||
56 | if ( 'all' !== $role ) { |
||
57 | $include = ''; |
||
58 | } else { |
||
59 | $role = ''; |
||
60 | } |
||
61 | |||
62 | $show_link = '1' == $show_link ? 'true' : 'false'; |
||
63 | $show_image = '1' == $show_image ? 'true' : 'false'; |
||
64 | $show_roles = '1' == $show_roles ? 'true' : 'false'; |
||
65 | $show_job_title = '1' == $show_job_title ? 'true' : 'false'; |
||
66 | $show_desc = '1' == $show_desc ? 'true' : 'false'; |
||
67 | $show_social = '1' == $show_social ? 'true' : 'false'; |
||
68 | $carousel = '1' == $carousel ? 'true' : 'false'; |
||
69 | $featured = '1' == $featured ? 'true' : 'false'; |
||
70 | |||
71 | if ( $title_link ) { |
||
72 | //$link_open = '<a href="' . $title_link . '">'; |
||
0 ignored issues
–
show
|
|||
73 | $link_open = ''; |
||
74 | $link_btn_open = '<a href="' . $title_link . '" class="btn border-btn">'; |
||
75 | //$link_close = '</a>'; |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
67% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
76 | $link_close = ''; |
||
77 | $link_btn_close = '</a>'; |
||
78 | } else { |
||
79 | $link_open = ''; |
||
80 | $link_btn_open = ''; |
||
81 | $link_close = ''; |
||
82 | $link_btn_close = ''; |
||
83 | } |
||
84 | |||
85 | echo wp_kses_post( $before_widget ); |
||
86 | |||
87 | if ( $title ) { |
||
88 | echo wp_kses_post( $before_title . $link_open . $title . $link_close . $after_title ); |
||
89 | } |
||
90 | |||
91 | if ( $tagline ) { |
||
92 | echo '<p class="tagline text-center">' . esc_html( $tagline ) . '</p>'; |
||
93 | } |
||
94 | |||
95 | if ( class_exists( 'LSX_Team' ) ) { |
||
96 | lsx_team( array( |
||
97 | 'columns' => $columns, |
||
98 | 'orderby' => $orderby, |
||
99 | 'order' => $order, |
||
100 | 'role' => $role, |
||
101 | 'limit' => $limit, |
||
102 | 'include' => $include, |
||
103 | 'display' => $display, |
||
104 | 'size' => $size, |
||
105 | 'show_link' => $show_link, |
||
106 | 'show_image' => $show_image, |
||
107 | 'show_roles' => $show_roles, |
||
108 | 'show_job_title' => $show_job_title, |
||
109 | 'show_desc' => $show_desc, |
||
110 | 'show_social' => $show_social, |
||
111 | 'carousel' => $carousel, |
||
112 | 'featured' => $featured, |
||
113 | ) ); |
||
114 | |||
115 | }; |
||
116 | |||
117 | if ( $button_text && $title_link ) { |
||
118 | echo wp_kses_post( '<p class="text-center lsx-team-archive-link-wrap"><span class="lsx-team-archive-link">' . $link_btn_open . $button_text . ' <i class="fa fa-angle-right"></i>' . $link_btn_close . '</span></p>' ); |
||
119 | } |
||
120 | |||
121 | echo wp_kses_post( $after_widget ); |
||
122 | } |
||
123 | |||
124 | public function update( $new_instance, $old_instance ) { |
||
125 | $instance = $old_instance; |
||
126 | |||
127 | $instance['title'] = wp_kses_post( force_balance_tags( $new_instance['title'] ) ); |
||
128 | $instance['title_link'] = strip_tags( $new_instance['title_link'] ); |
||
129 | $instance['tagline'] = strip_tags( $new_instance['tagline'] ); |
||
130 | $instance['columns'] = strip_tags( $new_instance['columns'] ); |
||
131 | $instance['orderby'] = strip_tags( $new_instance['orderby'] ); |
||
132 | $instance['order'] = strip_tags( $new_instance['order'] ); |
||
133 | $instance['role'] = strip_tags( $new_instance['role'] ); |
||
134 | $instance['limit'] = strip_tags( $new_instance['limit'] ); |
||
135 | $instance['include'] = strip_tags( $new_instance['include'] ); |
||
136 | $instance['display'] = strip_tags( $new_instance['display'] ); |
||
137 | $instance['size'] = strip_tags( $new_instance['size'] ); |
||
138 | $instance['show_link'] = strip_tags( $new_instance['show_link'] ); |
||
139 | $instance['show_image'] = strip_tags( $new_instance['show_image'] ); |
||
140 | $instance['show_roles'] = strip_tags( $new_instance['show_roles'] ); |
||
141 | $instance['show_job_title'] = strip_tags( $new_instance['show_job_title'] ); |
||
142 | $instance['show_desc'] = strip_tags( $new_instance['show_desc'] ); |
||
143 | $instance['show_social'] = strip_tags( $new_instance['show_social'] ); |
||
144 | $instance['button_text'] = strip_tags( $new_instance['button_text'] ); |
||
145 | $instance['carousel'] = strip_tags( $new_instance['carousel'] ); |
||
146 | $instance['featured'] = strip_tags( $new_instance['featured'] ); |
||
147 | |||
148 | return $instance; |
||
149 | } |
||
150 | |||
151 | public function form( $instance ) { |
||
152 | $defaults = array( |
||
153 | 'title' => 'Team Members', |
||
154 | 'title_link' => '', |
||
155 | 'tagline' => '', |
||
156 | 'columns' => '1', |
||
157 | 'orderby' => 'name', |
||
158 | 'order' => 'ASC', |
||
159 | 'role' => '', |
||
160 | 'limit' => '', |
||
161 | 'include' => '', |
||
162 | 'display' => 'excerpt', |
||
163 | 'size' => 'lsx-team-archive', |
||
164 | 'show_link' => 0, |
||
165 | 'show_image' => 1, |
||
166 | 'show_roles' => 0, |
||
167 | 'show_job_title' => 1, |
||
168 | 'show_desc' => 1, |
||
169 | 'show_social' => 1, |
||
170 | 'button_text' => '', |
||
171 | 'carousel' => 1, |
||
172 | 'featured' => 0, |
||
173 | ); |
||
174 | |||
175 | $instance = wp_parse_args( (array) $instance, $defaults ); |
||
176 | |||
177 | $title = esc_attr( $instance['title'] ); |
||
178 | $title_link = esc_attr( $instance['title_link'] ); |
||
179 | $tagline = esc_attr( $instance['tagline'] ); |
||
180 | $columns = esc_attr( $instance['columns'] ); |
||
181 | $orderby = esc_attr( $instance['orderby'] ); |
||
182 | $order = esc_attr( $instance['order'] ); |
||
183 | $role = esc_attr( $instance['role'] ); |
||
184 | $limit = esc_attr( $instance['limit'] ); |
||
185 | $include = esc_attr( $instance['include'] ); |
||
186 | $display = esc_attr( $instance['display'] ); |
||
187 | $size = esc_attr( $instance['size'] ); |
||
188 | $show_link = esc_attr( $instance['show_link'] ); |
||
189 | $show_image = esc_attr( $instance['show_image'] ); |
||
190 | $show_roles = esc_attr( $instance['show_roles'] ); |
||
191 | $show_job_title = esc_attr( $instance['show_job_title'] ); |
||
192 | $show_desc = esc_attr( $instance['show_desc'] ); |
||
193 | $show_social = esc_attr( $instance['show_social'] ); |
||
194 | $button_text = esc_attr( $instance['button_text'] ); |
||
195 | $carousel = esc_attr( $instance['carousel'] ); |
||
196 | $featured = esc_attr( $instance['featured'] ); |
||
197 | ?> |
||
198 | <p> |
||
199 | <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'lsx-team' ); ?></label> |
||
200 | <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 ); ?>" /> |
||
201 | </p> |
||
202 | <p> |
||
203 | <label for="<?php echo esc_attr( $this->get_field_id( 'title_link' ) ); ?>"><?php esc_html_e( 'Page Link:', 'lsx-team' ); ?></label> |
||
204 | <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title_link' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title_link' ) ); ?>" type="text" value="<?php echo esc_attr( $title_link ); ?>" /> |
||
205 | <small><?php esc_html_e( 'Link the widget to a page', 'lsx-team' ); ?></small> |
||
206 | </p> |
||
207 | <p> |
||
208 | <label for="<?php echo esc_attr( $this->get_field_id( 'tagline' ) ); ?>"><?php esc_html_e( 'Tagline:', 'lsx-team' ); ?></label> |
||
209 | <textarea class="widefat" rows="8" cols="20" id="<?php echo esc_attr( $this->get_field_id( 'tagline' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'tagline' ) ); ?>"><?php echo esc_html( $tagline ); ?></textarea> |
||
210 | <small><?php esc_html_e( 'Tagline to display below the widget title', 'lsx-team' ); ?></small> |
||
211 | </p> |
||
212 | <p> |
||
213 | <label for="<?php echo esc_attr( $this->get_field_id( 'columns' ) ); ?>"><?php esc_html_e( 'Columns:', 'lsx-team' ); ?></label> |
||
214 | <select name="<?php echo esc_attr( $this->get_field_name( 'columns' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'columns' ) ); ?>" class="widefat layout"> |
||
215 | <?php |
||
216 | $options = array( '1', '2', '3', '4' ); |
||
217 | |||
218 | foreach ( $options as $option ) { |
||
219 | echo '<option value="' . lcfirst( esc_attr( $option ) ) . '" id="' . esc_attr( $option ) . '"', lcfirst( $option ) == $columns ? ' selected="selected"' : '', '>', esc_html( $option ), '</option>'; |
||
220 | } |
||
221 | ?> |
||
222 | </select> |
||
223 | </p> |
||
224 | <p> |
||
225 | <label for="<?php echo esc_attr( $this->get_field_id( 'orderby' ) ); ?>"><?php esc_html_e( 'Order By:', 'lsx-team' ); ?></label> |
||
226 | <select name="<?php echo esc_attr( $this->get_field_name( 'orderby' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'orderby' ) ); ?>" class="widefat"> |
||
227 | <?php |
||
228 | $options = array( |
||
229 | esc_html__( 'None', 'lsx-team' ) => 'none', |
||
230 | esc_html__( 'ID', 'lsx-team' ) => 'ID', |
||
231 | esc_html__( 'Name', 'lsx-team' ) => 'name', |
||
232 | esc_html__( 'Date', 'lsx-team' ) => 'date', |
||
233 | esc_html__( 'Modified Date', 'lsx-team' ) => 'modified', |
||
234 | esc_html__( 'Random', 'lsx-team' ) => 'rand', |
||
235 | esc_html__( 'Menu (WP dashboard order)', 'lsx-team' ) => 'menu_order', |
||
236 | ); |
||
237 | |||
238 | foreach ( $options as $name => $value ) { |
||
239 | echo '<option value="' . esc_attr( $value ) . '" id="' . esc_attr( $value ) . '"', $orderby == $value ? ' selected="selected"' : '', '>', esc_html( $name ), '</option>'; |
||
240 | } |
||
241 | ?> |
||
242 | </select> |
||
243 | </p> |
||
244 | <p> |
||
245 | <label for="<?php echo esc_attr( $this->get_field_id( 'order' ) ); ?>"><?php esc_html_e( 'Order:', 'lsx-team' ); ?></label> |
||
246 | <select name="<?php echo esc_attr( $this->get_field_name( 'order' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'order' ) ); ?>" class="widefat"> |
||
247 | <?php |
||
248 | $options = array( |
||
249 | esc_html__( 'Ascending', 'lsx-team' ) => 'ASC', |
||
250 | esc_html__( 'Descending', 'lsx-team' ) => 'DESC', |
||
251 | ); |
||
252 | |||
253 | foreach ( $options as $name => $value ) { |
||
254 | echo '<option value="' . esc_attr( $value ) . '" id="' . esc_attr( $value ) . '"', $order == $value ? ' selected="selected"' : '', '>', esc_html( $name ), '</option>'; |
||
255 | } |
||
256 | ?> |
||
257 | </select> |
||
258 | </p> |
||
259 | <p> |
||
260 | <label for="<?php echo esc_attr( $this->get_field_id( 'role' ) ); ?>"><?php esc_html_e( 'Role:', 'lsx-team' ); ?></label> |
||
261 | <select name="<?php echo esc_attr( $this->get_field_name( 'role' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'role' ) ); ?>" class="widefat"> |
||
262 | <?php |
||
263 | $options = get_terms( 'team_role' ); |
||
264 | ?> |
||
265 | <option value="all" id="all"> |
||
266 | <?php esc_html_e( 'All Roles', 'lsx-team' ); ?> |
||
267 | </option> |
||
268 | <?php |
||
269 | foreach ( $options as $option ) { |
||
270 | echo '<option value="' . esc_attr( $option->slug ) . '" id="' . esc_attr( $option->slug ) . '"', $role == $option->slug ? ' selected="selected"' : '', '>', esc_html( $option->name ), '</option>'; |
||
271 | } |
||
272 | ?> |
||
273 | </select> |
||
274 | <small><?php esc_html_e( 'Display team members within a specific role', 'lsx-team' ); ?></small> |
||
275 | </p> |
||
276 | <p> |
||
277 | <label for="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>"><?php esc_html_e( 'Maximum amount:', 'lsx-team' ); ?></label> |
||
278 | <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'limit' ) ); ?>" type="text" value="<?php echo esc_attr( $limit ); ?>" /> |
||
279 | <small><?php esc_html_e( 'Leave empty to display all', 'lsx-team' ); ?></small> |
||
280 | </p> |
||
281 | <p> |
||
282 | <label for="<?php echo esc_attr( $this->get_field_id( 'include' ) ); ?>"><?php esc_html_e( 'Specify Team Members by ID:', 'lsx-team' ); ?></label> |
||
283 | <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'include' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'include' ) ); ?>" type="text" value="<?php echo esc_attr( $include ); ?>" /> |
||
284 | <small><?php esc_html_e( 'Comma separated list, overrides limit setting', 'lsx-team' ); ?></small> |
||
285 | </p> |
||
286 | <p> |
||
287 | <label for="<?php echo esc_attr( $this->get_field_id( 'display' ) ); ?>"><?php esc_html_e( 'Display:', 'lsx-team' ); ?></label> |
||
288 | <select name="<?php echo esc_attr( $this->get_field_name( 'display' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'display' ) ); ?>" class="widefat"> |
||
289 | <?php |
||
290 | $options = array( |
||
291 | esc_html__( 'Excerpt', 'lsx-team' ) => 'excerpt', |
||
292 | esc_html__( 'Full Content', 'lsx-team' ) => 'full', |
||
293 | ); |
||
294 | |||
295 | foreach ( $options as $name => $value ) { |
||
296 | echo '<option value="' . esc_attr( $value ) . '" id="' . esc_attr( $value ) . '"', $display == $value ? ' selected="selected"' : '', '>', esc_html( $name ), '</option>'; |
||
297 | } |
||
298 | ?> |
||
299 | </select> |
||
300 | </p> |
||
301 | <p> |
||
302 | <label for="<?php echo esc_attr( $this->get_field_id( 'size' ) ); ?>"><?php esc_html_e( 'Image size:', 'lsx-team' ); ?></label> |
||
303 | <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'size' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'size' ) ); ?>" type="text" value="<?php echo esc_attr( $size ); ?>" /> |
||
304 | </p> |
||
305 | <p> |
||
306 | <label for="<?php echo esc_attr( $this->get_field_id( 'button_text' ) ); ?>"><?php esc_html_e( 'Button "view all" text:', 'lsx-team' ); ?></label> |
||
307 | <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'button_text' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'button_text' ) ); ?>" type="text" value="<?php echo esc_attr( $button_text ); ?>" /> |
||
308 | <small><?php esc_html_e( 'Leave empty to not display the button', 'lsx-team' ); ?></small> |
||
309 | </p> |
||
310 | <p> |
||
311 | <input id="<?php echo esc_attr( $this->get_field_id( 'show_link' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'show_link' ) ); ?>" type="checkbox" value="1" <?php checked( '1', $show_link ); ?> /> |
||
312 | <label for="<?php echo esc_attr( $this->get_field_id( 'show_link' ) ); ?>"><?php esc_html_e( 'Link to Single', 'lsx-team' ); ?></label> |
||
313 | </p> |
||
314 | <p> |
||
315 | <input id="<?php echo esc_attr( $this->get_field_id( 'show_image' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'show_image' ) ); ?>" type="checkbox" value="1" <?php checked( '1', $show_image ); ?> /> |
||
316 | <label for="<?php echo esc_attr( $this->get_field_id( 'show_image' ) ); ?>"><?php esc_html_e( 'Show Images', 'lsx-team' ); ?></label> |
||
317 | </p> |
||
318 | <p> |
||
319 | <input id="<?php echo esc_attr( $this->get_field_id( 'show_roles' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'show_roles' ) ); ?>" type="checkbox" value="1" <?php checked( '1', $show_roles ); ?> /> |
||
320 | <label for="<?php echo esc_attr( $this->get_field_id( 'show_roles' ) ); ?>"><?php esc_html_e( 'Show Roles', 'lsx-team' ); ?></label> |
||
321 | </p> |
||
322 | <p> |
||
323 | <input id="<?php echo esc_attr( $this->get_field_id( 'show_job_title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'show_job_title' ) ); ?>" type="checkbox" value="1" <?php checked( '1', $show_job_title ); ?> /> |
||
324 | <label for="<?php echo esc_attr( $this->get_field_id( 'show_job_title' ) ); ?>"><?php esc_html_e( 'Show Job Title', 'lsx-team' ); ?></label> |
||
325 | </p> |
||
326 | <p> |
||
327 | <input id="<?php echo esc_attr( $this->get_field_id( 'show_desc' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'show_desc' ) ); ?>" type="checkbox" value="1" <?php checked( '1', $show_desc ); ?> /> |
||
328 | <label for="<?php echo esc_attr( $this->get_field_id( 'show_desc' ) ); ?>"><?php esc_html_e( 'Show Description', 'lsx-team' ); ?></label> |
||
329 | </p> |
||
330 | <p> |
||
331 | <input id="<?php echo esc_attr( $this->get_field_id( 'show_social' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'show_social' ) ); ?>" type="checkbox" value="1" <?php checked( '1', $show_social ); ?> /> |
||
332 | <label for="<?php echo esc_attr( $this->get_field_id( 'show_social' ) ); ?>"><?php esc_html_e( 'Show Social Icons', 'lsx-team' ); ?></label> |
||
333 | </p> |
||
334 | <p> |
||
335 | <input id="<?php echo esc_attr( $this->get_field_id( 'carousel' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'carousel' ) ); ?>" type="checkbox" value="1" <?php checked( '1', $carousel ); ?> /> |
||
336 | <label for="<?php echo esc_attr( $this->get_field_id( 'carousel' ) ); ?>"><?php esc_html_e( 'Carousel', 'lsx-team' ); ?></label> |
||
337 | </p> |
||
338 | <p> |
||
339 | <input id="<?php echo esc_attr( $this->get_field_id( 'featured' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'featured' ) ); ?>" type="checkbox" value="1" <?php checked( '1', $featured ); ?> /> |
||
340 | <label for="<?php echo esc_attr( $this->get_field_id( 'featured' ) ); ?>"><?php esc_html_e( 'Featured posts', 'lsx-team' ); ?></label> |
||
341 | </p> |
||
342 | <?php |
||
343 | } |
||
344 | |||
345 | } |
||
346 | |||
347 | /** |
||
348 | * Registers the Widget |
||
349 | */ |
||
350 | function lsx_team_widget() { |
||
351 | register_widget( 'LSX_Team_Widget' ); |
||
352 | } |
||
353 | |||
354 | add_action( 'widgets_init', 'lsx_team_widget' ); |
||
355 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.