Ticket #14494: 14494.diff
| File 14494.diff, 27.5 KB (added by mdawaffe, 3 years ago) |
|---|
-
wp-includes/query.php
98 98 */ 99 99 100 100 /** 101 * Is query requesting an archive page.101 * Is the query for an archive page? 102 102 * 103 * Month, Year, Category, Author, ... 104 * 105 * @see WP_Query::is_archive() 103 106 * @since 1.5.0 104 107 * @uses $wp_query 105 108 * 106 * @return bool True if page is archive.109 * @return bool 107 110 */ 108 111 function is_archive() { 109 112 global $wp_query; 110 113 111 return $wp_query->is_archive ;114 return $wp_query->is_archive(); 112 115 } 113 116 114 117 /** 115 * Is query requesting an attachment page.118 * Is the query for an attachment page? 116 119 * 120 * @see WP_Query::is_attachment() 117 121 * @since 2.0.0 118 122 * @uses $wp_query 119 123 * 120 * @return bool True if page is attachment.124 * @return bool 121 125 */ 122 126 function is_attachment() { 123 127 global $wp_query; 124 128 125 return $wp_query->is_attachment ;129 return $wp_query->is_attachment(); 126 130 } 127 131 128 132 /** 129 * Is query requesting an author page.133 * Is the query for an author archive page? 130 134 * 131 * If the $author parameter is specified then the check will be expanded to 132 * include whether the queried author matches the one given in the parameter. 133 * You can match against integers and against strings. 135 * If the $author parameter is specified, this function will additionally 136 * check if the query is for one of the authors specified. 134 137 * 135 * If matching against an integer, the ID should be used of the author for the 136 * test. If the $author is an ID and matches the author page user ID, then 137 * 'true' will be returned. 138 * 139 * If matching against strings, then the test will be matched against both the 140 * nickname and user nicename and will return true on success. 141 * 138 * @see WP_Query::is_author() 142 139 * @since 1.5.0 143 140 * @uses $wp_query 144 141 * 145 * @param string|int $author Optional. Is current page this author.146 * @return bool True if page is author or $author (if set).142 * @param mixed $author Optional. User ID, nickname, nicename, or array of User IDs, nicknames, and nicenames 143 * @return bool 147 144 */ 148 function is_author( $author = '') {145 function is_author( $author = '' ) { 149 146 global $wp_query; 150 147 151 if ( !$wp_query->is_author ) 152 return false; 153 154 if ( empty($author) ) 155 return true; 156 157 $author_obj = $wp_query->get_queried_object(); 158 159 $author = (array) $author; 160 161 if ( in_array( $author_obj->ID, $author ) ) 162 return true; 163 elseif ( in_array( $author_obj->nickname, $author ) ) 164 return true; 165 elseif ( in_array( $author_obj->user_nicename, $author ) ) 166 return true; 167 168 return false; 148 return $wp_query->is_author( $author ); 169 149 } 170 150 171 151 /** 172 * Whether current page query contains a category name or given category name.152 * Is the query for a category archive page? 173 153 * 174 * The category list can contain category IDs, names, or category slugs. If any175 * of them are part of the query, then it will return true.154 * If the $category parameter is specified, this function will additionally 155 * check if the query is for one of the categories specified. 176 156 * 157 * @see WP_Query::is_category() 177 158 * @since 1.5.0 178 159 * @uses $wp_query 179 160 * 180 * @param string|array $category Optional.161 * @param mixed $category Optional. Category ID, name, slug, or array of Category IDs, names, and slugs. 181 162 * @return bool 182 163 */ 183 function is_category( $category = '') {164 function is_category( $category = '' ) { 184 165 global $wp_query; 185 166 186 if ( !$wp_query->is_category ) 187 return false; 188 189 if ( empty($category) ) 190 return true; 191 192 $cat_obj = $wp_query->get_queried_object(); 193 194 $category = (array) $category; 195 196 if ( in_array( $cat_obj->term_id, $category ) ) 197 return true; 198 elseif ( in_array( $cat_obj->name, $category ) ) 199 return true; 200 elseif ( in_array( $cat_obj->slug, $category ) ) 201 return true; 202 203 return false; 167 return $wp_query->is_category( $category ); 204 168 } 205 169 206 170 /** 207 * Whether the current page query has the given tag slug or contains tag.171 * Is the query for a tag archive page? 208 172 * 173 * If the $tag parameter is specified, this function will additionally 174 * check if the query is for one of the tags specified. 175 * 176 * @see WP_Query::is_tag() 209 177 * @since 2.3.0 210 178 * @uses $wp_query 211 179 * 212 * @param string|array $slug Optional. Single tag or list of tags to check for.180 * @param mixed $slug Optional. Tag slug or array of slugs. 213 181 * @return bool 214 182 */ 215 183 function is_tag( $slug = '' ) { 216 184 global $wp_query; 217 185 218 if ( !$wp_query->is_tag ) 219 return false; 220 221 if ( empty( $slug ) ) 222 return true; 223 224 $tag_obj = $wp_query->get_queried_object(); 225 226 $slug = (array) $slug; 227 228 if ( in_array( $tag_obj->slug, $slug ) ) 229 return true; 230 231 return false; 186 return $wp_query->is_tag( $slug ); 232 187 } 233 188 234 189 /** 235 * Whether the current query is for the given taxonomy and/or term.190 * Is the query for a taxonomy archive page? 236 191 * 237 * If no taxonomy argument is set, returns true if any taxonomy is queried. 238 * If the taxonomy argument is passed but no term argument, returns true 239 * if the taxonomy or taxonomies in the argument are being queried. 240 * If both taxonomy and term arguments are passed, returns true 241 * if the current query is for a term contained in the terms argument 242 * which has a taxonomy contained in the taxonomy argument. 192 * If the $taxonomy parameter is specified, this function will additionally 193 * check if the query is for that specific $taxonomy. 243 194 * 195 * If the $term parameter is specified in addition to the $taxonomy parameter, 196 * this function will additionally check if the query is for one of the terms 197 * specified. 198 * 199 * @see WP_Query::is_tax() 244 200 * @since 2.5.0 245 201 * @uses $wp_query 246 202 * 247 * @param string|array $taxonomy Optional. Taxonomy slug or slugs to check in current query.248 * @param int|array|string $term. Optional. A single or array of, The term's ID, Name or Slug203 * @param mixed $taxonomy Optional. Taxonomy slug or slugs. 204 * @param mixed $term. Optional. Term ID, name, slug or array of Term IDs, names, and slugs. 249 205 * @return bool 250 206 */ 251 207 function is_tax( $taxonomy = '', $term = '' ) { 252 208 global $wp_query, $wp_taxonomies; 253 209 254 $queried_object = $wp_query->get_queried_object(); 255 $tax_array = array_intersect(array_keys($wp_taxonomies), (array) $taxonomy); 256 $term_array = (array) $term; 257 258 if ( !$wp_query->is_tax ) 259 return false; 260 261 if ( empty( $taxonomy ) ) 262 return true; 263 264 if ( empty( $term ) ) // Only a Taxonomy provided 265 return isset($queried_object->taxonomy) && count( $tax_array ) && in_array($queried_object->taxonomy, $tax_array); 266 267 return isset($queried_object->term_id) && 268 count(array_intersect( 269 array($queried_object->term_id, $queried_object->name, $queried_object->slug), 270 $term_array 271 )); 210 return $wp_query->is_tax( $taxonomy, $term ); 272 211 } 273 212 274 213 /** 275 214 * Whether the current URL is within the comments popup window. 276 215 * 216 * @see WP_Query::is_comments_popup() 277 217 * @since 1.5.0 278 218 * @uses $wp_query 279 219 * … … 282 222 function is_comments_popup() { 283 223 global $wp_query; 284 224 285 return $wp_query->is_comments_popup ;225 return $wp_query->is_comments_popup(); 286 226 } 287 227 288 228 /** 289 * Whether current URL is based on a date.229 * Is the query for a date archive? 290 230 * 231 * @see WP_Query::is_date() 291 232 * @since 1.5.0 292 233 * @uses $wp_query 293 234 * … … 296 237 function is_date() { 297 238 global $wp_query; 298 239 299 return $wp_query->is_date ;240 return $wp_query->is_date(); 300 241 } 301 242 302 243 /** 303 * Whether current blog URL contains a day.244 * Is the query for a day archive? 304 245 * 246 * @see WP_Query::is_day() 305 247 * @since 1.5.0 306 248 * @uses $wp_query 307 249 * … … 310 252 function is_day() { 311 253 global $wp_query; 312 254 313 return $wp_query->is_day ;255 return $wp_query->is_day(); 314 256 } 315 257 316 258 /** 317 * Whether current page query is feed URL.259 * Is the query for a feed? 318 260 * 261 * @see WP_Query::is_feed() 319 262 * @since 1.5.0 320 263 * @uses $wp_query 321 264 * … … 324 267 function is_feed() { 325 268 global $wp_query; 326 269 327 return $wp_query->is_feed ;270 return $wp_query->is_feed(); 328 271 } 329 272 330 273 /** 331 * Whether current page query is comment feed URL.274 * Is the query for a comments feed? 332 275 * 276 * @see WP_Query::is_comments_feed() 333 277 * @since 3.0.0 334 278 * @uses $wp_query 335 279 * … … 338 282 function is_comment_feed() { 339 283 global $wp_query; 340 284 341 return $wp_query->is_comment_feed ;285 return $wp_query->is_comment_feed(); 342 286 } 343 287 344 288 /** 345 * Whether current page query is the front of the site.289 * Is the query for the front page of the site? 346 290 * 291 * This is for what is displayed at your site's main URL. 292 * 293 * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_on_front'. 294 * 295 * If you set a static page for the front page of your site, this function will return 296 * true when viewing that page. 297 * 298 * Otherwise the same as @see is_home() 299 * 300 * @see WP_Query::is_front_page() 347 301 * @since 2.5.0 348 302 * @uses is_home() 349 303 * @uses get_option() … … 351 305 * @return bool True, if front of site. 352 306 */ 353 307 function is_front_page() { 354 // most likely case 355 if ( 'posts' == get_option('show_on_front') && is_home() ) 356 return true; 357 elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') && is_page(get_option('page_on_front')) ) 358 return true; 359 else 360 return false; 308 global $wp_query; 309 310 return $wp_query->is_front_page(); 361 311 } 362 312 363 313 /** 364 * Whether current page view is the blog homepage.314 * Is the query for the blog homepage? 365 315 * 366 * This is the page which is showing the time based blog content of your site 367 * so if you set a static page for the front page of your site then this will 368 * only be true on the page which you set as the "Posts page" in Reading Settings. 316 * This is the page which shows the time based blog content of your site. 369 317 * 318 * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_for_posts'. 319 * 320 * If you set a static page for the front page of your site, this function will return 321 * true only on the page you set as the "Posts page". 322 * 323 * @see is_front_page() 324 * 325 * @see WP_Query::is_home() 370 326 * @since 1.5.0 371 327 * @uses $wp_query 372 328 * … … 375 331 function is_home() { 376 332 global $wp_query; 377 333 378 return $wp_query->is_home ;334 return $wp_query->is_home(); 379 335 } 380 336 381 337 /** 382 * Whether current page query contains a month.338 * Is the query for a month archive? 383 339 * 340 * @see WP_Query::is_month() 384 341 * @since 1.5.0 385 342 * @uses $wp_query 386 343 * … … 389 346 function is_month() { 390 347 global $wp_query; 391 348 392 return $wp_query->is_month ;349 return $wp_query->is_month(); 393 350 } 394 351 395 352 /** 396 * Whether query is page or contains given page(s).353 * Is the query for a single Page? 397 354 * 398 * Calls the function without any parameters will only test whether the current 399 * query is of the page type. Either a list or a single item can be tested 400 * against for whether the query is a page and also is the value or one of the 401 * values in the page parameter. 355 * If the $page parameter is specified, this function will additionally 356 * check if the query is for one of the Pages specified. 402 357 * 403 * The parameter can contain the page ID, page title, or page name. The404 * parameter can also be an array of those three values.358 * @see is_single() 359 * @see is_singular() 405 360 * 361 * @see WP_Query::is_single() 406 362 * @since 1.5.0 407 363 * @uses $wp_query 408 364 * 409 * @param mixed $page Either page or list of pages to test against.365 * @param mixed $page Page ID, title, slug, or array of Page IDs, titles, and slugs. 410 366 * @return bool 411 367 */ 412 function is_page( $page = '') {368 function is_page( $page = '' ) { 413 369 global $wp_query; 414 370 415 if ( !$wp_query->is_page ) 416 return false; 417 418 if ( empty($page) ) 419 return true; 420 421 $page_obj = $wp_query->get_queried_object(); 422 423 $page = (array) $page; 424 425 if ( in_array( $page_obj->ID, $page ) ) 426 return true; 427 elseif ( in_array( $page_obj->post_title, $page ) ) 428 return true; 429 else if ( in_array( $page_obj->post_name, $page ) ) 430 return true; 431 432 return false; 371 return $wp_query->is_page( $page ); 433 372 } 434 373 435 374 /** 436 * Whether query contains multiple pages for the results.375 * Is the query for paged result and not for the first page? 437 376 * 377 * @see WP_Query::is_paged() 438 378 * @since 1.5.0 439 379 * @uses $wp_query 440 380 * … … 443 383 function is_paged() { 444 384 global $wp_query; 445 385 446 return $wp_query->is_paged ;386 return $wp_query->is_paged(); 447 387 } 448 388 449 389 /** 450 * Whether the current page was created by a plugin.390 * Is the query for a post or page preview? 451 391 * 452 * The plugin can set this by using the global $plugin_page and setting it to 453 * true. 454 * 455 * @since 1.5.0 456 * @global bool $plugin_page Used by plugins to tell the query that current is a plugin page. 457 * 458 * @return bool 459 */ 460 function is_plugin_page() { 461 global $plugin_page; 462 463 if ( isset($plugin_page) ) 464 return true; 465 466 return false; 467 } 468 469 /** 470 * Whether the current query is preview of post or page. 471 * 392 * @see WP_Query::is_preview() 472 393 * @since 2.0.0 473 394 * @uses $wp_query 474 395 * … … 477 398 function is_preview() { 478 399 global $wp_query; 479 400 480 return $wp_query->is_preview ;401 return $wp_query->is_preview(); 481 402 } 482 403 483 404 /** 484 * Whether the current query post is robots.405 * Is the query for the robots file? 485 406 * 407 * @see WP_Query::is_robots() 486 408 * @since 2.1.0 487 409 * @uses $wp_query 488 410 * … … 491 413 function is_robots() { 492 414 global $wp_query; 493 415 494 return $wp_query->is_robots ;416 return $wp_query->is_robots(); 495 417 } 496 418 497 419 /** 498 * Whether current query is the result of a user search.420 * Is the query for a search? 499 421 * 422 * @see WP_Query::is_search() 500 423 * @since 1.5.0 501 424 * @uses $wp_query 502 425 * … … 505 428 function is_search() { 506 429 global $wp_query; 507 430 508 return $wp_query->is_search ;431 return $wp_query->is_search(); 509 432 } 510 433 511 434 /** 512 * Whether the current page query is single page.435 * Is the query for a single post? 513 436 * 514 * The parameter can contain the post ID, post title, or post name. The515 * parameter can also be an array of those three values.437 * If the $post parameter is specified, this function will additionally 438 * check if the query is for one of the Posts specified. 516 439 * 517 * This applies to other post types, attachments, pages, posts. Just means that 518 * the current query has only a single object. 440 * Can also be used for attachments or any other post type except pages. 519 441 * 442 * @see is_page() 443 * @see is_singular() 444 * 445 * @see WP_Query::is_single() 520 446 * @since 1.5.0 521 447 * @uses $wp_query 522 448 * 523 * @param mixed $post Either post or list of posts to test against.449 * @param mixed $post Post ID, title, slug, or array of Post IDs, titles, and slugs. 524 450 * @return bool 525 451 */ 526 function is_single( $post = '') {452 function is_single( $post = '' ) { 527 453 global $wp_query; 528 454 529 if ( !$wp_query->is_single ) 530 return false; 531 532 if ( empty($post) ) 533 return true; 534 535 $post_obj = $wp_query->get_queried_object(); 536 537 $post = (array) $post; 538 539 if ( in_array( $post_obj->ID, $post ) ) 540 return true; 541 elseif ( in_array( $post_obj->post_title, $post ) ) 542 return true; 543 elseif ( in_array( $post_obj->post_name, $post ) ) 544 return true; 545 546 return false; 455 return $wp_query->is_single( $post ); 547 456 } 548 457 549 458 /** 550 * Whether is single post, is a page, or is an attachment.459 * Is the query for a single post of any post type (post, attachment, page, ... )? 551 460 * 461 * If the $post_types parameter is specified, this function will additionally 462 * check if the query is for one of the Posts Types specified. 463 * 464 * @see is_page() 465 * @see is_single() 466 * 467 * @see WP_Query::is_singular() 552 468 * @since 1.5.0 553 469 * @uses $wp_query 554 470 * 555 * @param string|array $post_types Optional. Post type or types to check in current query.471 * @param mixed $post_types Optional. Post Type or array of Post Types 556 472 * @return bool 557 473 */ 558 function is_singular( $post_types = '') {474 function is_singular( $post_types = '' ) { 559 475 global $wp_query; 560 476 561 if ( empty($post_types) || !$wp_query->is_singular ) 562 return $wp_query->is_singular; 563 564 $post_obj = $wp_query->get_queried_object(); 565 566 return in_array($post_obj->post_type, (array) $post_types); 477 return $wp_query->is_singular( $post_types ); 567 478 } 568 479 569 480 /** 570 * Whether the query contains a time.481 * Is the query for a specific time? 571 482 * 483 * @see WP_Query::is_time() 572 484 * @since 1.5.0 573 485 * @uses $wp_query 574 486 * … … 577 489 function is_time() { 578 490 global $wp_query; 579 491 580 return $wp_query->is_time ;492 return $wp_query->is_time(); 581 493 } 582 494 583 495 /** 584 * Whether the query is a trackback.496 * Is the query for a trackback endpoint call? 585 497 * 498 * @see WP_Query::is_trackback() 586 499 * @since 1.5.0 587 500 * @uses $wp_query 588 501 * … … 591 504 function is_trackback() { 592 505 global $wp_query; 593 506 594 return $wp_query->is_trackback ;507 return $wp_query->is_trackback(); 595 508 } 596 509 597 510 /** 598 * Whether the query contains a year.511 * Is the query for a specific year? 599 512 * 513 * @see WP_Query::is_year() 600 514 * @since 1.5.0 601 515 * @uses $wp_query 602 516 * … … 605 519 function is_year() { 606 520 global $wp_query; 607 521 608 return $wp_query->is_year ;522 return $wp_query->is_year(); 609 523 } 610 524 611 525 /** 612 * Whether current page query is a 404 and no results for WordPress query.526 * Is the query a 404 (returns no results)? 613 527 * 528 * @see WP_Query::is_404() 614 529 * @since 1.5.0 615 530 * @uses $wp_query 616 531 * 617 * @return bool True, if nothing is found matching WordPress Query.532 * @return bool 618 533 */ 619 534 function is_404() { 620 535 global $wp_query; 621 536 622 return $wp_query->is_404 ;537 return $wp_query->is_404(); 623 538 } 624 539 625 540 /* … … 2791 2706 $this->query($query); 2792 2707 } 2793 2708 } 2709 2710 /** 2711 * Is the query for an archive page? 2712 * 2713 * Month, Year, Category, Author, ... 2714 * 2715 * @since 3.1.0 2716 * 2717 * @return bool 2718 */ 2719 function is_archive() { 2720 return (bool) $this->is_archive; 2721 } 2722 2723 /** 2724 * Is the query for an attachment page? 2725 * 2726 * @since 3.1.0 2727 * 2728 * @return bool 2729 */ 2730 function is_attachment() { 2731 return (bool) $this->is_attachment; 2732 } 2733 2734 /** 2735 * Is the query for an author archive page? 2736 * 2737 * If the $author parameter is specified, this function will additionally 2738 * check if the query is for one of the authors specified. 2739 * 2740 * @since 3.1.0 2741 * 2742 * @param mixed $author Optional. User ID, nickname, nicename, or array of User IDs, nicknames, and nicenames 2743 * @return bool 2744 */ 2745 function is_author( $author = '' ) { 2746 if ( !$this->is_author ) 2747 return false; 2748 2749 if ( empty($author) ) 2750 return true; 2751 2752 $author_obj = $this->get_queried_object(); 2753 2754 $author = (array) $author; 2755 2756 if ( in_array( $author_obj->ID, $author ) ) 2757 return true; 2758 elseif ( in_array( $author_obj->nickname, $author ) ) 2759 return true; 2760 elseif ( in_array( $author_obj->user_nicename, $author ) ) 2761 return true; 2762 2763 return false; 2764 } 2765 2766 /** 2767 * Is the query for a category archive page? 2768 * 2769 * If the $category parameter is specified, this function will additionally 2770 * check if the query is for one of the categories specified. 2771 * 2772 * @since 3.1.0 2773 * 2774 * @param mixed $category Optional. Category ID, name, slug, or array of Category IDs, names, and slugs. 2775 * @return bool 2776 */ 2777 function is_category( $category = '' ) { 2778 if ( !$this->is_category ) 2779 return false; 2780 2781 if ( empty($category) ) 2782 return true; 2783 2784 $cat_obj = $this->get_queried_object(); 2785 2786 $category = (array) $category; 2787 2788 if ( in_array( $cat_obj->term_id, $category ) ) 2789 return true; 2790 elseif ( in_array( $cat_obj->name, $category ) ) 2791 return true; 2792 elseif ( in_array( $cat_obj->slug, $category ) ) 2793 return true; 2794 2795 return false; 2796 } 2797 2798 /** 2799 * Is the query for a tag archive page? 2800 * 2801 * If the $tag parameter is specified, this function will additionally 2802 * check if the query is for one of the tags specified. 2803 * 2804 * @since 3.1.0 2805 * 2806 * @param mixed $slug Optional. Tag slug or array of slugs. 2807 * @return bool 2808 */ 2809 function is_tag( $slug = '' ) { 2810 if ( !$this->is_tag ) 2811 return false; 2812 2813 if ( empty( $slug ) ) 2814 return true; 2815 2816 $tag_obj = $this->get_queried_object(); 2817 2818 $slug = (array) $slug; 2819 2820 if ( in_array( $tag_obj->slug, $slug ) ) 2821 return true; 2822 2823 return false; 2824 } 2825 2826 /** 2827 * Is the query for a taxonomy archive page? 2828 * 2829 * If the $taxonomy parameter is specified, this function will additionally 2830 * check if the query is for that specific $taxonomy. 2831 * 2832 * If the $term parameter is specified in addition to the $taxonomy parameter, 2833 * this function will additionally check if the query is for one of the terms 2834 * specified. 2835 * 2836 * @since 3.1.0 2837 * 2838 * @param mixed $taxonomy Optional. Taxonomy slug or slugs. 2839 * @param mixed $term. Optional. Term ID, name, slug or array of Term IDs, names, and slugs. 2840 * @return bool 2841 */ 2842 function is_tax( $taxonomy = '', $term = '' ) { 2843 global $wp_taxonomies; 2844 2845 if ( !$this->is_tax ) 2846 return false; 2847 2848 if ( empty( $taxonomy ) ) 2849 return true; 2850 2851 $queried_object = $this->get_queried_object(); 2852 $tax_array = array_intersect( array_keys( $wp_taxonomies ), (array) $taxonomy ); 2853 $term_array = (array) $term; 2854 2855 if ( empty( $term ) ) // Only a Taxonomy provided 2856 return isset( $queried_object->taxonomy ) && count( $tax_array ) && in_array( $queried_object->taxonomy, $tax_array ); 2857 2858 return isset( $queried_object->term_id ) && 2859 count( array_intersect( 2860 array( $queried_object->term_id, $queried_object->name, $queried_object->slug ), 2861 $term_array 2862 ) ); 2863 } 2864 2865 /** 2866 * Whether the current URL is within the comments popup window. 2867 * 2868 * @since 3.1.0 2869 * 2870 * @return bool 2871 */ 2872 function is_comments_popup() { 2873 return (bool) $this->is_comments_popup; 2874 } 2875 2876 /** 2877 * Is the query for a date archive? 2878 * 2879 * @since 3.1.0 2880 * 2881 * @return bool 2882 */ 2883 function is_date() { 2884 return (bool) $this->is_date; 2885 } 2886 2887 2888 /** 2889 * Is the query for a day archive? 2890 * 2891 * @since 3.1.0 2892 * 2893 * @return bool 2894 */ 2895 function is_day() { 2896 return (bool) $this->is_day; 2897 } 2898 2899 /** 2900 * Is the query for a feed? 2901 * 2902 * @since 3.1.0 2903 * 2904 * @return bool 2905 */ 2906 function is_feed() { 2907 return (bool) $this->is_feed; 2908 } 2909 2910 /** 2911 * Is the query for a comments feed? 2912 * 2913 * @since 3.1.0 2914 * 2915 * @return bool 2916 */ 2917 function is_comment_feed() { 2918 return (bool) $this->is_comment_feed; 2919 } 2920 2921 /** 2922 * Is the query for the front page of the site? 2923 * 2924 * This is for what is displayed at your site's main URL. 2925 * 2926 * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_on_front'. 2927 * 2928 * If you set a static page for the front page of your site, this function will return 2929 * true when viewing that page. 2930 * 2931 * Otherwise the same as @see WP_Query::is_home() 2932 * 2933 * @since 3.1.0 2934 * @uses is_home() 2935 * @uses get_option() 2936 * 2937 * @return bool True, if front of site. 2938 */ 2939 function is_front_page() { 2940 // most likely case 2941 if ( 'posts' == get_option( 'show_on_front') && $this->is_home() ) 2942 return true; 2943 elseif ( 'page' == get_option( 'show_on_front') && get_option( 'page_on_front' ) && $this->is_page( get_option( 'page_on_front' ) ) ) 2944 return true; 2945 else 2946 return false; 2947 } 2948 2949 /** 2950 * Is the query for the blog homepage? 2951 * 2952 * This is the page which shows the time based blog content of your site. 2953 * 2954 * Depends on the site's "Front page displays" Reading Settings 'show_on_front' and 'page_for_posts'. 2955 * 2956 * If you set a static page for the front page of your site, this function will return 2957 * true only on the page you set as the "Posts page". 2958 * 2959 * @see WP_Query::is_front_page() 2960 * 2961 * @since 3.1.0 2962 * 2963 * @return bool True if blog view homepage. 2964 */ 2965 function is_home() { 2966 return (bool) $this->is_home; 2967 } 2968 2969 /** 2970 * Is the query for a month archive? 2971 * 2972 * @since 3.1.0 2973 * 2974 * @return bool 2975 */ 2976 function is_month() { 2977 return (bool) $this->is_month; 2978 } 2979 2980 /** 2981 * Is the query for a single Page? 2982 * 2983 * If the $page parameter is specified, this function will additionally 2984 * check if the query is for one of the Pages specified. 2985 * 2986 * @see WP_Query::is_single() 2987 * @see WP_Query::is_singular() 2988 * 2989 * @since 3.1.0 2990 * 2991 * @param mixed $page Page ID, title, slug, or array of Page IDs, titles, and slugs. 2992 * @return bool 2993 */ 2994 function is_page( $page = '' ) { 2995 if ( !$this->is_page ) 2996 return false; 2997 2998 if ( empty( $page ) ) 2999 return true; 3000 3001 $page_obj = $this->get_queried_object(); 3002 3003 $page = (array) $page; 3004 3005 if ( in_array( $page_obj->ID, $page ) ) 3006 return true; 3007 elseif ( in_array( $page_obj->post_title, $page ) ) 3008 return true; 3009 else if ( in_array( $page_obj->post_name, $page ) ) 3010 return true; 3011 3012 return false; 3013 } 3014 3015 /** 3016 * Is the query for paged result and not for the first page? 3017 * 3018 * @since 3.1.0 3019 * 3020 * @return bool 3021 */ 3022 function is_paged() { 3023 return (bool) $this->is_paged; 3024 } 3025 3026 /** 3027 * Is the query for a post or page preview? 3028 * 3029 * @since 3.1.0 3030 * 3031 * @return bool 3032 */ 3033 function is_preview() { 3034 return (bool) $this->is_preview; 3035 } 3036 3037 /** 3038 * Is the query for the robots file? 3039 * 3040 * @since 3.1.0 3041 * 3042 * @return bool 3043 */ 3044 function is_robots() { 3045 return (bool) $this->is_robots; 3046 } 3047 3048 /** 3049 * Is the query for a search? 3050 * 3051 * @since 3.1.0 3052 * 3053 * @return bool 3054 */ 3055 function is_search() { 3056 return (bool) $this->is_search; 3057 } 3058 3059 /** 3060 * Is the query for a single post? 3061 * 3062 * If the $post parameter is specified, this function will additionally 3063 * check if the query is for one of the Posts specified. 3064 * 3065 * Can also be used for attachments or any other post type except pages. 3066 * 3067 * @see WP_Query::is_page() 3068 * @see WP_Query::is_singular() 3069 * 3070 * @since 3.1.0 3071 * 3072 * @param mixed $post Post ID, title, slug, or array of Post IDs, titles, and slugs. 3073 * @return bool 3074 */ 3075 function is_single( $post = '' ) { 3076 if ( !$this->is_single ) 3077 return false; 3078 3079 if ( empty($post) ) 3080 return true; 3081 3082 $post_obj = $this->get_queried_object(); 3083 3084 $post = (array) $post; 3085 3086 if ( in_array( $post_obj->ID, $post ) ) 3087 return true; 3088 elseif ( in_array( $post_obj->post_title, $post ) ) 3089 return true; 3090 elseif ( in_array( $post_obj->post_name, $post ) ) 3091 return true; 3092 3093 return false; 3094 } 3095 3096 /** 3097 * Is the query for a single post of any post type (post, attachment, page, ... )? 3098 * 3099 * If the $post_types parameter is specified, this function will additionally 3100 * check if the query is for one of the Posts Types specified. 3101 * 3102 * @see WP_Query::is_page() 3103 * @see WP_Query::is_single() 3104 * 3105 * @since 3.1.0 3106 * 3107 * @param mixed $post_types Optional. Post Type or array of Post Types 3108 * @return bool 3109 */ 3110 function is_singular( $post_types = '' ) { 3111 if ( empty( $post_types ) || !$this->is_singular ) 3112 return $this->is_singular; 3113 3114 $post_obj = $this->get_queried_object(); 3115 3116 return in_array( $post_obj->post_type, (array) $post_types ); 3117 } 3118 3119 /** 3120 * Is the query for a specific time? 3121 * 3122 * @since 3.1.0 3123 * 3124 * @return bool 3125 */ 3126 function is_time() { 3127 return (bool) $this->is_time; 3128 } 3129 3130 /** 3131 * Is the query for a trackback endpoint call? 3132 * 3133 * @since 3.1.0 3134 * 3135 * @return bool 3136 */ 3137 function is_trackback() { 3138 return (bool) $this->is_trackback; 3139 } 3140 3141 /** 3142 * Is the query for a specific year? 3143 * 3144 * @since 3.1.0 3145 * 3146 * @return bool 3147 */ 3148 function is_year() { 3149 return (bool) $this->is_year; 3150 } 3151 3152 /** 3153 * Is the query a 404 (returns no results)? 3154 * 3155 * @since 3.1.0 3156 * 3157 * @return bool 3158 */ 3159 function is_404() { 3160 return (bool) $this->is_404; 3161 } 2794 3162 } 2795 3163 2796 3164 /** -
wp-includes/deprecated.php
2534 2534 _deprecated_function( __FUNCTION__, '3.0', 'term_exists()' ); 2535 2535 return term_exists( $term, $taxonomy, $parent ); 2536 2536 } 2537 2538 /** 2539 * Is the current admin page generated by a plugin? 2540 * 2541 * @since 1.5.0 2542 * @deprecated 3.1 2543 * @deprecated Use global $plugin_page and/or get_plugin_page_hookname() hooks. 2544 * 2545 * @global $plugin_page 2546 * 2547 * @return bool 2548 */ 2549 function is_plugin_page() { 2550 _deprecated_function( __FUNCTION__, '3.1' ); 2551 2552 global $plugin_page; 2553 2554 if ( isset($plugin_page) ) 2555 return true; 2556 2557 return false; 2558 }
