|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +// === nopaging tests === |
| 4 | + |
3 | 5 | $args = array( |
4 | 6 | 'nopaging' => true, // Bad. |
5 | 7 | ); |
6 | 8 |
|
7 | 9 | _query_posts( 'nopaging=true' ); // Bad. |
8 | 10 |
|
9 | | -$query_args['my_posts_per_page'] = -1; // OK. |
| 11 | +$query_args['my_posts_per_page'] = -1; // OK - not a recognized key. |
10 | 12 |
|
11 | 13 | // Verify handling with no trailing comma at end of array. |
12 | 14 | $args = array( |
13 | 15 | 'nopaging' => true // Bad. |
14 | 16 | ); |
15 | 17 | $args = [ 'nopaging' => true ]; // Bad. |
| 18 | + |
| 19 | +// nopaging with integer 1. |
| 20 | +$args = [ 'nopaging' => 1 ]; // Bad. |
| 21 | + |
| 22 | +// nopaging with false - should not trigger. |
| 23 | +$args = [ 'nopaging' => false ]; // OK. |
| 24 | + |
| 25 | +// nopaging with integer 0 - should not trigger. |
| 26 | +$args = [ 'nopaging' => 0 ]; // OK. |
| 27 | + |
| 28 | +// nopaging via variable assignment. |
| 29 | +$args['nopaging'] = true; // Bad. |
| 30 | + |
| 31 | +// nopaging via variable assignment with false. |
| 32 | +$args['nopaging'] = false; // OK. |
| 33 | + |
| 34 | +// === posts_per_page tests === |
| 35 | + |
| 36 | +// posts_per_page set to -1 in long array syntax. |
| 37 | +$args = array( |
| 38 | + 'posts_per_page' => -1, // Bad. |
| 39 | +); |
| 40 | + |
| 41 | +// posts_per_page set to -1 in short array syntax. |
| 42 | +$args = [ 'posts_per_page' => -1 ]; // Bad. |
| 43 | + |
| 44 | +// posts_per_page set to -1 as string. |
| 45 | +$args = [ 'posts_per_page' => '-1' ]; // Bad. |
| 46 | + |
| 47 | +// posts_per_page set to a normal value - should not trigger. |
| 48 | +$args = [ 'posts_per_page' => 50 ]; // OK. |
| 49 | + |
| 50 | +// posts_per_page set to 1 - should not trigger. |
| 51 | +$args = [ 'posts_per_page' => 1 ]; // OK. |
| 52 | + |
| 53 | +// numberposts set to -1. |
| 54 | +$args = [ 'numberposts' => -1 ]; // Bad. |
| 55 | + |
| 56 | +// numberposts set to a normal value - should not trigger. |
| 57 | +$args = [ 'numberposts' => 10 ]; // OK. |
| 58 | + |
| 59 | +// posts_per_page via variable assignment. |
| 60 | +$args['posts_per_page'] = -1; // Bad. |
| 61 | + |
| 62 | +// posts_per_page via variable assignment with normal value. |
| 63 | +$args['posts_per_page'] = 10; // OK. |
| 64 | + |
| 65 | +// Query string with posts_per_page=-1. |
| 66 | +_query_posts( 'posts_per_page=-1&orderby=date' ); // Bad. |
| 67 | + |
| 68 | +// Query string with posts_per_page set to a normal value. |
| 69 | +_query_posts( 'posts_per_page=50' ); // OK. |
| 70 | + |
| 71 | +// Query string with numberposts=-1. |
| 72 | +_query_posts( 'numberposts=-1' ); // Bad. |
| 73 | + |
| 74 | +// === Ignoring with phpcs:ignore comments === |
| 75 | + |
| 76 | +// phpcs:ignore WordPressVIPMinimum.Performance.NoPaging.posts_per_page_posts_per_page -- Intentional: fetching all items for export. |
| 77 | +$args = [ 'posts_per_page' => -1 ]; // OK - ignored. |
| 78 | + |
| 79 | +$args = [ |
| 80 | + // phpcs:ignore WordPressVIPMinimum.Performance.NoPaging.posts_per_page_numberposts -- Intentional: legacy API requires all results. |
| 81 | + 'numberposts' => -1, // OK - ignored. |
| 82 | +]; |
| 83 | + |
| 84 | +// phpcs:ignore WordPressVIPMinimum.Performance.NoPaging.nopaging_nopaging -- Intentional: sitemap generation. |
| 85 | +$args = [ 'nopaging' => true ]; // OK - ignored. |
0 commit comments