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 |
||
2 | /** |
||
3 | * WordPress Query API |
||
4 | * |
||
5 | * The query API attempts to get which part of WordPress the user is on. It |
||
6 | * also provides functionality for getting URL query information. |
||
7 | * |
||
8 | * @link https://codex.wordpress.org/The_Loop More information on The Loop. |
||
9 | * |
||
10 | * @package WordPress |
||
11 | * @subpackage Query |
||
12 | */ |
||
13 | |||
14 | /** |
||
15 | * Retrieve variable in the WP_Query class. |
||
16 | * |
||
17 | * @since 1.5.0 |
||
18 | * @since 3.9.0 The `$default` argument was introduced. |
||
19 | * |
||
20 | * @global WP_Query $wp_query Global WP_Query instance. |
||
21 | * |
||
22 | * @param string $var The variable key to retrieve. |
||
23 | * @param mixed $default Optional. Value to return if the query variable is not set. Default empty. |
||
24 | * @return mixed Contents of the query variable. |
||
25 | */ |
||
26 | function get_query_var( $var, $default = '' ) { |
||
27 | global $wp_query; |
||
28 | return $wp_query->get( $var, $default ); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Retrieve the currently-queried object. |
||
33 | * |
||
34 | * Wrapper for WP_Query::get_queried_object(). |
||
35 | * |
||
36 | * @since 3.1.0 |
||
37 | * @access public |
||
38 | * |
||
39 | * @global WP_Query $wp_query Global WP_Query instance. |
||
40 | * |
||
41 | * @return object Queried object. |
||
42 | */ |
||
43 | function get_queried_object() { |
||
44 | global $wp_query; |
||
45 | return $wp_query->get_queried_object(); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Retrieve ID of the current queried object. |
||
50 | * |
||
51 | * Wrapper for WP_Query::get_queried_object_id(). |
||
52 | * |
||
53 | * @since 3.1.0 |
||
54 | * |
||
55 | * @global WP_Query $wp_query Global WP_Query instance. |
||
56 | * |
||
57 | * @return int ID of the queried object. |
||
58 | */ |
||
59 | function get_queried_object_id() { |
||
60 | global $wp_query; |
||
61 | return $wp_query->get_queried_object_id(); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Set query variable. |
||
66 | * |
||
67 | * @since 2.2.0 |
||
68 | * |
||
69 | * @global WP_Query $wp_query Global WP_Query instance. |
||
70 | * |
||
71 | * @param string $var Query variable key. |
||
72 | * @param mixed $value Query variable value. |
||
73 | */ |
||
74 | function set_query_var( $var, $value ) { |
||
75 | global $wp_query; |
||
76 | $wp_query->set( $var, $value ); |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * Sets up The Loop with query parameters. |
||
81 | * |
||
82 | * Note: This function will completely override the main query and isn't intended for use |
||
83 | * by plugins or themes. Its overly-simplistic approach to modifying the main query can be |
||
84 | * problematic and should be avoided wherever possible. In most cases, there are better, |
||
85 | * more performant options for modifying the main query such as via the {@see 'pre_get_posts'} |
||
86 | * action within WP_Query. |
||
87 | * |
||
88 | * This must not be used within the WordPress Loop. |
||
89 | * |
||
90 | * @since 1.5.0 |
||
91 | * |
||
92 | * @global WP_Query $wp_query Global WP_Query instance. |
||
93 | * |
||
94 | * @param array|string $query Array or string of WP_Query arguments. |
||
95 | * @return array List of post objects. |
||
96 | */ |
||
97 | function query_posts($query) { |
||
98 | $GLOBALS['wp_query'] = new WP_Query(); |
||
99 | return $GLOBALS['wp_query']->query($query); |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Destroys the previous query and sets up a new query. |
||
104 | * |
||
105 | * This should be used after query_posts() and before another query_posts(). |
||
106 | * This will remove obscure bugs that occur when the previous WP_Query object |
||
107 | * is not destroyed properly before another is set up. |
||
108 | * |
||
109 | * @since 2.3.0 |
||
110 | * |
||
111 | * @global WP_Query $wp_query Global WP_Query instance. |
||
112 | * @global WP_Query $wp_the_query Copy of the global WP_Query instance created during wp_reset_query(). |
||
113 | */ |
||
114 | function wp_reset_query() { |
||
115 | $GLOBALS['wp_query'] = $GLOBALS['wp_the_query']; |
||
116 | wp_reset_postdata(); |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * After looping through a separate query, this function restores |
||
121 | * the $post global to the current post in the main query. |
||
122 | * |
||
123 | * @since 3.0.0 |
||
124 | * |
||
125 | * @global WP_Query $wp_query Global WP_Query instance. |
||
126 | */ |
||
127 | function wp_reset_postdata() { |
||
128 | global $wp_query; |
||
129 | |||
130 | if ( isset( $wp_query ) ) { |
||
131 | $wp_query->reset_postdata(); |
||
132 | } |
||
133 | } |
||
134 | |||
135 | /* |
||
136 | * Query type checks. |
||
137 | */ |
||
138 | |||
139 | /** |
||
140 | * Is the query for an existing archive page? |
||
141 | * |
||
142 | * Month, Year, Category, Author, Post Type archive... |
||
143 | * |
||
144 | * @since 1.5.0 |
||
145 | * |
||
146 | * @global WP_Query $wp_query Global WP_Query instance. |
||
147 | * |
||
148 | * @return bool |
||
149 | */ |
||
150 | View Code Duplication | function is_archive() { |
|
0 ignored issues
–
show
|
|||
151 | global $wp_query; |
||
152 | |||
153 | if ( ! isset( $wp_query ) ) { |
||
154 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
155 | return false; |
||
156 | } |
||
157 | |||
158 | return $wp_query->is_archive(); |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * Is the query for an existing post type archive page? |
||
163 | * |
||
164 | * @since 3.1.0 |
||
165 | * |
||
166 | * @global WP_Query $wp_query Global WP_Query instance. |
||
167 | * |
||
168 | * @param string|array $post_types Optional. Post type or array of posts types to check against. |
||
169 | * @return bool |
||
170 | */ |
||
171 | View Code Duplication | function is_post_type_archive( $post_types = '' ) { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
172 | global $wp_query; |
||
173 | |||
174 | if ( ! isset( $wp_query ) ) { |
||
175 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
176 | return false; |
||
177 | } |
||
178 | |||
179 | return $wp_query->is_post_type_archive( $post_types ); |
||
180 | } |
||
181 | |||
182 | /** |
||
183 | * Is the query for an existing attachment page? |
||
184 | * |
||
185 | * @since 2.0.0 |
||
186 | * |
||
187 | * @global WP_Query $wp_query Global WP_Query instance. |
||
188 | * |
||
189 | * @param int|string|array|object $attachment Attachment ID, title, slug, or array of such. |
||
190 | * @return bool |
||
191 | */ |
||
192 | View Code Duplication | function is_attachment( $attachment = '' ) { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
193 | global $wp_query; |
||
194 | |||
195 | if ( ! isset( $wp_query ) ) { |
||
196 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
197 | return false; |
||
198 | } |
||
199 | |||
200 | return $wp_query->is_attachment( $attachment ); |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * Is the query for an existing author archive page? |
||
205 | * |
||
206 | * If the $author parameter is specified, this function will additionally |
||
207 | * check if the query is for one of the authors specified. |
||
208 | * |
||
209 | * @since 1.5.0 |
||
210 | * |
||
211 | * @global WP_Query $wp_query Global WP_Query instance. |
||
212 | * |
||
213 | * @param mixed $author Optional. User ID, nickname, nicename, or array of User IDs, nicknames, and nicenames |
||
214 | * @return bool |
||
215 | */ |
||
216 | View Code Duplication | function is_author( $author = '' ) { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
217 | global $wp_query; |
||
218 | |||
219 | if ( ! isset( $wp_query ) ) { |
||
220 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
221 | return false; |
||
222 | } |
||
223 | |||
224 | return $wp_query->is_author( $author ); |
||
225 | } |
||
226 | |||
227 | /** |
||
228 | * Is the query for an existing category archive page? |
||
229 | * |
||
230 | * If the $category parameter is specified, this function will additionally |
||
231 | * check if the query is for one of the categories specified. |
||
232 | * |
||
233 | * @since 1.5.0 |
||
234 | * |
||
235 | * @global WP_Query $wp_query Global WP_Query instance. |
||
236 | * |
||
237 | * @param mixed $category Optional. Category ID, name, slug, or array of Category IDs, names, and slugs. |
||
238 | * @return bool |
||
239 | */ |
||
240 | View Code Duplication | function is_category( $category = '' ) { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
241 | global $wp_query; |
||
242 | |||
243 | if ( ! isset( $wp_query ) ) { |
||
244 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
245 | return false; |
||
246 | } |
||
247 | |||
248 | return $wp_query->is_category( $category ); |
||
249 | } |
||
250 | |||
251 | /** |
||
252 | * Is the query for an existing tag archive page? |
||
253 | * |
||
254 | * If the $tag parameter is specified, this function will additionally |
||
255 | * check if the query is for one of the tags specified. |
||
256 | * |
||
257 | * @since 2.3.0 |
||
258 | * |
||
259 | * @global WP_Query $wp_query Global WP_Query instance. |
||
260 | * |
||
261 | * @param mixed $tag Optional. Tag ID, name, slug, or array of Tag IDs, names, and slugs. |
||
262 | * @return bool |
||
263 | */ |
||
264 | View Code Duplication | function is_tag( $tag = '' ) { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
265 | global $wp_query; |
||
266 | |||
267 | if ( ! isset( $wp_query ) ) { |
||
268 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
269 | return false; |
||
270 | } |
||
271 | |||
272 | return $wp_query->is_tag( $tag ); |
||
273 | } |
||
274 | |||
275 | /** |
||
276 | * Is the query for an existing custom taxonomy archive page? |
||
277 | * |
||
278 | * If the $taxonomy parameter is specified, this function will additionally |
||
279 | * check if the query is for that specific $taxonomy. |
||
280 | * |
||
281 | * If the $term parameter is specified in addition to the $taxonomy parameter, |
||
282 | * this function will additionally check if the query is for one of the terms |
||
283 | * specified. |
||
284 | * |
||
285 | * @since 2.5.0 |
||
286 | * |
||
287 | * @global WP_Query $wp_query Global WP_Query instance. |
||
288 | * |
||
289 | * @param string|array $taxonomy Optional. Taxonomy slug or slugs. |
||
290 | * @param int|string|array $term Optional. Term ID, name, slug or array of Term IDs, names, and slugs. |
||
291 | * @return bool True for custom taxonomy archive pages, false for built-in taxonomies (category and tag archives). |
||
292 | */ |
||
293 | View Code Duplication | function is_tax( $taxonomy = '', $term = '' ) { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
294 | global $wp_query; |
||
295 | |||
296 | if ( ! isset( $wp_query ) ) { |
||
297 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
298 | return false; |
||
299 | } |
||
300 | |||
301 | return $wp_query->is_tax( $taxonomy, $term ); |
||
302 | } |
||
303 | |||
304 | /** |
||
305 | * Is the query for an existing date archive? |
||
306 | * |
||
307 | * @since 1.5.0 |
||
308 | * |
||
309 | * @global WP_Query $wp_query Global WP_Query instance. |
||
310 | * |
||
311 | * @return bool |
||
312 | */ |
||
313 | View Code Duplication | function is_date() { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
314 | global $wp_query; |
||
315 | |||
316 | if ( ! isset( $wp_query ) ) { |
||
317 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
318 | return false; |
||
319 | } |
||
320 | |||
321 | return $wp_query->is_date(); |
||
322 | } |
||
323 | |||
324 | /** |
||
325 | * Is the query for an existing day archive? |
||
326 | * |
||
327 | * @since 1.5.0 |
||
328 | * |
||
329 | * @global WP_Query $wp_query Global WP_Query instance. |
||
330 | * |
||
331 | * @return bool |
||
332 | */ |
||
333 | View Code Duplication | function is_day() { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
334 | global $wp_query; |
||
335 | |||
336 | if ( ! isset( $wp_query ) ) { |
||
337 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
338 | return false; |
||
339 | } |
||
340 | |||
341 | return $wp_query->is_day(); |
||
342 | } |
||
343 | |||
344 | /** |
||
345 | * Is the query for a feed? |
||
346 | * |
||
347 | * @since 1.5.0 |
||
348 | * |
||
349 | * @global WP_Query $wp_query Global WP_Query instance. |
||
350 | * |
||
351 | * @param string|array $feeds Optional feed types to check. |
||
352 | * @return bool |
||
353 | */ |
||
354 | View Code Duplication | function is_feed( $feeds = '' ) { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
355 | global $wp_query; |
||
356 | |||
357 | if ( ! isset( $wp_query ) ) { |
||
358 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
359 | return false; |
||
360 | } |
||
361 | |||
362 | return $wp_query->is_feed( $feeds ); |
||
363 | } |
||
364 | |||
365 | /** |
||
366 | * Is the query for a comments feed? |
||
367 | * |
||
368 | * @since 3.0.0 |
||
369 | * |
||
370 | * @global WP_Query $wp_query Global WP_Query instance. |
||
371 | * |
||
372 | * @return bool |
||
373 | */ |
||
374 | View Code Duplication | function is_comment_feed() { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
375 | global $wp_query; |
||
376 | |||
377 | if ( ! isset( $wp_query ) ) { |
||
378 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
379 | return false; |
||
380 | } |
||
381 | |||
382 | return $wp_query->is_comment_feed(); |
||
383 | } |
||
384 | |||
385 | /** |
||
386 | * Is the query for the front page of the site? |
||
387 | * |
||
388 | * This is for what is displayed at your site's main URL. |
||
389 | * |
||
390 | * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_on_front'. |
||
391 | * |
||
392 | * If you set a static page for the front page of your site, this function will return |
||
393 | * true when viewing that page. |
||
394 | * |
||
395 | * Otherwise the same as @see is_home() |
||
396 | * |
||
397 | * @since 2.5.0 |
||
398 | * |
||
399 | * @global WP_Query $wp_query Global WP_Query instance. |
||
400 | * |
||
401 | * @return bool True, if front of site. |
||
402 | */ |
||
403 | View Code Duplication | function is_front_page() { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
404 | global $wp_query; |
||
405 | |||
406 | if ( ! isset( $wp_query ) ) { |
||
407 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
408 | return false; |
||
409 | } |
||
410 | |||
411 | return $wp_query->is_front_page(); |
||
412 | } |
||
413 | |||
414 | /** |
||
415 | * Determines if the query is for the blog homepage. |
||
416 | * |
||
417 | * The blog homepage is the page that shows the time-based blog content of the site. |
||
418 | * |
||
419 | * is_home() is dependent on the site's "Front page displays" Reading Settings 'show_on_front' |
||
420 | * and 'page_for_posts'. |
||
421 | * |
||
422 | * If a static page is set for the front page of the site, this function will return true only |
||
423 | * on the page you set as the "Posts page". |
||
424 | * |
||
425 | * @since 1.5.0 |
||
426 | * |
||
427 | * @see is_front_page() |
||
428 | * @global WP_Query $wp_query Global WP_Query instance. |
||
429 | * |
||
430 | * @return bool True if blog view homepage, otherwise false. |
||
431 | */ |
||
432 | View Code Duplication | function is_home() { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
433 | global $wp_query; |
||
434 | |||
435 | if ( ! isset( $wp_query ) ) { |
||
436 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
437 | return false; |
||
438 | } |
||
439 | |||
440 | return $wp_query->is_home(); |
||
441 | } |
||
442 | |||
443 | /** |
||
444 | * Is the query for an existing month archive? |
||
445 | * |
||
446 | * @since 1.5.0 |
||
447 | * |
||
448 | * @global WP_Query $wp_query Global WP_Query instance. |
||
449 | * |
||
450 | * @return bool |
||
451 | */ |
||
452 | View Code Duplication | function is_month() { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
453 | global $wp_query; |
||
454 | |||
455 | if ( ! isset( $wp_query ) ) { |
||
456 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
457 | return false; |
||
458 | } |
||
459 | |||
460 | return $wp_query->is_month(); |
||
461 | } |
||
462 | |||
463 | /** |
||
464 | * Is the query for an existing single page? |
||
465 | * |
||
466 | * If the $page parameter is specified, this function will additionally |
||
467 | * check if the query is for one of the pages specified. |
||
468 | * |
||
469 | * @see is_single() |
||
470 | * @see is_singular() |
||
471 | * |
||
472 | * @since 1.5.0 |
||
473 | * |
||
474 | * @global WP_Query $wp_query Global WP_Query instance. |
||
475 | * |
||
476 | * @param int|string|array $page Optional. Page ID, title, slug, or array of such. Default empty. |
||
477 | * @return bool Whether the query is for an existing single page. |
||
478 | */ |
||
479 | View Code Duplication | function is_page( $page = '' ) { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
480 | global $wp_query; |
||
481 | |||
482 | if ( ! isset( $wp_query ) ) { |
||
483 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
484 | return false; |
||
485 | } |
||
486 | |||
487 | return $wp_query->is_page( $page ); |
||
488 | } |
||
489 | |||
490 | /** |
||
491 | * Is the query for paged result and not for the first page? |
||
492 | * |
||
493 | * @since 1.5.0 |
||
494 | * |
||
495 | * @global WP_Query $wp_query Global WP_Query instance. |
||
496 | * |
||
497 | * @return bool |
||
498 | */ |
||
499 | View Code Duplication | function is_paged() { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
500 | global $wp_query; |
||
501 | |||
502 | if ( ! isset( $wp_query ) ) { |
||
503 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
504 | return false; |
||
505 | } |
||
506 | |||
507 | return $wp_query->is_paged(); |
||
508 | } |
||
509 | |||
510 | /** |
||
511 | * Is the query for a post or page preview? |
||
512 | * |
||
513 | * @since 2.0.0 |
||
514 | * |
||
515 | * @global WP_Query $wp_query Global WP_Query instance. |
||
516 | * |
||
517 | * @return bool |
||
518 | */ |
||
519 | View Code Duplication | function is_preview() { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
520 | global $wp_query; |
||
521 | |||
522 | if ( ! isset( $wp_query ) ) { |
||
523 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
524 | return false; |
||
525 | } |
||
526 | |||
527 | return $wp_query->is_preview(); |
||
528 | } |
||
529 | |||
530 | /** |
||
531 | * Is the query for the robots file? |
||
532 | * |
||
533 | * @since 2.1.0 |
||
534 | * |
||
535 | * @global WP_Query $wp_query Global WP_Query instance. |
||
536 | * |
||
537 | * @return bool |
||
538 | */ |
||
539 | View Code Duplication | function is_robots() { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
540 | global $wp_query; |
||
541 | |||
542 | if ( ! isset( $wp_query ) ) { |
||
543 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
544 | return false; |
||
545 | } |
||
546 | |||
547 | return $wp_query->is_robots(); |
||
548 | } |
||
549 | |||
550 | /** |
||
551 | * Is the query for a search? |
||
552 | * |
||
553 | * @since 1.5.0 |
||
554 | * |
||
555 | * @global WP_Query $wp_query Global WP_Query instance. |
||
556 | * |
||
557 | * @return bool |
||
558 | */ |
||
559 | View Code Duplication | function is_search() { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
560 | global $wp_query; |
||
561 | |||
562 | if ( ! isset( $wp_query ) ) { |
||
563 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
564 | return false; |
||
565 | } |
||
566 | |||
567 | return $wp_query->is_search(); |
||
568 | } |
||
569 | |||
570 | /** |
||
571 | * Is the query for an existing single post? |
||
572 | * |
||
573 | * Works for any post type, except attachments and pages |
||
574 | * |
||
575 | * If the $post parameter is specified, this function will additionally |
||
576 | * check if the query is for one of the Posts specified. |
||
577 | * |
||
578 | * @see is_page() |
||
579 | * @see is_singular() |
||
580 | * |
||
581 | * @since 1.5.0 |
||
582 | * |
||
583 | * @global WP_Query $wp_query Global WP_Query instance. |
||
584 | * |
||
585 | * @param int|string|array $post Optional. Post ID, title, slug, or array of such. Default empty. |
||
586 | * @return bool Whether the query is for an existing single post. |
||
587 | */ |
||
588 | View Code Duplication | function is_single( $post = '' ) { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
589 | global $wp_query; |
||
590 | |||
591 | if ( ! isset( $wp_query ) ) { |
||
592 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
593 | return false; |
||
594 | } |
||
595 | |||
596 | return $wp_query->is_single( $post ); |
||
597 | } |
||
598 | |||
599 | /** |
||
600 | * Is the query for an existing single post of any post type (post, attachment, page, |
||
601 | * custom post types)? |
||
602 | * |
||
603 | * If the $post_types parameter is specified, this function will additionally |
||
604 | * check if the query is for one of the Posts Types specified. |
||
605 | * |
||
606 | * @see is_page() |
||
607 | * @see is_single() |
||
608 | * |
||
609 | * @since 1.5.0 |
||
610 | * |
||
611 | * @global WP_Query $wp_query Global WP_Query instance. |
||
612 | * |
||
613 | * @param string|array $post_types Optional. Post type or array of post types. Default empty. |
||
614 | * @return bool Whether the query is for an existing single post of any of the given post types. |
||
615 | */ |
||
616 | View Code Duplication | function is_singular( $post_types = '' ) { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
617 | global $wp_query; |
||
618 | |||
619 | if ( ! isset( $wp_query ) ) { |
||
620 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
621 | return false; |
||
622 | } |
||
623 | |||
624 | return $wp_query->is_singular( $post_types ); |
||
625 | } |
||
626 | |||
627 | /** |
||
628 | * Is the query for a specific time? |
||
629 | * |
||
630 | * @since 1.5.0 |
||
631 | * |
||
632 | * @global WP_Query $wp_query Global WP_Query instance. |
||
633 | * |
||
634 | * @return bool |
||
635 | */ |
||
636 | View Code Duplication | function is_time() { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
637 | global $wp_query; |
||
638 | |||
639 | if ( ! isset( $wp_query ) ) { |
||
640 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
641 | return false; |
||
642 | } |
||
643 | |||
644 | return $wp_query->is_time(); |
||
645 | } |
||
646 | |||
647 | /** |
||
648 | * Is the query for a trackback endpoint call? |
||
649 | * |
||
650 | * @since 1.5.0 |
||
651 | * |
||
652 | * @global WP_Query $wp_query Global WP_Query instance. |
||
653 | * |
||
654 | * @return bool |
||
655 | */ |
||
656 | View Code Duplication | function is_trackback() { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
657 | global $wp_query; |
||
658 | |||
659 | if ( ! isset( $wp_query ) ) { |
||
660 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
661 | return false; |
||
662 | } |
||
663 | |||
664 | return $wp_query->is_trackback(); |
||
665 | } |
||
666 | |||
667 | /** |
||
668 | * Is the query for an existing year archive? |
||
669 | * |
||
670 | * @since 1.5.0 |
||
671 | * |
||
672 | * @global WP_Query $wp_query Global WP_Query instance. |
||
673 | * |
||
674 | * @return bool |
||
675 | */ |
||
676 | View Code Duplication | function is_year() { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
677 | global $wp_query; |
||
678 | |||
679 | if ( ! isset( $wp_query ) ) { |
||
680 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
681 | return false; |
||
682 | } |
||
683 | |||
684 | return $wp_query->is_year(); |
||
685 | } |
||
686 | |||
687 | /** |
||
688 | * Is the query a 404 (returns no results)? |
||
689 | * |
||
690 | * @since 1.5.0 |
||
691 | * |
||
692 | * @global WP_Query $wp_query Global WP_Query instance. |
||
693 | * |
||
694 | * @return bool |
||
695 | */ |
||
696 | View Code Duplication | function is_404() { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
697 | global $wp_query; |
||
698 | |||
699 | if ( ! isset( $wp_query ) ) { |
||
700 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
701 | return false; |
||
702 | } |
||
703 | |||
704 | return $wp_query->is_404(); |
||
705 | } |
||
706 | |||
707 | /** |
||
708 | * Is the query for an embedded post? |
||
709 | * |
||
710 | * @since 4.4.0 |
||
711 | * |
||
712 | * @global WP_Query $wp_query Global WP_Query instance. |
||
713 | * |
||
714 | * @return bool Whether we're in an embedded post or not. |
||
715 | */ |
||
716 | View Code Duplication | function is_embed() { |
|
0 ignored issues
–
show
This function seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
717 | global $wp_query; |
||
718 | |||
719 | if ( ! isset( $wp_query ) ) { |
||
720 | _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' ); |
||
721 | return false; |
||
722 | } |
||
723 | |||
724 | return $wp_query->is_embed(); |
||
725 | } |
||
726 | |||
727 | /** |
||
728 | * Is the query the main query? |
||
729 | * |
||
730 | * @since 3.3.0 |
||
731 | * |
||
732 | * @global WP_Query $wp_query Global WP_Query instance. |
||
733 | * |
||
734 | * @return bool |
||
735 | */ |
||
736 | function is_main_query() { |
||
737 | if ( 'pre_get_posts' === current_filter() ) { |
||
738 | $message = sprintf( |
||
739 | /* translators: 1: pre_get_posts 2: WP_Query->is_main_query() 3: is_main_query() 4: link to codex is_main_query() page. */ |
||
740 | __( 'In %1$s, use the %2$s method, not the %3$s function. See %4$s.' ), |
||
741 | '<code>pre_get_posts</code>', |
||
742 | '<code>WP_Query->is_main_query()</code>', |
||
743 | '<code>is_main_query()</code>', |
||
744 | __( 'https://codex.wordpress.org/Function_Reference/is_main_query' ) |
||
745 | ); |
||
746 | _doing_it_wrong( __FUNCTION__, $message, '3.7.0' ); |
||
747 | } |
||
748 | |||
749 | global $wp_query; |
||
750 | return $wp_query->is_main_query(); |
||
751 | } |
||
752 | |||
753 | /* |
||
754 | * The Loop. Post loop control. |
||
755 | */ |
||
756 | |||
757 | /** |
||
758 | * Whether current WordPress query has results to loop over. |
||
759 | * |
||
760 | * @since 1.5.0 |
||
761 | * |
||
762 | * @global WP_Query $wp_query Global WP_Query instance. |
||
763 | * |
||
764 | * @return bool |
||
765 | */ |
||
766 | function have_posts() { |
||
767 | global $wp_query; |
||
768 | return $wp_query->have_posts(); |
||
769 | } |
||
770 | |||
771 | /** |
||
772 | * Whether the caller is in the Loop. |
||
773 | * |
||
774 | * @since 2.0.0 |
||
775 | * |
||
776 | * @global WP_Query $wp_query Global WP_Query instance. |
||
777 | * |
||
778 | * @return bool True if caller is within loop, false if loop hasn't started or ended. |
||
779 | */ |
||
780 | function in_the_loop() { |
||
781 | global $wp_query; |
||
782 | return $wp_query->in_the_loop; |
||
783 | } |
||
784 | |||
785 | /** |
||
786 | * Rewind the loop posts. |
||
787 | * |
||
788 | * @since 1.5.0 |
||
789 | * |
||
790 | * @global WP_Query $wp_query Global WP_Query instance. |
||
791 | */ |
||
792 | function rewind_posts() { |
||
793 | global $wp_query; |
||
794 | $wp_query->rewind_posts(); |
||
795 | } |
||
796 | |||
797 | /** |
||
798 | * Iterate the post index in the loop. |
||
799 | * |
||
800 | * @since 1.5.0 |
||
801 | * |
||
802 | * @global WP_Query $wp_query Global WP_Query instance. |
||
803 | */ |
||
804 | function the_post() { |
||
805 | global $wp_query; |
||
806 | $wp_query->the_post(); |
||
807 | } |
||
808 | |||
809 | /* |
||
810 | * Comments loop. |
||
811 | */ |
||
812 | |||
813 | /** |
||
814 | * Whether there are comments to loop over. |
||
815 | * |
||
816 | * @since 2.2.0 |
||
817 | * |
||
818 | * @global WP_Query $wp_query Global WP_Query instance. |
||
819 | * |
||
820 | * @return bool |
||
821 | */ |
||
822 | function have_comments() { |
||
823 | global $wp_query; |
||
824 | return $wp_query->have_comments(); |
||
825 | } |
||
826 | |||
827 | /** |
||
828 | * Iterate comment index in the comment loop. |
||
829 | * |
||
830 | * @since 2.2.0 |
||
831 | * |
||
832 | * @global WP_Query $wp_query Global WP_Query instance. |
||
833 | * |
||
834 | * @return object |
||
835 | */ |
||
836 | function the_comment() { |
||
837 | global $wp_query; |
||
838 | return $wp_query->the_comment(); |
||
839 | } |
||
840 | |||
841 | /** |
||
842 | * Redirect old slugs to the correct permalink. |
||
843 | * |
||
844 | * Attempts to find the current slug from the past slugs. |
||
845 | * |
||
846 | * @since 2.1.0 |
||
847 | * |
||
848 | * @global wpdb $wpdb WordPress database abstraction object. |
||
849 | */ |
||
850 | function wp_old_slug_redirect() { |
||
851 | if ( is_404() && '' !== get_query_var( 'name' ) ) { |
||
852 | global $wpdb; |
||
853 | |||
854 | // Guess the current post_type based on the query vars. |
||
855 | if ( get_query_var( 'post_type' ) ) { |
||
856 | $post_type = get_query_var( 'post_type' ); |
||
857 | } elseif ( get_query_var( 'attachment' ) ) { |
||
858 | $post_type = 'attachment'; |
||
859 | } elseif ( get_query_var( 'pagename' ) ) { |
||
860 | $post_type = 'page'; |
||
861 | } else { |
||
862 | $post_type = 'post'; |
||
863 | } |
||
864 | |||
865 | if ( is_array( $post_type ) ) { |
||
866 | if ( count( $post_type ) > 1 ) { |
||
867 | return; |
||
868 | } |
||
869 | $post_type = reset( $post_type ); |
||
870 | } |
||
871 | |||
872 | // Do not attempt redirect for hierarchical post types |
||
873 | if ( is_post_type_hierarchical( $post_type ) ) { |
||
874 | return; |
||
875 | } |
||
876 | |||
877 | $query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_slug' AND meta_value = %s", $post_type, get_query_var( 'name' ) ); |
||
878 | |||
879 | // if year, monthnum, or day have been specified, make our query more precise |
||
880 | // just in case there are multiple identical _wp_old_slug values |
||
881 | if ( get_query_var( 'year' ) ) { |
||
882 | $query .= $wpdb->prepare(" AND YEAR(post_date) = %d", get_query_var( 'year' ) ); |
||
883 | } |
||
884 | if ( get_query_var( 'monthnum' ) ) { |
||
885 | $query .= $wpdb->prepare(" AND MONTH(post_date) = %d", get_query_var( 'monthnum' ) ); |
||
886 | } |
||
887 | if ( get_query_var( 'day' ) ) { |
||
888 | $query .= $wpdb->prepare(" AND DAYOFMONTH(post_date) = %d", get_query_var( 'day' ) ); |
||
889 | } |
||
890 | |||
891 | $id = (int) $wpdb->get_var( $query ); |
||
892 | |||
893 | if ( ! $id ) { |
||
894 | return; |
||
895 | } |
||
896 | |||
897 | $link = get_permalink( $id ); |
||
898 | |||
899 | if ( get_query_var( 'paged' ) > 1 ) { |
||
900 | $link = user_trailingslashit( trailingslashit( $link ) . 'page/' . get_query_var( 'paged' ) ); |
||
0 ignored issues
–
show
|
|||
901 | } elseif( is_embed() ) { |
||
902 | $link = user_trailingslashit( trailingslashit( $link ) . 'embed' ); |
||
0 ignored issues
–
show
|
|||
903 | } |
||
904 | |||
905 | /** |
||
906 | * Filters the old slug redirect URL. |
||
907 | * |
||
908 | * @since 4.4.0 |
||
909 | * |
||
910 | * @param string $link The redirect URL. |
||
911 | */ |
||
912 | $link = apply_filters( 'old_slug_redirect_url', $link ); |
||
913 | |||
914 | if ( ! $link ) { |
||
915 | return; |
||
916 | } |
||
917 | |||
918 | wp_redirect( $link, 301 ); // Permanent redirect |
||
919 | exit; |
||
0 ignored issues
–
show
The function wp_old_slug_redirect() contains an exit expression.
An exit expression should only be used in rare cases. For example, if you write a short command line script. In most cases however, using an ![]() |
|||
920 | } |
||
921 | } |
||
922 | |||
923 | /** |
||
924 | * Set up global post data. |
||
925 | * |
||
926 | * @since 1.5.0 |
||
927 | * @since 4.4.0 Added the ability to pass a post ID to `$post`. |
||
928 | * |
||
929 | * @global WP_Query $wp_query Global WP_Query instance. |
||
930 | * |
||
931 | * @param WP_Post|object|int $post WP_Post instance or Post ID/object. |
||
932 | * @return bool True when finished. |
||
933 | */ |
||
934 | function setup_postdata( $post ) { |
||
935 | global $wp_query; |
||
936 | |||
937 | if ( ! empty( $wp_query ) && $wp_query instanceof WP_Query ) { |
||
938 | return $wp_query->setup_postdata( $post ); |
||
939 | } |
||
940 | |||
941 | return false; |
||
942 | } |
||
943 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.