1 | <?php |
||||
2 | /** |
||||
3 | * LSX Team Main Class |
||||
4 | * |
||||
5 | * @package LSX Team |
||||
6 | * @author LightSpeed |
||||
7 | * @license GPL3 |
||||
8 | * @link |
||||
9 | * @copyright 2018 LightSpeed |
||||
10 | */ |
||||
11 | class LSX_Team { |
||||
12 | |||||
13 | public $options; |
||||
14 | |||||
15 | public function __construct() { |
||||
16 | $this->options = team_get_options(); |
||||
17 | |||||
18 | add_action( 'init', array( $this, 'custom_image_sizes' ) ); |
||||
19 | add_filter( 'lsx_banner_allowed_post_types', array( $this, 'lsx_banner_allowed_post_types' ) ); |
||||
20 | |||||
21 | } |
||||
22 | |||||
23 | /** |
||||
24 | * Enable project custom post type on LSX Banners. |
||||
25 | */ |
||||
26 | public function custom_image_sizes( $post_types ) { |
||||
27 | add_image_size( 'lsx-team-archive', 170, 170, true ); |
||||
28 | add_image_size( 'lsx-team-single', 320, 320, true ); |
||||
29 | } |
||||
30 | |||||
31 | /** |
||||
32 | * Enable project custom post type on LSX Banners. |
||||
33 | */ |
||||
34 | public function lsx_banner_allowed_post_types( $post_types ) { |
||||
35 | $post_types[] = 'team'; |
||||
36 | return $post_types; |
||||
37 | } |
||||
38 | |||||
39 | /** |
||||
40 | * Return the team thumbnail. |
||||
41 | */ |
||||
42 | public function get_thumbnail( $post_id, $size ) { |
||||
43 | add_filter( 'lsx_placeholder_url', array( $this, 'placeholder' ), 10, 1 ); |
||||
44 | add_filter( 'lsx_to_placeholder_url', array( $this, 'placeholder' ), 10, 1 ); |
||||
45 | |||||
46 | if ( is_numeric( $size ) ) { |
||||
47 | $thumb_size = array( $size, $size ); |
||||
48 | } else { |
||||
49 | $thumb_size = $size; |
||||
50 | } |
||||
51 | |||||
52 | $thumbnail_class = 'img-responsive'; |
||||
53 | |||||
54 | if ( ! empty( get_the_post_thumbnail( $post_id ) ) || ! empty( get_post_meta( $post_id, 'lsx_email_gravatar', true ) ) ) { |
||||
55 | if ( ! empty( get_the_post_thumbnail( $post_id ) ) ) { |
||||
56 | $thumbnail = get_the_post_thumbnail( $post_id, $thumb_size, array( |
||||
57 | 'class' => $thumbnail_class, |
||||
58 | ) ); |
||||
59 | } else { |
||||
60 | $thumbnail = get_avatar( get_post_meta( $post_id, 'lsx_email_gravatar', true ), $size, $this->options['display']['team_placeholder'], false, array( |
||||
61 | 'class' => $thumbnail_class, |
||||
62 | ) ); |
||||
63 | } |
||||
64 | } |
||||
65 | if ( empty( $thumbnail ) ) { |
||||
66 | if ( $this->options['display'] && ! empty( $this->options['display']['team_placeholder'] ) ) { |
||||
67 | $thumbnail = '<img loading="lazy" class="img-responsive wp-post-image" src="' . $this->options['display']['team_placeholder'] . '" width="' . $size . '" />'; |
||||
68 | } else { |
||||
69 | $thumbnail = '<img loading="lazy" class="img-responsive wp-post-image" src="https://www.gravatar.com/avatar/none?d=mm&s=' . $size . '" width="' . $size . '" />'; |
||||
70 | } |
||||
71 | } |
||||
72 | |||||
73 | remove_filter( 'lsx_placeholder_url', array( $this, 'placeholder' ), 10, 1 ); |
||||
74 | remove_filter( 'lsx_to_placeholder_url', array( $this, 'placeholder' ), 10, 1 ); |
||||
75 | |||||
76 | return $thumbnail; |
||||
77 | } |
||||
78 | |||||
79 | /** |
||||
80 | * Replaces the widget with Mystery Man |
||||
81 | */ |
||||
82 | public function placeholder( $image ) { |
||||
83 | $image = array( |
||||
84 | LSX_TEAM_URL . 'assets/img/mystery-man-square.png', |
||||
85 | 512, |
||||
86 | 512, |
||||
87 | true, |
||||
88 | ); |
||||
89 | |||||
90 | return $image; |
||||
91 | } |
||||
92 | |||||
93 | /** |
||||
94 | * Returns the shortcode output markup |
||||
95 | */ |
||||
96 | public function output( $atts ) { |
||||
97 | extract( shortcode_atts(array( |
||||
98 | 'columns' => 4, |
||||
99 | 'orderby' => 'name', |
||||
100 | 'order' => 'ASC', |
||||
101 | 'role' => '', |
||||
102 | 'limit' => '99', |
||||
103 | 'include' => '', |
||||
104 | 'display' => 'excerpt', |
||||
105 | 'size' => 'lsx-team-archive', |
||||
106 | 'show_link' => false, |
||||
107 | 'show_email' => false, |
||||
108 | 'show_image' => true, |
||||
109 | 'show_roles' => false, |
||||
110 | 'show_job_title' => true, |
||||
111 | 'show_desc' => true, |
||||
112 | 'show_social' => true, |
||||
113 | 'carousel' => true, |
||||
114 | 'featured' => false, |
||||
115 | ), $atts ) ); |
||||
116 | |||||
117 | $output = ''; |
||||
118 | |||||
119 | if ( ! empty( $include ) ) { |
||||
120 | $include = explode( ',', $include ); |
||||
121 | |||||
122 | $args = array( |
||||
123 | 'post_type' => 'team', |
||||
124 | 'posts_per_page' => $limit, |
||||
125 | 'post__in' => $include, |
||||
126 | 'orderby' => 'post__in', |
||||
127 | 'order' => $order, |
||||
128 | ); |
||||
129 | } else { |
||||
130 | $args = array( |
||||
131 | 'post_type' => 'team', |
||||
132 | 'posts_per_page' => $limit, |
||||
133 | 'orderby' => $orderby, |
||||
134 | 'order' => $order, |
||||
135 | ); |
||||
136 | |||||
137 | if ( 'true' === $featured || true === $featured ) { |
||||
138 | $args['meta_key'] = 'lsx_featured'; |
||||
139 | $args['meta_value'] = 1; |
||||
140 | } |
||||
141 | } |
||||
142 | |||||
143 | if ( ! empty( $role ) ) { |
||||
144 | $args['tax_query'] = array( |
||||
145 | array( |
||||
146 | 'taxonomy' => 'team_role', |
||||
147 | 'field' => 'id', |
||||
148 | 'terms' => $role, |
||||
149 | ), |
||||
150 | ); |
||||
151 | } |
||||
152 | |||||
153 | $team = new \WP_Query( $args ); |
||||
154 | |||||
155 | if ( $team->have_posts() ) { |
||||
156 | global $post; |
||||
157 | |||||
158 | $count = 0; |
||||
159 | $count_global = 0; |
||||
160 | |||||
161 | $column_size = intval( 12 / $columns ); |
||||
162 | |||||
163 | $carousel = true === $carousel || 'true' === $carousel ? true : false; |
||||
164 | |||||
165 | if ( $carousel ) { |
||||
166 | $output .= "<div class='lsx-team-shortcode lsx-team-block' id='lsx-team-slider' data-slick='{\"slidesToShow\": $columns, \"slidesToScroll\": $columns }'>"; |
||||
167 | } else { |
||||
168 | $output .= "<div class='lsx-team-shortcode'><div class='row'>"; |
||||
169 | } |
||||
170 | |||||
171 | while ( $team->have_posts() ) { |
||||
172 | $team->the_post(); |
||||
173 | |||||
174 | // Count |
||||
175 | $count++; |
||||
176 | $count_global++; |
||||
177 | |||||
178 | $member_name = apply_filters( 'the_title', $post->post_title ); |
||||
179 | $member_roles = ''; |
||||
180 | $member_description = ''; |
||||
181 | $member_avatar = ''; |
||||
182 | $member_socials = ''; |
||||
183 | $member_job_title = ''; |
||||
184 | $member_email = ''; |
||||
185 | $bottom_link = ''; |
||||
186 | $facebook = get_post_meta( $post->ID, 'lsx_facebook', true ); |
||||
187 | $twitter = get_post_meta( $post->ID, 'lsx_twitter', true ); |
||||
188 | $linkedin = get_post_meta( $post->ID, 'lsx_linkedin', true ); |
||||
189 | |||||
190 | // Link to single |
||||
191 | if ( ( true === $show_link || 'true' === $show_link ) && ( empty( team_get_option( 'team_disable_single' ) ) ) ) { |
||||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||||
192 | $bottom_link = '<a href="' . get_permalink( $post->ID ) . '" class="lsx-team-show-more">More about ' . strtok( $member_name, ' ' ) . '<i class="fa fa-long-arrow-right" aria-hidden="true"></i></a>'; |
||||
193 | } |
||||
194 | |||||
195 | if ( true === $show_email || 'true' === $show_email ) { |
||||
196 | $email = get_post_meta( $post->ID, 'lsx_email_contact', true ); |
||||
197 | |||||
198 | $member_email = '<a href="mailto:' . sanitize_email( $email ) . '" class="lsx-team-email">' . sanitize_email( $email ) . '</a>'; |
||||
0 ignored issues
–
show
It seems like
$email can also be of type false ; however, parameter $email of sanitize_email() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
199 | } |
||||
200 | |||||
201 | if ( ( true === $show_link || 'true' === $show_link ) && ( empty( team_get_option( 'team_disable_single' ) ) ) ) { |
||||
0 ignored issues
–
show
|
|||||
202 | $member_name = '<h5 class="lsx-team-name"><a href="' . get_permalink() . '">' . $member_name . '</a></h5>'; |
||||
203 | } else { |
||||
204 | $member_name = '<h5 class="lsx-team-name">' . $member_name . '</h5>'; |
||||
205 | } |
||||
206 | |||||
207 | // Member roles |
||||
208 | if ( true === $show_roles || 'true' === $show_roles ) { |
||||
209 | $roles = ''; |
||||
210 | $terms = get_the_terms( $post->ID, 'team_role' ); |
||||
211 | |||||
212 | if ( $terms && ! is_wp_error( $terms ) ) { |
||||
213 | $roles = array(); |
||||
214 | |||||
215 | foreach ( $terms as $term ) { |
||||
216 | $roles[] = $term->name; |
||||
217 | } |
||||
218 | |||||
219 | $roles = join( ', ', $roles ); |
||||
220 | } |
||||
221 | |||||
222 | $member_roles = '' !== $roles ? "<small class='lsx-team-roles'>$roles</small>" : ''; |
||||
223 | } |
||||
224 | |||||
225 | if ( true === $show_job_title || 'true' === $show_job_title ) { |
||||
226 | $job_title = get_post_meta( $post->ID, 'lsx_job_title', true ); |
||||
227 | $member_job_title = ! empty( $job_title ) ? "<small class='lsx-team-job-title'>$job_title</small>" : ''; |
||||
228 | } |
||||
229 | |||||
230 | // Member description |
||||
231 | if ( true === $show_desc || 'true' === $show_desc ) { |
||||
232 | if ( 'full' === $display ) { |
||||
233 | $member_description = apply_filters( 'the_content', get_the_content( esc_html__( 'Read More', 'lsx-team' ) ) ); |
||||
234 | $member_description = str_replace( ']]>', ']]>', $member_description ); |
||||
235 | } elseif ( 'excerpt' === $display ) { |
||||
236 | $member_description = apply_filters( 'the_excerpt', get_the_excerpt() ); |
||||
237 | } |
||||
238 | |||||
239 | $member_description = ! empty( $member_description ) ? "<div class='lsx-team-description'>$member_description</div>" : ''; |
||||
240 | } |
||||
241 | |||||
242 | // Member avatar |
||||
243 | if ( true === $show_image || 'true' === $show_image ) { |
||||
244 | $member_avatar = $this->get_thumbnail( $post->ID, $size ); |
||||
245 | |||||
246 | if ( ( true === $show_link || 'true' === $show_link ) && ( empty( $this->options['display'] ) || empty( team_get_option( 'team_disable_single' ) ) ) ) { |
||||
0 ignored issues
–
show
|
|||||
247 | $member_avatar = "<figure class='lsx-team-avatar'><a href='" . get_permalink() . "'>$member_avatar</a></figure>"; |
||||
248 | } else { |
||||
249 | $member_avatar = "<figure class='lsx-team-avatar'>$member_avatar</figure>"; |
||||
250 | } |
||||
251 | } |
||||
252 | |||||
253 | // Member socials |
||||
254 | if ( true === $show_social || 'true' === $show_social ) { |
||||
255 | $links = array( |
||||
256 | 'facebook' => $facebook, |
||||
257 | 'twitter' => $twitter, |
||||
258 | 'linkedin' => $linkedin, |
||||
259 | ); |
||||
260 | |||||
261 | foreach ( $links as $sm => $sm_link ) { |
||||
262 | if ( ! empty( $sm_link ) ) { |
||||
263 | $member_socials .= "<li><a href='$sm_link' target='_blank'><i class='fa fa-$sm' aria-hidden='true'></i></a></li>"; |
||||
264 | } |
||||
265 | } |
||||
266 | |||||
267 | $member_socials = ! empty( $member_socials ) ? "<ul class='lsx-team-socials list-inline'>$member_socials</ul>" : ''; |
||||
268 | } |
||||
269 | |||||
270 | if ( ! $carousel ) { |
||||
271 | $output .= "<div class='col-xs-12 col-md-$column_size'>"; |
||||
272 | } |
||||
273 | |||||
274 | $output .= " |
||||
275 | <div class='lsx-team-slot'> |
||||
276 | $member_avatar |
||||
277 | $member_name |
||||
278 | $member_job_title |
||||
279 | $member_roles |
||||
280 | $member_description |
||||
281 | $member_socials |
||||
282 | $member_email |
||||
283 | $bottom_link |
||||
284 | </div> |
||||
285 | "; |
||||
286 | |||||
287 | if ( ! $carousel ) { |
||||
288 | $output .= '</div>'; |
||||
289 | |||||
290 | if ( $count == $columns && $team->post_count > $count_global ) { |
||||
291 | $output .= '</div>'; |
||||
292 | $output .= '<div class="row">'; |
||||
293 | $count = 0; |
||||
294 | } |
||||
295 | } |
||||
296 | |||||
297 | wp_reset_postdata(); |
||||
298 | } |
||||
299 | |||||
300 | if ( ! $carousel ) { |
||||
301 | $output .= '</div>'; |
||||
302 | } |
||||
303 | |||||
304 | $output .= '</div>'; |
||||
305 | |||||
306 | return $output; |
||||
307 | } |
||||
308 | } |
||||
309 | |||||
310 | } |
||||
311 | |||||
312 | global $lsx_team; |
||||
313 | $lsx_team = new LSX_Team(); |
||||
314 |