Conditions | 48 |
Paths | > 20000 |
Total Lines | 211 |
Code Lines | 134 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
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' ) ) ) ) { |
||
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>'; |
||
199 | } |
||
200 | |||
201 | if ( ( true === $show_link || 'true' === $show_link ) && ( empty( team_get_option( 'team_disable_single' ) ) ) ) { |
||
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' ) ) ) ) { |
||
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 | } |
||
314 |