This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | /** |
||
3 | * Vendor functions |
||
4 | * |
||
5 | * @package PrintCenter\Vendor\Functions |
||
6 | * @since 1.0.0 |
||
7 | */ |
||
8 | |||
9 | |||
10 | // Exit if accessed directly |
||
11 | if( ! defined( 'ABSPATH' ) ) { |
||
12 | exit; |
||
13 | } |
||
14 | |||
15 | |||
16 | /** |
||
17 | * Get all vendors |
||
18 | * |
||
19 | * @since 1.0.0 |
||
20 | * @global object $woo_vendors The vendors object |
||
21 | * @return array $vendors_array Array of vendors |
||
22 | */ |
||
23 | function printcenter_get_vendors() { |
||
24 | global $woo_vendors; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
25 | |||
26 | $vendors_array = false; |
||
27 | |||
28 | $args = array( |
||
29 | 'hide_empty' => false |
||
30 | ); |
||
31 | |||
32 | $vendors = get_terms( $woo_vendors->token, $args ); |
||
33 | |||
34 | if( is_array( $vendors ) && count( $vendors ) > 0 ) { |
||
35 | foreach ( $vendors as $vendor ) { |
||
36 | if( isset( $vendor->term_id ) ) { |
||
37 | $vendor_data = printcenter_get_vendor( $vendor->term_id ); |
||
38 | |||
39 | if( $vendor_data ) { |
||
40 | $vendors_array[] = $vendor_data; |
||
41 | } |
||
42 | } |
||
43 | } |
||
44 | } |
||
45 | |||
46 | return $vendors_array; |
||
47 | } |
||
48 | |||
49 | |||
50 | /** |
||
51 | * Get individual vendor by ID |
||
52 | * |
||
53 | * @since 1.0.0 |
||
54 | * @param int $vendor_id ID of the vendor |
||
55 | * @global object $woo_vendors The vendors object |
||
56 | * @return object $vendor The vendor object |
||
57 | */ |
||
58 | function printcenter_get_vendor( $vendor_id = 0 ) { |
||
59 | global $woo_vendors; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
60 | |||
61 | $vendor = false; |
||
62 | |||
63 | if( $vendor_id > 0 ) { |
||
64 | // Get vendor info |
||
65 | $vendor_data = get_term( $vendor_id, $woo_vendors->token ); |
||
66 | $vendor_info = get_option( $woo_vendors->token . '_' . $vendor_id ); |
||
67 | |||
68 | // Set up vendor object |
||
69 | $vendor = new stdClass(); |
||
70 | |||
71 | if( is_object( $vendor_data ) && count( $vendor_data ) > 0 && isset( $vendor_data->term_id ) ) { |
||
72 | $vendor->ID = $vendor_data->term_id; |
||
73 | $vendor->title = $vendor_data->name; |
||
74 | $vendor->slug = $vendor_data->slug; |
||
75 | $vendor->description = $vendor_data->description; |
||
76 | $vendor->url = get_term_link( $vendor_data, $woo_vendors->token ); |
||
77 | } |
||
78 | |||
79 | if( is_array( $vendor_info ) && count( $vendor_info ) > 0 ) { |
||
80 | foreach( $vendor_info as $key => $value ) { |
||
81 | $vendor->$key = $vendor_info[ $key ]; |
||
82 | } |
||
83 | } |
||
84 | |||
85 | $vendor->admins = printcenter_get_vendor_admins( $vendor_id ); |
||
86 | } |
||
87 | |||
88 | return $vendor; |
||
89 | } |
||
90 | |||
91 | |||
92 | /** |
||
93 | * Get vendors for product |
||
94 | * |
||
95 | * @since 1.0.0 |
||
96 | * @param int $product_id Product ID |
||
97 | * @global object $woo_vendors The vendors object |
||
98 | * @return array $vendors Array of product vendors |
||
99 | */ |
||
100 | function printcenter_get_product_vendors( $product_id = 0 ) { |
||
101 | global $woo_vendors; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
102 | |||
103 | $vendors = false; |
||
104 | |||
105 | if( $product_id > 0 ) { |
||
106 | $vendors_data = wp_get_post_terms( $product_id, $woo_vendors->token ); |
||
107 | foreach( $vendors_data as $vendor_data ) { |
||
108 | $vendor = printcenter_get_vendor( $vendor_data->term_id ); |
||
109 | |||
110 | if( $vendor ) { |
||
111 | $vendors[] = $vendor; |
||
112 | } |
||
113 | } |
||
114 | } |
||
115 | |||
116 | return $vendors; |
||
117 | } |
||
118 | |||
119 | |||
120 | /** |
||
121 | * Get assigned commission percentage |
||
122 | * |
||
123 | * @since 1.0.0 |
||
124 | * @param int $product_id ID of the product |
||
125 | * @param int $vendor_id ID of the vendor |
||
126 | * @global object $woo_vendors The vendors object |
||
127 | * @return int Relevent commission percentage |
||
128 | */ |
||
129 | function printcenter_get_commission_percent( $product_id = 0, $vendor_id = 0 ) { |
||
130 | global $woo_vendors; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
131 | |||
132 | // Use product commission percentage first |
||
133 | if( $product_id > 0 ) { |
||
134 | $data = get_post_meta( $product_id, '_product_vendors_commission', true ); |
||
135 | |||
136 | if( $data && strlen( $data ) > 0 ) { |
||
137 | return $data; |
||
138 | } |
||
139 | } |
||
140 | |||
141 | // Use vendor commission percentage if no product commission is specified |
||
142 | if( $vendor_id > 0 ) { |
||
143 | $vendor_data = get_option( $woo_vendors->token . '_' . $vendor_id ); |
||
144 | |||
145 | if( $vendor_data['commission'] && strlen( $vendor_data['commission'] ) > 0 && $vendor_data['commission'] != '' ) { |
||
146 | return $vendor_data['commission']; |
||
147 | } |
||
148 | } |
||
149 | |||
150 | // If no commission percentages are specified then default to base commission or fallback of 50% |
||
151 | $commission = intval( get_option( 'woocommerce_product_vendors_base_commission', 50 ) ); |
||
152 | |||
153 | // Account for potential issue of base commission being over 100% |
||
154 | if( $commission > 100 ) { |
||
155 | $commission = 100; |
||
156 | } |
||
157 | |||
158 | return $commission; |
||
159 | } |
||
160 | |||
161 | |||
162 | /** |
||
163 | * Get all commissions assigned to a specific vendor |
||
164 | * |
||
165 | * @since 1.0.0 |
||
166 | * @param int $vendor_id ID of vendor |
||
167 | * @param int $year Optional year to filter by |
||
168 | * @param int $month Optional month to filter by |
||
169 | * @param int $day Optional day to filter by |
||
170 | * @return array $commissions Array of commission post objects |
||
171 | */ |
||
172 | function printcenter_get_vendor_commissions( $vendor_id = 0, $year = false, $month = false, $day = false ) { |
||
173 | $commissions = false; |
||
174 | |||
175 | if( $vendor_id > 0 ) { |
||
176 | |||
177 | $args = array( |
||
178 | 'post_type' => 'shop_commission', |
||
179 | 'post_status' => array( 'publish', 'private' ), |
||
180 | 'posts_per_page' => -1, |
||
181 | 'meta_query' => array( |
||
182 | array( |
||
183 | 'key' => '_commission_vendor', |
||
184 | 'value' => $vendor_id, |
||
185 | 'compare' => '=' |
||
186 | ) |
||
187 | ) |
||
188 | ); |
||
189 | |||
190 | // Add date parameters if specified |
||
191 | if( $year ) { |
||
0 ignored issues
–
show
The expression
$year of type false|integer is loosely compared to true ; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For 0 == false // true
0 == null // true
123 == false // false
123 == null // false
// It is often better to use strict comparison
0 === false // false
0 === null // false
![]() |
|||
192 | $args['year'] = $year; |
||
193 | } |
||
194 | |||
195 | if( $month ) { |
||
0 ignored issues
–
show
The expression
$month of type false|integer is loosely compared to true ; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For 0 == false // true
0 == null // true
123 == false // false
123 == null // false
// It is often better to use strict comparison
0 === false // false
0 === null // false
![]() |
|||
196 | $args['monthnum'] = $month; |
||
197 | } |
||
198 | |||
199 | if( $day ) { |
||
0 ignored issues
–
show
The expression
$day of type false|integer is loosely compared to true ; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For 0 == false // true
0 == null // true
123 == false // false
123 == null // false
// It is often better to use strict comparison
0 === false // false
0 === null // false
![]() |
|||
200 | $args['day'] = $day; |
||
201 | } |
||
202 | |||
203 | $commissions = get_posts( $args ); |
||
204 | } |
||
205 | |||
206 | return $commissions; |
||
207 | } |
||
208 | |||
209 | |||
210 | /** |
||
211 | * Get all products belonging to vendor |
||
212 | * |
||
213 | * @since 1.0.0 |
||
214 | * @param int $vendor_id ID of vendor |
||
215 | * @global object $woo_vendors The vendors object |
||
216 | * @return array $products Array of product post objects |
||
217 | */ |
||
218 | function printcenter_get_vendor_products( $vendor_id = 0 ) { |
||
219 | global $woo_vendors; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
220 | |||
221 | $products = false; |
||
222 | |||
223 | if( $vendor_id > 0 ) { |
||
224 | $args = array( |
||
225 | 'post_type' => 'product', |
||
226 | 'post_status' => 'publish', |
||
227 | 'posts_per_page' => -1, |
||
228 | 'tax_query' => array( |
||
229 | array( |
||
230 | 'taxonomy' => $woo_vendors->token, |
||
231 | 'field' => 'id', |
||
232 | 'terms' => $vendor_id, |
||
233 | ) |
||
234 | ) |
||
235 | ); |
||
236 | |||
237 | $products = get_posts( $args ); |
||
238 | } |
||
239 | |||
240 | return $products; |
||
241 | } |
||
242 | |||
243 | |||
244 | /** |
||
245 | * Get vendor for which user is an admin |
||
246 | * |
||
247 | * @since 1.0.0 |
||
248 | * @param int $user_id ID of user |
||
249 | * @return object $vendor Vendor object |
||
250 | */ |
||
251 | function printcenter_get_user_vendor( $user_id = 0 ) { |
||
252 | if( $user_id == 0 ) { |
||
253 | global $current_user; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
254 | |||
255 | wp_get_current_user(); |
||
256 | |||
257 | $user_id = $current_user->ID; |
||
258 | } |
||
259 | |||
260 | $vendor = false; |
||
261 | |||
262 | if( $user_id > 0 ) { |
||
263 | $vendor_id = get_user_meta( $user_id, 'product_vendor', true ); |
||
264 | |||
265 | if( $vendor_id != '' ) { |
||
266 | $vendor = get_vendor( $vendor_id ); |
||
267 | } |
||
268 | } |
||
269 | |||
270 | return $vendor; |
||
271 | } |
||
272 | |||
273 | |||
274 | /** |
||
275 | * Get admins for vendor |
||
276 | * |
||
277 | * @since 1.0.0 |
||
278 | * @param int $vendor_id ID of vendor |
||
279 | * @return array $admins Array of user objects |
||
280 | */ |
||
281 | function printcenter_get_vendor_admins( $vendor_id = 0 ) { |
||
282 | $admins = false; |
||
283 | |||
284 | if( $vendor_id > 0 ) { |
||
285 | $args = array( |
||
286 | 'meta_key' => 'product_vendor', |
||
287 | 'meta_value' => $vendor_id, |
||
288 | 'meta_compare' => '=' |
||
289 | ); |
||
290 | |||
291 | $admins = get_users( $args ); |
||
292 | } |
||
293 | |||
294 | return $admins; |
||
295 | } |
||
296 | |||
297 | |||
298 | /** |
||
299 | * Get commission details |
||
300 | * |
||
301 | * @since 1.0.0 |
||
302 | * @param int $commission_id Commission ID |
||
303 | * @return object $commission Commission object |
||
304 | */ |
||
305 | function printcenter_get_commission( $commission_id = 0 ) { |
||
306 | $commission = false; |
||
307 | |||
308 | if( $commission_id > 0 ) { |
||
309 | // Get post data |
||
310 | $commission = get_post( $commission_id ); |
||
311 | |||
312 | // Get meta data |
||
313 | $commission->product = get_post_meta( $commission_id, '_commission_product', true ); |
||
314 | $commission->vendor = printcenter_get_vendor( get_post_meta( $commission_id, '_commission_vendor', true ) ); |
||
315 | $commission->amount = get_post_meta( $commission_id, '_commission_amount', true ); |
||
316 | $commission->paid_status = get_post_meta( $commission_id, '_paid_status', true ); |
||
317 | } |
||
318 | |||
319 | return $commission; |
||
320 | } |
||
321 | |||
322 | |||
323 | /** |
||
324 | * Check if user is admin of specific vendor |
||
325 | * |
||
326 | * @since 1.0.0 |
||
327 | * @param int $vendor_id ID of vendor |
||
328 | * @param int $user_id ID of user |
||
329 | * @return bool True if user is a vendor admin |
||
330 | */ |
||
331 | function printcenter_is_vendor_admin( $vendor_id = 0, $user_id = 0 ) { |
||
332 | if( $user_id == 0 ) { |
||
333 | global $current_user; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
334 | |||
335 | wp_get_current_user(); |
||
336 | |||
337 | $user_id = $current_user->ID; |
||
338 | } |
||
339 | |||
340 | $is_vendor_admin = false; |
||
341 | |||
342 | if( $vendor_id > 0 && $user_id > 0 ) { |
||
343 | $vendor = get_vendor( $vendor_id ); |
||
344 | |||
345 | if( isset( $vendor->admins ) ) { |
||
346 | foreach( $vendor->admins as $admin ) { |
||
347 | if( $admin->ID == $user_id ) { |
||
348 | $is_vendor_admin = true; |
||
349 | } |
||
350 | } |
||
351 | } |
||
352 | } |
||
353 | |||
354 | return apply_filters( 'printcenter_is_vendor_admin', $is_vendor_admin, $vendor_id, $user_id ); |
||
355 | } |
||
356 | |||
357 | |||
358 | /** |
||
359 | * Check if user is a vendor admin and return vendor ID |
||
360 | * |
||
361 | * @since 1.0.0 |
||
362 | * @param int $user_id User ID |
||
363 | * @return mixed Vendor ID if true, otherwise boolean false |
||
364 | */ |
||
365 | function printcenter_is_vendor( $user_id = 0 ) { |
||
366 | if( $user_id == 0 ) { |
||
367 | global $current_user; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
368 | |||
369 | wp_get_current_user(); |
||
370 | |||
371 | $user_id = $current_user->ID; |
||
372 | } |
||
373 | |||
374 | $is_vendor = false; |
||
375 | |||
376 | if( $user_id > 0 ) { |
||
377 | $vendor_id = get_user_meta( $user_id, 'product_vendor', true ); |
||
378 | |||
379 | if( $vendor_id && strlen( $vendor_id ) > 0 ) { |
||
380 | $is_vendor = $vendor_id; |
||
381 | } |
||
382 | } |
||
383 | |||
384 | return apply_filters( 'printcenter_is_vendor', $is_vendor, $user_id ); |
||
385 | } |
||
386 | |||
387 | |||
388 | /** |
||
389 | * Check if current user has vendor access to the WP dashboard |
||
390 | * |
||
391 | * @since 1.0.0 |
||
392 | * @return bool True if user has vendor access, otherwise false |
||
393 | */ |
||
394 | function printcenter_vendor_access() { |
||
395 | $is_vendor = printcenter_is_vendor(); |
||
396 | $vendor_access = false; |
||
397 | |||
398 | if( $is_vendor && ! current_user_can( 'manage_woocommerce' ) ) { |
||
399 | $vendor_access = true; |
||
400 | } |
||
401 | |||
402 | return apply_filters( 'printcenter_vendor_access', $vendor_access ); |
||
403 | } |
||
404 | |||
405 | |||
406 | if( ! function_exists( '_wp_ajax_add_non_hierarchical_term' ) ) { |
||
407 | /** |
||
408 | * Mod of _wp_ajax_add_hierarchical_term to handle non-hierarchical taxonomies |
||
409 | * |
||
410 | * @since 1.0.0 |
||
411 | * @return void |
||
412 | */ |
||
413 | function _wp_ajax_add_non_hierarchical_term() { |
||
414 | $action = $_POST['action']; |
||
415 | $taxonomy = get_taxonomy( substr( $action, 4 ) ); |
||
416 | |||
417 | check_ajax_referer( $action, '_ajax_nonce-add-' . $taxonomy->name ); |
||
418 | |||
419 | if( ! current_user_can( $taxonomy->cap->edit_terms ) ) { |
||
420 | wp_die( -1 ); |
||
421 | } |
||
422 | |||
423 | $names = explode( ',', $_POST['new'.$taxonomy->name] ); |
||
424 | $parent = 0; |
||
425 | |||
426 | if( $taxonomy->name == 'category' ) { |
||
427 | $post_category = isset( $_POST['post_category'] ) ? (array) $_POST['post_category'] : array(); |
||
428 | } else { |
||
429 | $post_category = ( isset( $_POST['tax_input'] ) && isset( $_POST['tax_input'][$taxonomy->name] ) ) ? (array) $_POST['tax_input'][$taxonomy->name] : array(); |
||
430 | } |
||
431 | |||
432 | $checked_categories = array_map( 'absint', (array) $post_category ); |
||
433 | |||
434 | foreach( $names as $tax_name ) { |
||
435 | $tax_name = trim( $tax_name ); |
||
436 | $category_nicename = sanitize_title( $tax_name ); |
||
437 | |||
438 | if( '' === $category_nicename ) { |
||
439 | continue; |
||
440 | } |
||
441 | |||
442 | if( ! $cat_id = term_exists( $tax_name, $taxonomy->name, $parent ) ) { |
||
443 | $cat_id = wp_insert_term( $tax_name, $taxonomy->name, array( 'parent' => $parent ) ); |
||
444 | } |
||
445 | |||
446 | if( is_wp_error( $cat_id ) ) { |
||
447 | continue; |
||
448 | } else if ( is_array( $cat_id ) ) { |
||
449 | $cat_id = $cat_id['term_id']; |
||
450 | } |
||
451 | |||
452 | $checked_categories[] = $cat_id; |
||
453 | |||
454 | if ( $parent ) { |
||
455 | // Do these all at once in a second |
||
456 | continue; |
||
457 | } |
||
458 | |||
459 | $new_term = get_term( $cat_id, $taxonomy->name ); |
||
460 | $data = "\n<li id='{$taxonomy->name}-{$cat_id}'>" . '<label class="selectit"><input value="' . $new_term->slug . '" type="checkbox" name="tax_input['.$taxonomy->name.'][]" id="in-'.$taxonomy->name.'-' . $new_term->term_id . '"' . checked( in_array( $new_term->term_id, $checked_categories ), true, false ) . ' /> ' . esc_html( apply_filters('the_category', $new_term->name )) . '</label>'; |
||
461 | $add = array( |
||
462 | 'what' => $taxonomy->name, |
||
463 | 'id' => $cat_id, |
||
464 | 'data' => str_replace( array("\n", "\t"), '', $data ), |
||
465 | 'position' => -1 |
||
466 | ); |
||
467 | } |
||
468 | |||
469 | $x = new WP_Ajax_Response( $add ); |
||
0 ignored issues
–
show
The variable
$add does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
470 | $x->send(); |
||
471 | } |
||
472 | } |
||
473 | |||
474 | |||
475 | if( ! class_exists( 'Walker_Tag_Checklist' ) ) { |
||
476 | /** |
||
477 | * Mod of WP's Walker_Category_Checklist class |
||
478 | * |
||
479 | * @since 1.0.0 |
||
480 | */ |
||
481 | class Walker_Tag_Checklist extends Walker { |
||
482 | |||
483 | /** |
||
484 | * @since 1.0.0 |
||
485 | * @var string $tree_type The type of tree we are working with |
||
486 | */ |
||
487 | var $tree_type = 'tag'; |
||
0 ignored issues
–
show
The visibility should be declared for property
$tree_type .
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using class A {
var $property;
}
the property is implicitly global. To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2. ![]() |
|||
488 | |||
489 | /** |
||
490 | * @since 1.0.0 |
||
491 | * @var array $db_fields The lookup field mapping for this walker |
||
492 | */ |
||
493 | var $db_fields = array ('parent' => 'parent', 'id' => 'term_id'); |
||
0 ignored issues
–
show
The visibility should be declared for property
$db_fields .
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using class A {
var $property;
}
the property is implicitly global. To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2. ![]() |
|||
494 | |||
495 | /** |
||
496 | * The start level for the walker |
||
497 | * |
||
498 | * @since 1.0.0 |
||
499 | * @param string $output The existing HTML for this item |
||
500 | * @param int $depth The indentation depth of this level |
||
501 | * @param array $args Arguements to pass to the function (unused) |
||
502 | * @return void |
||
503 | */ |
||
504 | function start_lvl( &$output, $depth = 0, $args = array() ) { |
||
0 ignored issues
–
show
|
|||
505 | $indent = str_repeat("\t", $depth); |
||
506 | $output .= "$indent<ul class='children'>\n"; |
||
507 | } |
||
508 | |||
509 | /** |
||
510 | * The end level for the walker |
||
511 | * |
||
512 | * @since 1.0.0 |
||
513 | * @param string $output The existing HTML for this item |
||
514 | * @param int $depth The indentation depth of this level |
||
515 | * @param array $args Arguements to pass to the function (unused) |
||
516 | * @return void |
||
517 | */ |
||
518 | function end_lvl( &$output, $depth = 0, $args = array() ) { |
||
0 ignored issues
–
show
|
|||
519 | $indent = str_repeat("\t", $depth); |
||
520 | $output .= "$indent</ul>\n"; |
||
521 | } |
||
522 | |||
523 | /** |
||
524 | * The start of this item for the walker |
||
525 | * |
||
526 | * @since 1.0.0 |
||
527 | * @param string $output The existing HTML for this item |
||
528 | * @param object $object The object for this item |
||
529 | * @param int $depth The indentation depth of this level |
||
530 | * @param array $args Arguements to pass to the function (unused) |
||
531 | * @param int $current_object_id The ID of this object |
||
532 | * @return void |
||
533 | */ |
||
534 | function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { |
||
0 ignored issues
–
show
|
|||
535 | extract($args); |
||
536 | |||
537 | if ( empty($taxonomy) ) { |
||
538 | $taxonomy = 'tag'; |
||
539 | } |
||
540 | |||
541 | if ( $taxonomy == 'tag' ) { |
||
542 | $name = 'post_tag'; |
||
543 | } else { |
||
544 | $name = 'tax_input['.$taxonomy.']'; |
||
545 | } |
||
546 | |||
547 | $class = in_array( $object->term_id, $popular_cats ) ? ' class="popular-category"' : ''; |
||
548 | $output .= "\n<li id='{$taxonomy}-{$object->term_id}'$class>" . '<label class="selectit"><input value="' . $object->slug . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $object->term_id . '"' . checked( in_array( $object->term_id, $selected_cats ), true, false ) . disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . esc_html( apply_filters('the_category', $object->name )) . '</label>'; |
||
549 | } |
||
550 | |||
551 | /** |
||
552 | * The end of this item for the walker |
||
553 | * |
||
554 | * @since 1.0.0 |
||
555 | * @param string $output The existing HTML for this item |
||
556 | * @param object $object The object for this item |
||
557 | * @param int $depth The indentation depth of this level |
||
558 | * @param array $args Arguements to pass to the function (unused) |
||
559 | * @return void |
||
560 | */ |
||
561 | function end_el( &$output, $object, $depth = 0, $args = array() ) { |
||
0 ignored issues
–
show
|
|||
562 | $output .= "</li>\n"; |
||
563 | } |
||
564 | } |
||
565 | } |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.