1 | <?php |
||||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||||
2 | |||||
3 | $lsx_team_scporder = new LSX_TEAM_SCPO_Engine(); |
||||
4 | |||||
5 | /** |
||||
6 | * SCPO Engine |
||||
7 | * |
||||
8 | * @package LSX Team |
||||
9 | * @author LightSpeed |
||||
10 | * @license GPL3 |
||||
11 | * @link |
||||
12 | * @copyright 2018 LightSpeed |
||||
13 | */ |
||||
14 | class LSX_TEAM_SCPO_Engine { |
||||
15 | |||||
16 | public function __construct() { |
||||
0 ignored issues
–
show
|
|||||
17 | if ( ! get_option( 'lsx_team_scporder_install' ) ) |
||||
0 ignored issues
–
show
|
|||||
18 | $this->lsx_team_scporder_install(); |
||||
19 | |||||
20 | add_action( 'admin_init', array( $this, 'refresh' ) ); |
||||
21 | add_action( 'admin_init', array( $this, 'load_script_css' ) ); |
||||
22 | |||||
23 | add_action( 'wp_ajax_update-menu-order', array( $this, 'update_menu_order' ) ); |
||||
24 | add_action( 'wp_ajax_update-menu-order-tags', array( $this, 'update_menu_order_tags' ) ); |
||||
25 | |||||
26 | add_action( 'pre_get_posts', array( $this, 'lsx_team_scporder_pre_get_posts' ) ); |
||||
27 | |||||
28 | add_filter( 'get_previous_post_where', array( $this, 'lsx_team_scporder_previous_post_where' ) ); |
||||
29 | add_filter( 'get_previous_post_sort', array( $this, 'lsx_team_scporder_previous_post_sort' ) ); |
||||
30 | add_filter( 'get_next_post_where', array( $this, 'lsx_team_scporder_next_post_where' ) ); |
||||
31 | add_filter( 'get_next_post_sort', array( $this, 'lsx_team_scporder_next_post_sort' ) ); |
||||
32 | |||||
33 | add_filter( 'get_terms_orderby', array( $this, 'lsx_team_scporder_get_terms_orderby' ), 10, 3 ); |
||||
34 | add_filter( 'wp_get_object_terms', array( $this, 'lsx_team_scporder_get_object_terms' ), 10, 3 ); |
||||
35 | add_filter( 'get_terms', array( $this, 'lsx_team_scporder_get_object_terms' ), 10, 3 ); |
||||
36 | } |
||||
0 ignored issues
–
show
|
|||||
37 | |||||
38 | public function lsx_team_scporder_install() { |
||||
0 ignored issues
–
show
|
|||||
39 | global $wpdb; |
||||
40 | $result = $wpdb->query( "DESCRIBE $wpdb->terms `lsx_team_term_order`" ); |
||||
0 ignored issues
–
show
|
|||||
41 | |||||
42 | if ( ! $result ) { |
||||
0 ignored issues
–
show
|
|||||
43 | $result = $wpdb->query( "ALTER TABLE $wpdb->terms ADD `lsx_team_term_order` INT( 4 ) NULL DEFAULT '0'" ); |
||||
0 ignored issues
–
show
|
|||||
44 | } |
||||
45 | |||||
46 | update_option( 'lsx_team_scporder_install', 1 ); |
||||
47 | } |
||||
0 ignored issues
–
show
|
|||||
48 | |||||
49 | public function _check_load_script_css() { |
||||
0 ignored issues
–
show
|
|||||
50 | $active = false; |
||||
51 | |||||
52 | $objects = $this->get_lsx_team_scporder_options_objects(); |
||||
53 | $tags = $this->get_lsx_team_scporder_options_tags(); |
||||
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. ![]() |
|||||
54 | |||||
55 | if ( empty( $objects ) && empty( $tags ) ) |
||||
0 ignored issues
–
show
|
|||||
56 | return false; |
||||
57 | |||||
58 | if ( isset( $_GET['orderby'] ) || strstr( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'action=edit' ) || strstr( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'wp-admin/post-new.php' ) ) |
||||
0 ignored issues
–
show
It seems like
wp_unslash($_SERVER['REQUEST_URI']) can also be of type array ; however, parameter $str of sanitize_text_field() 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
![]() |
|||||
59 | return false; |
||||
60 | |||||
61 | if ( ! empty( $objects ) ) { |
||||
0 ignored issues
–
show
|
|||||
62 | if ( isset( $_GET['post_type'] ) && ! isset( $_GET['taxonomy'] ) && array_key_exists( sanitize_text_field( wp_unslash( $_GET['post_type'] ) ), $objects ) ) { // if page or custom post types. |
||||
0 ignored issues
–
show
|
|||||
63 | $active = true; |
||||
64 | } |
||||
0 ignored issues
–
show
|
|||||
65 | if ( ! isset( $_GET['post_type'] ) && strstr( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ), 'wp-admin/edit.php' ) && array_key_exists( 'post', $objects ) ) { // if post. |
||||
0 ignored issues
–
show
|
|||||
66 | $active = true; |
||||
67 | } |
||||
68 | } |
||||
69 | |||||
70 | if ( ! empty( $tags ) ) { |
||||
0 ignored issues
–
show
|
|||||
71 | if ( isset( $_GET['taxonomy'] ) && array_key_exists( sanitize_text_field( wp_unslash( $_GET['taxonomy'] ) ), $tags ) ) { |
||||
0 ignored issues
–
show
|
|||||
72 | $active = true; |
||||
73 | } |
||||
74 | } |
||||
75 | |||||
76 | return $active; |
||||
77 | } |
||||
0 ignored issues
–
show
|
|||||
78 | |||||
79 | public function load_script_css() { |
||||
0 ignored issues
–
show
|
|||||
80 | if ( $this->_check_load_script_css() ) { |
||||
0 ignored issues
–
show
|
|||||
81 | wp_enqueue_script( 'scporderjs', LSX_TEAM_URL . 'assets/js/scporder.min.js', array( 'jquery', 'jquery-ui-sortable' ), null, true ); |
||||
0 ignored issues
–
show
|
|||||
82 | |||||
83 | $scporderjs_params = array( |
||||
84 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
||||
0 ignored issues
–
show
|
|||||
85 | 'ajax_nonce' => wp_create_nonce( 'scporder' ), |
||||
86 | ); |
||||
0 ignored issues
–
show
|
|||||
87 | |||||
88 | wp_localize_script( 'scporderjs', 'scporderjs_params', $scporderjs_params ); |
||||
89 | |||||
90 | wp_enqueue_style( 'scporder', LSX_TEAM_URL . 'assets/css/scporder.css', array(), null ); |
||||
0 ignored issues
–
show
|
|||||
91 | } |
||||
92 | } |
||||
0 ignored issues
–
show
|
|||||
93 | |||||
94 | public function refresh() { |
||||
0 ignored issues
–
show
|
|||||
95 | global $wpdb; |
||||
96 | $objects = $this->get_lsx_team_scporder_options_objects(); |
||||
97 | $tags = $this->get_lsx_team_scporder_options_tags(); |
||||
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. ![]() |
|||||
98 | |||||
99 | if ( ! empty( $objects ) ) { |
||||
0 ignored issues
–
show
|
|||||
100 | foreach ( $objects as $object => $object_data ) { |
||||
0 ignored issues
–
show
|
|||||
101 | $result = $wpdb->get_results( $wpdb->prepare( " |
||||
0 ignored issues
–
show
|
|||||
102 | SELECT count( * ) as cnt, max( menu_order ) as max, min( menu_order ) as min |
||||
103 | FROM $wpdb->posts |
||||
104 | WHERE post_type = '%s' AND post_status IN ( 'publish', 'pending', 'draft', 'private', 'future' ) |
||||
0 ignored issues
–
show
|
|||||
105 | ", $object ) ); |
||||
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.
![]() |
|||||
106 | |||||
107 | if ( 0 == $result[0]->cnt || $result[0]->cnt == $result[0]->max ) |
||||
0 ignored issues
–
show
|
|||||
108 | continue; |
||||
109 | |||||
110 | $results = $wpdb->get_results( $wpdb->prepare( " |
||||
0 ignored issues
–
show
|
|||||
111 | SELECT ID |
||||
112 | FROM $wpdb->posts |
||||
113 | WHERE post_type = '%s' AND post_status IN ( 'publish', 'pending', 'draft', 'private', 'future' ) |
||||
0 ignored issues
–
show
|
|||||
114 | ORDER BY menu_order ASC |
||||
115 | ", $object ) ); |
||||
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.
![]() |
|||||
116 | |||||
117 | foreach ( $results as $key => $result ) { |
||||
0 ignored issues
–
show
|
|||||
118 | $wpdb->update( $wpdb->posts, |
||||
0 ignored issues
–
show
|
|||||
119 | array( |
||||
120 | 'menu_order' => $key + 1, |
||||
121 | ), |
||||
122 | array( |
||||
123 | 'ID' => $result->ID, |
||||
124 | ) |
||||
125 | ); |
||||
126 | } |
||||
127 | } |
||||
128 | } |
||||
129 | |||||
130 | if ( ! empty( $tags ) ) { |
||||
0 ignored issues
–
show
|
|||||
131 | foreach ( $tags as $taxonomy => $taxonomy_data ) { |
||||
0 ignored issues
–
show
|
|||||
132 | $result = $wpdb->get_results( $wpdb->prepare( " |
||||
0 ignored issues
–
show
|
|||||
133 | SELECT count( * ) as cnt, max( lsx_team_term_order ) as max, min( lsx_team_term_order ) as min |
||||
134 | FROM $wpdb->terms AS terms |
||||
135 | INNER JOIN $wpdb->term_taxonomy AS term_taxonomy ON ( terms.term_id = term_taxonomy.term_id ) |
||||
136 | WHERE term_taxonomy.taxonomy = '%s' |
||||
0 ignored issues
–
show
|
|||||
137 | ", $taxonomy ) ); |
||||
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.
![]() |
|||||
138 | |||||
139 | if ( 0 == $result[0]->cnt || $result[0]->cnt == $result[0]->max ) |
||||
0 ignored issues
–
show
|
|||||
140 | continue; |
||||
141 | |||||
142 | $results = $wpdb->get_results( $wpdb->prepare( " |
||||
0 ignored issues
–
show
|
|||||
143 | SELECT terms.term_id |
||||
144 | FROM $wpdb->terms AS terms |
||||
145 | INNER JOIN $wpdb->term_taxonomy AS term_taxonomy ON ( terms.term_id = term_taxonomy.term_id ) |
||||
146 | WHERE term_taxonomy.taxonomy = '%s' |
||||
0 ignored issues
–
show
|
|||||
147 | ORDER BY lsx_team_term_order ASC |
||||
148 | ", $taxonomy ) ); |
||||
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.
![]() |
|||||
149 | |||||
150 | foreach ( $results as $key => $result ) { |
||||
0 ignored issues
–
show
|
|||||
151 | $wpdb->update( |
||||
0 ignored issues
–
show
|
|||||
152 | $wpdb->terms, |
||||
153 | array( |
||||
154 | 'lsx_team_term_order' => $key + 1, |
||||
155 | ), |
||||
156 | array( |
||||
157 | 'term_id' => $result->term_id, |
||||
158 | ) |
||||
159 | ); |
||||
160 | } |
||||
161 | } |
||||
162 | } |
||||
163 | } |
||||
0 ignored issues
–
show
|
|||||
164 | |||||
165 | public function update_menu_order() { |
||||
0 ignored issues
–
show
|
|||||
166 | check_ajax_referer( 'scporder', 'security' ); |
||||
167 | |||||
168 | global $wpdb; |
||||
169 | |||||
170 | parse_str( sanitize_text_field( wp_unslash( $_POST['order'] ) ), $data ); |
||||
0 ignored issues
–
show
|
|||||
171 | |||||
172 | if ( ! is_array( $data ) ) |
||||
0 ignored issues
–
show
|
|||||
173 | return false; |
||||
174 | |||||
175 | $id_arr = array(); |
||||
176 | |||||
177 | foreach ( $data as $key => $values ) { |
||||
0 ignored issues
–
show
|
|||||
178 | foreach ( $values as $position => $id ) { |
||||
0 ignored issues
–
show
|
|||||
179 | $id_arr[] = $id; |
||||
180 | } |
||||
181 | } |
||||
182 | |||||
183 | $menu_order_arr = array(); |
||||
184 | |||||
185 | foreach ( $id_arr as $key => $id ) { |
||||
0 ignored issues
–
show
|
|||||
186 | $results = $wpdb->get_results( "SELECT menu_order FROM $wpdb->posts WHERE ID = " . intval( $id ) ); |
||||
0 ignored issues
–
show
|
|||||
187 | foreach ( $results as $result ) { |
||||
0 ignored issues
–
show
|
|||||
188 | $menu_order_arr[] = $result->menu_order; |
||||
189 | } |
||||
190 | } |
||||
191 | |||||
192 | sort( $menu_order_arr ); |
||||
193 | |||||
194 | foreach ( $data as $key => $values ) { |
||||
0 ignored issues
–
show
|
|||||
195 | foreach ( $values as $position => $id ) { |
||||
0 ignored issues
–
show
|
|||||
196 | $wpdb->update( $wpdb->posts, |
||||
0 ignored issues
–
show
|
|||||
197 | array( |
||||
198 | 'menu_order' => $menu_order_arr[ $position ], |
||||
199 | ), |
||||
200 | array( |
||||
201 | 'ID' => intval( $id ), |
||||
202 | ) |
||||
203 | ); |
||||
204 | } |
||||
205 | } |
||||
206 | } |
||||
0 ignored issues
–
show
|
|||||
207 | |||||
208 | public function update_menu_order_tags() { |
||||
0 ignored issues
–
show
|
|||||
209 | check_ajax_referer( 'scporder', 'security' ); |
||||
210 | |||||
211 | global $wpdb; |
||||
212 | |||||
213 | parse_str( sanitize_text_field( wp_unslash( $_POST['order'] ) ), $data ); |
||||
0 ignored issues
–
show
|
|||||
214 | |||||
215 | if ( ! is_array( $data ) ) |
||||
0 ignored issues
–
show
|
|||||
216 | return false; |
||||
217 | |||||
218 | $id_arr = array(); |
||||
219 | |||||
220 | foreach ( $data as $key => $values ) { |
||||
0 ignored issues
–
show
|
|||||
221 | foreach ( $values as $position => $id ) { |
||||
0 ignored issues
–
show
|
|||||
222 | $id_arr[] = $id; |
||||
223 | } |
||||
224 | } |
||||
225 | |||||
226 | $menu_order_arr = array(); |
||||
227 | |||||
228 | foreach ( $id_arr as $key => $id ) { |
||||
0 ignored issues
–
show
|
|||||
229 | $results = $wpdb->get_results( " |
||||
0 ignored issues
–
show
|
|||||
230 | SELECT lsx_team_term_order |
||||
231 | FROM $wpdb->terms |
||||
232 | WHERE term_id = " . intval( $id ) ); |
||||
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.
![]() |
|||||
233 | foreach ( $results as $result ) { |
||||
0 ignored issues
–
show
|
|||||
234 | $menu_order_arr[] = $result->lsx_team_term_order; |
||||
235 | } |
||||
236 | } |
||||
237 | |||||
238 | sort( $menu_order_arr ); |
||||
239 | |||||
240 | foreach ( $data as $key => $values ) { |
||||
0 ignored issues
–
show
|
|||||
241 | foreach ( $values as $position => $id ) { |
||||
0 ignored issues
–
show
|
|||||
242 | $wpdb->update( $wpdb->terms, |
||||
0 ignored issues
–
show
|
|||||
243 | array( |
||||
244 | 'lsx_team_term_order' => $menu_order_arr[ $position ], |
||||
245 | ), |
||||
246 | array( |
||||
247 | 'term_id' => intval( $id ), |
||||
248 | ) |
||||
249 | ); |
||||
250 | } |
||||
251 | } |
||||
252 | } |
||||
0 ignored issues
–
show
|
|||||
253 | |||||
254 | public function lsx_team_scporder_previous_post_where( $where ) { |
||||
0 ignored issues
–
show
|
|||||
255 | global $post; |
||||
256 | $objects = $this->get_lsx_team_scporder_options_objects(); |
||||
257 | |||||
258 | if ( empty( $objects ) ) |
||||
0 ignored issues
–
show
|
|||||
259 | return $where; |
||||
260 | |||||
261 | if ( isset( $post->post_type ) && array_key_exists( $post->post_type, $objects ) ) { |
||||
0 ignored issues
–
show
|
|||||
262 | $current_menu_order = $post->menu_order; |
||||
263 | $where = "WHERE p.menu_order > '" . $current_menu_order . "' AND p.post_type = '" . $post->post_type . "' AND p.post_status = 'publish'"; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 14 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. ![]() |
|||||
264 | } |
||||
265 | |||||
266 | return $where; |
||||
267 | } |
||||
0 ignored issues
–
show
|
|||||
268 | |||||
269 | public function lsx_team_scporder_previous_post_sort( $orderby ) { |
||||
0 ignored issues
–
show
|
|||||
270 | global $post; |
||||
271 | $objects = $this->get_lsx_team_scporder_options_objects(); |
||||
272 | |||||
273 | if ( empty( $objects ) ) |
||||
0 ignored issues
–
show
|
|||||
274 | return $orderby; |
||||
275 | |||||
276 | if ( isset( $post->post_type ) && array_key_exists( $post->post_type, $objects ) ) { |
||||
0 ignored issues
–
show
|
|||||
277 | $orderby = 'ORDER BY p.menu_order ASC LIMIT 1'; |
||||
278 | } |
||||
279 | |||||
280 | return $orderby; |
||||
281 | } |
||||
0 ignored issues
–
show
|
|||||
282 | |||||
283 | public function lsx_team_scporder_next_post_where( $where ) { |
||||
0 ignored issues
–
show
|
|||||
284 | global $post; |
||||
285 | $objects = $this->get_lsx_team_scporder_options_objects(); |
||||
286 | |||||
287 | if ( empty( $objects ) ) |
||||
0 ignored issues
–
show
|
|||||
288 | return $where; |
||||
289 | |||||
290 | if ( isset( $post->post_type ) && array_key_exists( $post->post_type, $objects ) ) { |
||||
0 ignored issues
–
show
|
|||||
291 | $current_menu_order = $post->menu_order; |
||||
292 | $where = "WHERE p.menu_order < '" . $current_menu_order . "' AND p.post_type = '" . $post->post_type . "' AND p.post_status = 'publish'"; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 14 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. ![]() |
|||||
293 | } |
||||
294 | |||||
295 | return $where; |
||||
296 | } |
||||
0 ignored issues
–
show
|
|||||
297 | |||||
298 | public function lsx_team_scporder_next_post_sort( $orderby ) { |
||||
0 ignored issues
–
show
|
|||||
299 | global $post; |
||||
300 | $objects = $this->get_lsx_team_scporder_options_objects(); |
||||
301 | |||||
302 | if ( empty( $objects ) ) |
||||
0 ignored issues
–
show
|
|||||
303 | return $orderby; |
||||
304 | |||||
305 | if ( isset( $post->post_type ) && array_key_exists( $post->post_type, $objects ) ) { |
||||
0 ignored issues
–
show
|
|||||
306 | $orderby = 'ORDER BY p.menu_order DESC LIMIT 1'; |
||||
307 | } |
||||
308 | |||||
309 | return $orderby; |
||||
310 | } |
||||
0 ignored issues
–
show
|
|||||
311 | |||||
312 | public function lsx_team_scporder_pre_get_posts( $wp_query ) { |
||||
0 ignored issues
–
show
|
|||||
313 | $objects = $this->get_lsx_team_scporder_options_objects(); |
||||
314 | |||||
315 | if ( empty( $objects ) ) |
||||
0 ignored issues
–
show
|
|||||
316 | return false; |
||||
317 | |||||
318 | if ( is_admin() ) { |
||||
0 ignored issues
–
show
|
|||||
319 | if ( isset( $wp_query->query['post_type'] ) && ! isset( $_GET['orderby'] ) ) { |
||||
0 ignored issues
–
show
|
|||||
320 | if ( array_key_exists( $wp_query->query['post_type'], $objects ) ) { |
||||
0 ignored issues
–
show
|
|||||
321 | $wp_query->set( 'orderby', 'menu_order' ); |
||||
322 | $wp_query->set( 'order', 'ASC' ); |
||||
323 | } |
||||
324 | } |
||||
325 | } else { |
||||
326 | $active = false; |
||||
327 | |||||
328 | if ( isset( $wp_query->query['post_type'] ) ) { |
||||
0 ignored issues
–
show
|
|||||
329 | if ( ! is_array( $wp_query->query['post_type'] ) ) { |
||||
0 ignored issues
–
show
|
|||||
330 | if ( array_key_exists( $wp_query->query['post_type'], $objects ) ) { |
||||
0 ignored issues
–
show
|
|||||
331 | $active = true; |
||||
332 | } |
||||
333 | } |
||||
334 | } else { |
||||
335 | if ( array_key_exists( 'post', $objects ) ) { |
||||
0 ignored issues
–
show
|
|||||
336 | $active = true; |
||||
337 | } |
||||
338 | } |
||||
339 | |||||
340 | if ( ! $active ) |
||||
0 ignored issues
–
show
|
|||||
341 | return false; |
||||
342 | |||||
343 | if ( isset( $wp_query->query['suppress_filters'] ) ) { |
||||
0 ignored issues
–
show
|
|||||
344 | if ( $wp_query->get( 'orderby' ) == 'date' ) |
||||
0 ignored issues
–
show
|
|||||
345 | $wp_query->set( 'orderby', 'menu_order' ); |
||||
346 | if ( $wp_query->get( 'order' ) == 'DESC' ) |
||||
0 ignored issues
–
show
|
|||||
347 | $wp_query->set( 'order', 'ASC' ); |
||||
348 | } else { |
||||
349 | if ( ! $wp_query->get( 'orderby' ) ) |
||||
0 ignored issues
–
show
|
|||||
350 | $wp_query->set( 'orderby', 'menu_order' ); |
||||
351 | if ( ! $wp_query->get( 'order' ) ) |
||||
0 ignored issues
–
show
|
|||||
352 | $wp_query->set( 'order', 'ASC' ); |
||||
353 | } |
||||
354 | } |
||||
355 | } |
||||
0 ignored issues
–
show
|
|||||
356 | |||||
357 | public function lsx_team_scporder_get_terms_orderby( $orderby, $args ) { |
||||
0 ignored issues
–
show
|
|||||
358 | if ( is_admin() ) |
||||
0 ignored issues
–
show
|
|||||
359 | return $orderby; |
||||
360 | |||||
361 | $tags = $this->get_lsx_team_scporder_options_tags(); |
||||
362 | |||||
363 | if ( ! isset( $args['taxonomy'] ) ) |
||||
0 ignored issues
–
show
|
|||||
364 | return $orderby; |
||||
365 | |||||
366 | $taxonomy = $args['taxonomy']; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 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. ![]() |
|||||
367 | if ( is_array( $taxonomy ) && count( $taxonomy ) == 1 ) |
||||
0 ignored issues
–
show
|
|||||
368 | $taxonomy = $taxonomy[0]; |
||||
369 | if ( ! array_key_exists( $taxonomy[0], $tags ) ) |
||||
370 | return $orderby; |
||||
371 | |||||
372 | $orderby = 't.lsx_team_term_order'; |
||||
373 | return $orderby; |
||||
374 | } |
||||
0 ignored issues
–
show
|
|||||
375 | |||||
376 | public function lsx_team_scporder_get_object_terms( $terms ) { |
||||
0 ignored issues
–
show
|
|||||
377 | $tags = $this->get_lsx_team_scporder_options_tags(); |
||||
378 | |||||
379 | if ( is_admin() && isset( $_GET['orderby'] ) ) |
||||
0 ignored issues
–
show
|
|||||
380 | return $terms; |
||||
381 | |||||
382 | foreach ( $terms as $key => $term ) { |
||||
0 ignored issues
–
show
|
|||||
383 | if ( is_object( $term ) && isset( $term->taxonomy ) ) { |
||||
0 ignored issues
–
show
|
|||||
384 | $taxonomy = $term->taxonomy; |
||||
385 | if ( ! array_key_exists( $taxonomy, $tags ) ) |
||||
0 ignored issues
–
show
|
|||||
386 | return $terms; |
||||
387 | } else { |
||||
388 | return $terms; |
||||
389 | } |
||||
390 | } |
||||
391 | |||||
392 | usort( $terms, array( $this, 'taxcmp' ) ); |
||||
393 | return $terms; |
||||
394 | } |
||||
0 ignored issues
–
show
|
|||||
395 | |||||
396 | public function taxcmp( $a, $b ) { |
||||
0 ignored issues
–
show
|
|||||
397 | if ( $a->lsx_team_term_order == $b->lsx_team_term_order ) |
||||
0 ignored issues
–
show
|
|||||
398 | return 0; |
||||
399 | |||||
400 | return ( $a->lsx_team_term_order < $b->lsx_team_term_order ) ? -1 : 1; |
||||
401 | } |
||||
0 ignored issues
–
show
|
|||||
402 | |||||
403 | public function get_lsx_team_scporder_options_objects() { |
||||
0 ignored issues
–
show
|
|||||
404 | return array( |
||||
405 | 'team' => esc_html_x( 'Team Member', 'post type singular name', 'lsx-team' ), |
||||
406 | ); |
||||
407 | } |
||||
0 ignored issues
–
show
|
|||||
408 | |||||
409 | public function get_lsx_team_scporder_options_tags() { |
||||
0 ignored issues
–
show
|
|||||
410 | return array( |
||||
411 | 'team_role' => esc_html_x( 'Role', 'taxonomy singular name', 'lsx-team' ), |
||||
412 | ); |
||||
413 | } |
||||
0 ignored issues
–
show
|
|||||
414 | |||||
415 | } |
||||
416 | |||||
417 | /** |
||||
418 | * SCP Order Uninstall hook |
||||
419 | */ |
||||
420 | register_uninstall_hook( __FILE__, 'lsx_team_scporder_uninstall' ); |
||||
421 | |||||
422 | function lsx_team_scporder_uninstall() { |
||||
0 ignored issues
–
show
|
|||||
423 | global $wpdb; |
||||
424 | |||||
425 | if ( function_exists( 'is_multisite' ) && is_multisite() ) { |
||||
0 ignored issues
–
show
|
|||||
426 | $curr_blog = $wpdb->blogid; |
||||
427 | $blogids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
||||
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. ![]() |
|||||
428 | |||||
429 | foreach ( $blogids as $blog_id ) { |
||||
0 ignored issues
–
show
|
|||||
430 | switch_to_blog( $blog_id ); |
||||
431 | lsx_team_scporder_uninstall_db(); |
||||
432 | } |
||||
433 | |||||
434 | switch_to_blog( $curr_blog ); |
||||
435 | } else { |
||||
436 | lsx_team_scporder_uninstall_db(); |
||||
437 | } |
||||
438 | } |
||||
0 ignored issues
–
show
|
|||||
439 | |||||
440 | function lsx_team_scporder_uninstall_db() { |
||||
0 ignored issues
–
show
|
|||||
441 | global $wpdb; |
||||
442 | $result = $wpdb->query( "DESCRIBE $wpdb->terms `lsx_team_term_order`" ); |
||||
0 ignored issues
–
show
|
|||||
443 | |||||
444 | if ( $result ) { |
||||
0 ignored issues
–
show
|
|||||
445 | $result = $wpdb->query( "ALTER TABLE $wpdb->terms DROP `lsx_team_term_order`" ); |
||||
0 ignored issues
–
show
|
|||||
446 | } |
||||
447 | |||||
448 | delete_option( 'lsx_team_scporder_install' ); |
||||
449 | } |
||||
0 ignored issues
–
show
|
|||||
450 |