1 | <?php |
||||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||||
2 | /** |
||||
3 | * LSX Projects Main Class |
||||
4 | * |
||||
5 | * @package LSX Projects |
||||
6 | * @author LightSpeed |
||||
7 | * @license GPL3 |
||||
8 | * @link |
||||
9 | * @copyright 2016 LightSpeed |
||||
10 | */ |
||||
11 | class LSX_Projects { |
||||
12 | |||||
13 | public $columns, $responsive, $options; |
||||
0 ignored issues
–
show
|
|||||
14 | |||||
15 | public function __construct() { |
||||
0 ignored issues
–
show
|
|||||
16 | $this->options = projects_get_options(); |
||||
17 | |||||
18 | add_filter( 'lsx_banner_allowed_post_types', array( $this, 'lsx_banner_allowed_post_types' ) ); |
||||
19 | add_filter( 'lsx_banner_allowed_taxonomies', array( $this, 'lsx_banner_allowed_taxonomies' ) ); |
||||
20 | } |
||||
0 ignored issues
–
show
|
|||||
21 | |||||
22 | /** |
||||
0 ignored issues
–
show
|
|||||
23 | * Enable project custom post type on LSX Banners. |
||||
24 | */ |
||||
25 | public function lsx_banner_allowed_post_types( $post_types ) { |
||||
26 | $post_types[] = 'project'; |
||||
27 | return $post_types; |
||||
28 | } |
||||
0 ignored issues
–
show
|
|||||
29 | |||||
30 | /** |
||||
0 ignored issues
–
show
|
|||||
31 | * Enable project custom taxonomies on LSX Banners. |
||||
32 | */ |
||||
33 | public function lsx_banner_allowed_taxonomies( $taxonomies ) { |
||||
34 | $taxonomies[] = 'project-group'; |
||||
35 | return $taxonomies; |
||||
36 | } |
||||
0 ignored issues
–
show
|
|||||
37 | |||||
38 | /** |
||||
0 ignored issues
–
show
|
|||||
39 | * Returns the shortcode output markup |
||||
40 | */ |
||||
41 | public function output( $atts ) { |
||||
42 | // @codingStandardsIgnoreLine |
||||
43 | extract( shortcode_atts( array( |
||||
44 | 'columns' => 3, |
||||
0 ignored issues
–
show
|
|||||
45 | 'orderby' => 'name', |
||||
0 ignored issues
–
show
|
|||||
46 | 'order' => 'ASC', |
||||
0 ignored issues
–
show
|
|||||
47 | 'limit' => '-1', |
||||
0 ignored issues
–
show
|
|||||
48 | 'include' => '', |
||||
0 ignored issues
–
show
|
|||||
49 | 'display' => 'excerpt', |
||||
0 ignored issues
–
show
|
|||||
50 | 'size' => 'lsx-thumbnail-single', |
||||
0 ignored issues
–
show
|
|||||
51 | 'responsive' => 'true', |
||||
52 | 'show_image' => 'true', |
||||
53 | 'carousel' => 'true', |
||||
0 ignored issues
–
show
|
|||||
54 | 'featured' => 'false', |
||||
0 ignored issues
–
show
|
|||||
55 | ), $atts ) ); |
||||
0 ignored issues
–
show
For multi-line function calls, the closing parenthesis should be on a new line.
If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line: someFunctionCall(
$firstArgument,
$secondArgument,
$thirdArgument
); // Closing parenthesis on a new line.
![]() |
|||||
56 | |||||
57 | $output = ''; |
||||
58 | |||||
59 | if ( 'true' === $responsive || true === $responsive ) { |
||||
0 ignored issues
–
show
|
|||||
60 | $responsive = ' img-responsive'; |
||||
61 | } else { |
||||
62 | $responsive = ''; |
||||
63 | } |
||||
64 | |||||
65 | $this->columns = $columns; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
66 | $this->responsive = $responsive; |
||||
67 | |||||
68 | if ( ! empty( $include ) ) { |
||||
0 ignored issues
–
show
|
|||||
69 | $include = explode( ',', $include ); |
||||
70 | |||||
71 | $args = array( |
||||
72 | 'post_type' => 'project', |
||||
0 ignored issues
–
show
|
|||||
73 | 'posts_per_page' => $limit, |
||||
74 | 'post__in' => $include, |
||||
0 ignored issues
–
show
|
|||||
75 | 'orderby' => 'post__in', |
||||
0 ignored issues
–
show
|
|||||
76 | 'order' => $order, |
||||
0 ignored issues
–
show
|
|||||
77 | ); |
||||
78 | } else { |
||||
79 | $args = array( |
||||
80 | 'post_type' => 'project', |
||||
0 ignored issues
–
show
|
|||||
81 | 'posts_per_page' => $limit, |
||||
82 | 'orderby' => $orderby, |
||||
0 ignored issues
–
show
|
|||||
83 | 'order' => $order, |
||||
0 ignored issues
–
show
|
|||||
84 | ); |
||||
85 | |||||
86 | if ( 'true' === $featured || true === $featured ) { |
||||
0 ignored issues
–
show
|
|||||
87 | $args['meta_key'] = 'lsx_project_featured'; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
88 | $args['meta_value'] = 1; |
||||
0 ignored issues
–
show
|
|||||
89 | } |
||||
90 | } |
||||
91 | |||||
92 | $projects = new \WP_Query( $args ); |
||||
93 | |||||
94 | if ( $projects->have_posts() ) { |
||||
0 ignored issues
–
show
|
|||||
95 | global $post; |
||||
96 | |||||
97 | $count = 0; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
98 | $count_global = 0; |
||||
99 | |||||
100 | if ( 'true' === $carousel || true === $carousel ) { |
||||
0 ignored issues
–
show
|
|||||
101 | $output .= "<div id='lsx-projects-slider' class='lsx-projects-shortcode' data-slick='{\"slidesToShow\": $columns, \"slidesToScroll\": $columns }'>"; |
||||
102 | } else { |
||||
103 | $output .= "<div class='lsx-projects-shortcode'><div class='row'>"; |
||||
104 | } |
||||
105 | |||||
106 | while ( $projects->have_posts() ) { |
||||
0 ignored issues
–
show
|
|||||
107 | $projects->the_post(); |
||||
108 | |||||
109 | // Count |
||||
0 ignored issues
–
show
|
|||||
110 | $count++; |
||||
111 | $count_global++; |
||||
112 | |||||
113 | // Content |
||||
0 ignored issues
–
show
|
|||||
114 | if ( 'full' === $display ) { |
||||
0 ignored issues
–
show
|
|||||
115 | $content = apply_filters( 'the_content', get_the_content() ); |
||||
116 | $content = str_replace( ']]>', ']]>', $content ); |
||||
117 | } elseif ( 'excerpt' === $display ) { |
||||
0 ignored issues
–
show
|
|||||
118 | $content = apply_filters( 'the_excerpt', get_the_excerpt() ); |
||||
119 | } |
||||
120 | |||||
121 | // Image |
||||
0 ignored issues
–
show
|
|||||
122 | if ( 'true' === $show_image || true === $show_image ) { |
||||
0 ignored issues
–
show
|
|||||
123 | if ( is_numeric( $size ) ) { |
||||
0 ignored issues
–
show
|
|||||
124 | $thumb_size = array( $size, $size ); |
||||
125 | } else { |
||||
126 | $thumb_size = $size; |
||||
127 | } |
||||
128 | |||||
129 | if ( ! empty( get_the_post_thumbnail( $post->ID ) ) ) { |
||||
0 ignored issues
–
show
|
|||||
130 | $image = get_the_post_thumbnail( $post->ID, $thumb_size, array( |
||||
0 ignored issues
–
show
|
|||||
131 | 'class' => $responsive, |
||||
132 | ) ); |
||||
0 ignored issues
–
show
For multi-line function calls, the closing parenthesis should be on a new line.
If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line: someFunctionCall(
$firstArgument,
$secondArgument,
$thirdArgument
); // Closing parenthesis on a new line.
![]() |
|||||
133 | } else { |
||||
134 | $image = ''; |
||||
135 | } |
||||
136 | |||||
137 | if ( empty( $image ) ) { |
||||
0 ignored issues
–
show
|
|||||
138 | if ( ! empty( $this->options['display']['projects_placeholder'] ) ) { |
||||
0 ignored issues
–
show
|
|||||
139 | $image = '<img class="' . $responsive . '" src="' . $this->options['display']['projects_placeholder'] . '" width="' . $size . '" alt="placeholder" />'; |
||||
140 | } else { |
||||
141 | $image = ''; |
||||
142 | } |
||||
143 | } |
||||
144 | } else { |
||||
145 | $image = ''; |
||||
146 | } |
||||
147 | |||||
148 | // Project groups |
||||
0 ignored issues
–
show
|
|||||
149 | $groups = ''; |
||||
150 | $terms = get_the_terms( $post->ID, 'project-group' ); |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
151 | |||||
152 | if ( $terms && ! is_wp_error( $terms ) ) { |
||||
0 ignored issues
–
show
|
|||||
153 | $groups = array(); |
||||
154 | |||||
155 | foreach ( $terms as $term ) { |
||||
0 ignored issues
–
show
|
|||||
156 | $groups[] = $term->name; |
||||
157 | } |
||||
158 | |||||
159 | $groups = join( ', ', $groups ); |
||||
160 | } |
||||
161 | |||||
162 | $project_groups = '' !== $groups ? "<p class='lsx-projects-groups'>$groups</p>" : ''; |
||||
163 | |||||
164 | if ( 'true' === $carousel || true === $carousel ) { |
||||
0 ignored issues
–
show
|
|||||
165 | $output .= " |
||||
166 | <div class='lsx-projects-slot'> |
||||
167 | " . ( ! empty( $image ) ? "<a href='" . get_permalink() . "'><figure class='lsx-projects-avatar'>$image</figure></a>" : '' ) . " |
||||
0 ignored issues
–
show
Are you sure
get_permalink() of type false|string can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
168 | <h5 class='lsx-projects-title'><a href='" . get_permalink() . "'>" . apply_filters( 'the_title', $post->post_title ) . "</a></h5> |
||||
169 | $project_groups |
||||
170 | <div class='lsx-projects-content'><a href='" . get_permalink() . "' class='moretag'>" . esc_html__( 'View more', 'lsx-projects' ) . '</a></div> |
||||
171 | </div>'; |
||||
172 | } elseif ( $columns >= 1 && $columns <= 4 ) { |
||||
0 ignored issues
–
show
|
|||||
173 | $md_col_width = 12 / $columns; |
||||
174 | |||||
175 | $output .= " |
||||
176 | <div class='col-xs-12 col-md-" . $md_col_width . "'> |
||||
177 | <div class='lsx-projects-slot'> |
||||
178 | " . ( ! empty( $image ) ? "<a href='" . get_permalink() . "'><figure class='lsx-projects-avatar'>$image</figure></a>" : '' ) . " |
||||
179 | <h5 class='lsx-projects-title'><a href='" . get_permalink() . "'>" . apply_filters( 'the_title', $post->post_title ) . "</a></h5> |
||||
180 | $project_groups |
||||
181 | <div class='lsx-projects-content'><a href='" . get_permalink() . "' class='moretag'>" . esc_html__( 'View more', 'lsx-projects' ) . '</a></div> |
||||
182 | </div> |
||||
183 | </div>'; |
||||
184 | |||||
185 | if ( $count == $columns && $projects->post_count > $count_global ) { |
||||
0 ignored issues
–
show
|
|||||
186 | $output .= '</div>'; |
||||
187 | $output .= "<div class='row'>"; |
||||
188 | $count = 0; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||||
189 | } |
||||
190 | } else { |
||||
191 | $output .= " |
||||
192 | <p class='bg-warning' style='padding: 20px;'> |
||||
193 | " . esc_html__( 'Invalid number of columns set. LSX Projects supports 1 to 4 columns.', 'lsx-projects' ) . ' |
||||
194 | </p>'; |
||||
195 | } |
||||
196 | |||||
197 | wp_reset_postdata(); |
||||
198 | } |
||||
199 | |||||
200 | if ( 'true' !== $carousel && true !== $carousel ) { |
||||
0 ignored issues
–
show
|
|||||
201 | $output .= '</div>'; |
||||
202 | } |
||||
203 | |||||
204 | $output .= '</div>'; |
||||
205 | |||||
206 | return $output; |
||||
207 | } |
||||
208 | } |
||||
0 ignored issues
–
show
|
|||||
209 | |||||
210 | } |
||||
211 | |||||
212 | global $lsx_projects; |
||||
213 | $lsx_projects = new LSX_Projects(); |
||||
214 |