WordPress.org

Make WordPress Core

Ticket #14494: 14494.diff

File 14494.diff, 27.5 KB (added by mdawaffe, 10 years ago)
  • wp-includes/query.php

     
    9898 */
    9999
    100100/**
    101  * Is query requesting an archive page.
     101 * Is the query for an archive page?
    102102 *
     103 * Month, Year, Category, Author, ...
     104 *
     105 * @see WP_Query::is_archive()
    103106 * @since 1.5.0
    104107 * @uses $wp_query
    105108 *
    106  * @return bool True if page is archive.
     109 * @return bool
    107110 */
    108111function is_archive() {
    109112        global $wp_query;
    110113
    111         return $wp_query->is_archive;
     114        return $wp_query->is_archive();
    112115}
    113116
    114117/**
    115  * Is query requesting an attachment page.
     118 * Is the query for an attachment page?
    116119 *
     120 * @see WP_Query::is_attachment()
    117121 * @since 2.0.0
    118122 * @uses $wp_query
    119123 *
    120  * @return bool True if page is attachment.
     124 * @return bool
    121125 */
    122126function is_attachment() {
    123127        global $wp_query;
    124128
    125         return $wp_query->is_attachment;
     129        return $wp_query->is_attachment();
    126130}
    127131
    128132/**
    129  * Is query requesting an author page.
     133 * Is the query for an author archive page?
    130134 *
    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.
    134137 *
    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()
    142139 * @since 1.5.0
    143140 * @uses $wp_query
    144141 *
    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
    147144 */
    148 function is_author($author = '') {
     145function is_author( $author = '' ) {
    149146        global $wp_query;
    150147
    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 );
    169149}
    170150
    171151/**
    172  * Whether current page query contains a category name or given category name.
     152 * Is the query for a category archive page?
    173153 *
    174  * The category list can contain category IDs, names, or category slugs. If any
    175  * 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.
    176156 *
     157 * @see WP_Query::is_category()
    177158 * @since 1.5.0
    178159 * @uses $wp_query
    179160 *
    180  * @param string|array $category Optional.
     161 * @param mixed $category Optional. Category ID, name, slug, or array of Category IDs, names, and slugs.
    181162 * @return bool
    182163 */
    183 function is_category($category = '') {
     164function is_category( $category = '' ) {
    184165        global $wp_query;
    185166
    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 );
    204168}
    205169
    206170/**
    207  * Whether the current page query has the given tag slug or contains tag.
     171 * Is the query for a tag archive page?
    208172 *
     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()
    209177 * @since 2.3.0
    210178 * @uses $wp_query
    211179 *
    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.
    213181 * @return bool
    214182 */
    215183function is_tag( $slug = '' ) {
    216184        global $wp_query;
    217185
    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 );
    232187}
    233188
    234189/**
    235  * Whether the current query is for the given taxonomy and/or term.
     190 * Is the query for a taxonomy archive page?
    236191 *
    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.
    243194 *
     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()
    244200 * @since 2.5.0
    245201 * @uses $wp_query
    246202 *
    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 Slug
     203 * @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.
    249205 * @return bool
    250206 */
    251207function is_tax( $taxonomy = '', $term = '' ) {
    252208        global $wp_query, $wp_taxonomies;
    253209
    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 );
    272211}
    273212
    274213/**
    275214 * Whether the current URL is within the comments popup window.
    276215 *
     216 * @see WP_Query::is_comments_popup()
    277217 * @since 1.5.0
    278218 * @uses $wp_query
    279219 *
     
    282222function is_comments_popup() {
    283223        global $wp_query;
    284224
    285         return $wp_query->is_comments_popup;
     225        return $wp_query->is_comments_popup();
    286226}
    287227
    288228/**
    289  * Whether current URL is based on a date.
     229 * Is the query for a date archive?
    290230 *
     231 * @see WP_Query::is_date()
    291232 * @since 1.5.0
    292233 * @uses $wp_query
    293234 *
     
    296237function is_date() {
    297238        global $wp_query;
    298239
    299         return $wp_query->is_date;
     240        return $wp_query->is_date();
    300241}
    301242
    302243/**
    303  * Whether current blog URL contains a day.
     244 * Is the query for a day archive?
    304245 *
     246 * @see WP_Query::is_day()
    305247 * @since 1.5.0
    306248 * @uses $wp_query
    307249 *
     
    310252function is_day() {
    311253        global $wp_query;
    312254
    313         return $wp_query->is_day;
     255        return $wp_query->is_day();
    314256}
    315257
    316258/**
    317  * Whether current page query is feed URL.
     259 * Is the query for a feed?
    318260 *
     261 * @see WP_Query::is_feed()
    319262 * @since 1.5.0
    320263 * @uses $wp_query
    321264 *
     
    324267function is_feed() {
    325268        global $wp_query;
    326269
    327         return $wp_query->is_feed;
     270        return $wp_query->is_feed();
    328271}
    329272
    330273/**
    331  * Whether current page query is comment feed URL.
     274 * Is the query for a comments feed?
    332275 *
     276 * @see WP_Query::is_comments_feed()
    333277 * @since 3.0.0
    334278 * @uses $wp_query
    335279 *
     
    338282function is_comment_feed() {
    339283        global $wp_query;
    340284
    341         return $wp_query->is_comment_feed;
     285        return $wp_query->is_comment_feed();
    342286}
    343287
    344288/**
    345  * Whether current page query is the front of the site.
     289 * Is the query for the front page of the site?
    346290 *
     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()
    347301 * @since 2.5.0
    348302 * @uses is_home()
    349303 * @uses get_option()
     
    351305 * @return bool True, if front of site.
    352306 */
    353307function 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();
    361311}
    362312
    363313/**
    364  * Whether current page view is the blog homepage.
     314 * Is the query for the blog homepage?
    365315 *
    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.
    369317 *
     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()
    370326 * @since 1.5.0
    371327 * @uses $wp_query
    372328 *
     
    375331function is_home() {
    376332        global $wp_query;
    377333
    378         return $wp_query->is_home;
     334        return $wp_query->is_home();
    379335}
    380336
    381337/**
    382  * Whether current page query contains a month.
     338 * Is the query for a month archive?
    383339 *
     340 * @see WP_Query::is_month()
    384341 * @since 1.5.0
    385342 * @uses $wp_query
    386343 *
     
    389346function is_month() {
    390347        global $wp_query;
    391348
    392         return $wp_query->is_month;
     349        return $wp_query->is_month();
    393350}
    394351
    395352/**
    396  * Whether query is page or contains given page(s).
     353 * Is the query for a single Page?
    397354 *
    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.
    402357 *
    403  * The parameter can contain the page ID, page title, or page name. The
    404  * parameter can also be an array of those three values.
     358 * @see is_single()
     359 * @see is_singular()
    405360 *
     361 * @see WP_Query::is_single()
    406362 * @since 1.5.0
    407363 * @uses $wp_query
    408364 *
    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.
    410366 * @return bool
    411367 */
    412 function is_page($page = '') {
     368function is_page( $page = '' ) {
    413369        global $wp_query;
    414370
    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 );
    433372}
    434373
    435374/**
    436  * Whether query contains multiple pages for the results.
     375 * Is the query for paged result and not for the first page?
    437376 *
     377 * @see WP_Query::is_paged()
    438378 * @since 1.5.0
    439379 * @uses $wp_query
    440380 *
     
    443383function is_paged() {
    444384        global $wp_query;
    445385
    446         return $wp_query->is_paged;
     386        return $wp_query->is_paged();
    447387}
    448388
    449389/**
    450  * Whether the current page was created by a plugin.
     390 * Is the query for a post or page preview?
    451391 *
    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()
    472393 * @since 2.0.0
    473394 * @uses $wp_query
    474395 *
     
    477398function is_preview() {
    478399        global $wp_query;
    479400
    480         return $wp_query->is_preview;
     401        return $wp_query->is_preview();
    481402}
    482403
    483404/**
    484  * Whether the current query post is robots.
     405 * Is the query for the robots file?
    485406 *
     407 * @see WP_Query::is_robots()
    486408 * @since 2.1.0
    487409 * @uses $wp_query
    488410 *
     
    491413function is_robots() {
    492414        global $wp_query;
    493415
    494         return $wp_query->is_robots;
     416        return $wp_query->is_robots();
    495417}
    496418
    497419/**
    498  * Whether current query is the result of a user search.
     420 * Is the query for a search?
    499421 *
     422 * @see WP_Query::is_search()
    500423 * @since 1.5.0
    501424 * @uses $wp_query
    502425 *
     
    505428function is_search() {
    506429        global $wp_query;
    507430
    508         return $wp_query->is_search;
     431        return $wp_query->is_search();
    509432}
    510433
    511434/**
    512  * Whether the current page query is single page.
     435 * Is the query for a single post?
    513436 *
    514  * The parameter can contain the post ID, post title, or post name. The
    515  * 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.
    516439 *
    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.
    519441 *
     442 * @see is_page()
     443 * @see is_singular()
     444 *
     445 * @see WP_Query::is_single()
    520446 * @since 1.5.0
    521447 * @uses $wp_query
    522448 *
    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.
    524450 * @return bool
    525451 */
    526 function is_single($post = '') {
     452function is_single( $post = '' ) {
    527453        global $wp_query;
    528454
    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 );
    547456}
    548457
    549458/**
    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, ... )?
    551460 *
     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()
    552468 * @since 1.5.0
    553469 * @uses $wp_query
    554470 *
    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
    556472 * @return bool
    557473 */
    558 function is_singular($post_types = '') {
     474function is_singular( $post_types = '' ) {
    559475        global $wp_query;
    560476
    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 );
    567478}
    568479
    569480/**
    570  * Whether the query contains a time.
     481 * Is the query for a specific time?
    571482 *
     483 * @see WP_Query::is_time()
    572484 * @since 1.5.0
    573485 * @uses $wp_query
    574486 *
     
    577489function is_time() {
    578490        global $wp_query;
    579491
    580         return $wp_query->is_time;
     492        return $wp_query->is_time();
    581493}
    582494
    583495/**
    584  * Whether the query is a trackback.
     496 * Is the query for a trackback endpoint call?
    585497 *
     498 * @see WP_Query::is_trackback()
    586499 * @since 1.5.0
    587500 * @uses $wp_query
    588501 *
     
    591504function is_trackback() {
    592505        global $wp_query;
    593506
    594         return $wp_query->is_trackback;
     507        return $wp_query->is_trackback();
    595508}
    596509
    597510/**
    598  * Whether the query contains a year.
     511 * Is the query for a specific year?
    599512 *
     513 * @see WP_Query::is_year()
    600514 * @since 1.5.0
    601515 * @uses $wp_query
    602516 *
     
    605519function is_year() {
    606520        global $wp_query;
    607521
    608         return $wp_query->is_year;
     522        return $wp_query->is_year();
    609523}
    610524
    611525/**
    612  * Whether current page query is a 404 and no results for WordPress query.
     526 * Is the query a 404 (returns no results)?
    613527 *
     528 * @see WP_Query::is_404()
    614529 * @since 1.5.0
    615530 * @uses $wp_query
    616531 *
    617  * @return bool True, if nothing is found matching WordPress Query.
     532 * @return bool
    618533 */
    619534function is_404() {
    620535        global $wp_query;
    621536
    622         return $wp_query->is_404;
     537        return $wp_query->is_404();
    623538}
    624539
    625540/*
     
    27912706                        $this->query($query);
    27922707                }
    27932708        }
     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        }
    27943162}
    27953163
    27963164/**
  • wp-includes/deprecated.php

     
    25342534        _deprecated_function( __FUNCTION__, '3.0', 'term_exists()' );
    25352535        return term_exists( $term, $taxonomy, $parent );
    25362536}
     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 */
     2549function 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}