WordPress.org

Make WordPress Core

Ticket #12526: has_term.2.diff

File has_term.2.diff, 3.8 KB (added by ptahdunbar, 9 years ago)

same as previous patch, but does not deprecate in_category.

  • wp-includes/category-template.php

     
    251251 * @param int|post object Optional.  Post to check instead of the current post. @since 2.7.0
    252252 * @return bool True if the current post is in any of the given categories.
    253253 */
    254 function in_category( $category, $_post = null ) {
    255         if ( empty( $category ) )
    256                 return false;
    257 
    258         if ( $_post ) {
    259                 $_post = get_post( $_post );
    260         } else {
    261                 $_post =& $GLOBALS['post'];
    262         }
    263 
    264         if ( !$_post )
    265                 return false;
    266 
    267         $r = is_object_in_term( $_post->ID, 'category', $category );
    268         if ( is_wp_error( $r ) )
    269                 return false;
    270         return $r;
     254function in_category( $category, $post = null ) {
     255        return has_category( $category, $post );
    271256}
    272257
    273258/**
     
    969954}
    970955
    971956/**
    972  * Check if the current post has any of given tags.
     957 * Check if the current post has any of given categories.
    973958 *
    974  * The given tags are checked against the post's tags' term_ids, names and slugs.
    975  * Tags given as integers will only be checked against the post's tags' term_ids.
    976  * If no tags are given, determines if post has any tags.
     959 * @since 3.0.0
    977960 *
    978  * Prior to v2.7 of WordPress, tags given as integers would also be checked against the post's tags' names and slugs (in addition to term_ids)
    979  * Prior to v2.7, this function could only be used in the WordPress Loop.
    980  * As of 2.7, the function can be used anywhere if it is provided a post ID or post object.
     961 * @uses is_object_in_term()
     962 * @see has_term()
    981963 *
     964 * @param string|int|array $tag Optional. The category name/category_id/slug or array of them to check for.
     965 * @param int|post object Optional.  Post to check instead of the current post.
     966 * @return bool True if the current post has any of the the given categories (or any category, if no category specified).
     967 */
     968function has_category( $category = '', $post = null ) {
     969        return has_term( $category, 'category', $post );
     970}
     971
     972/**
     973 * Check if the current post has any of given tags.
     974 *
    982975 * @since 2.6.0
    983976 *
    984977 * @uses is_object_in_term()
     978 * @see has_term()
    985979 *
    986  * @param string|int|array $tag Optional. The tag name/term_id/slug or array of them to check for.
     980 * @param string|int|array $tag Optional. The tag name/tag_id/slug or array of them to check for.
     981 * @param int|post object Optional.  Post to check instead of the current post.
     982 * @return bool True if the current post has any of the the given tags (or any tag, if no tag specified).
     983 */
     984function has_tag( $tag = '', $post = null ) {
     985        return has_term( $tag, 'post_tag', $post );
     986}
     987
     988
     989/**
     990 * Check if the current post has any of given terms.
     991 *
     992 * The given terms are checked against the post's terms' term_ids, names and slugs.
     993 * Terms given as integers will only be checked against the post's terms' term_ids.
     994 * If no terms are given, determines if post has any terms.
     995 *
     996 * @since 3.0.0
     997 *
     998 * @uses is_object_in_term()
     999 *
     1000 * @param string|int|array $tag Optional. The term name/term_id/slug or array of them to check for.
    9871001 * @param int|post object Optional.  Post to check instead of the current post. @since 2.7.0
    9881002 * @return bool True if the current post has any of the the given tags (or any tag, if no tag specified).
    9891003 */
    990 function has_tag( $tag = '', $_post = null ) {
    991         if ( $_post ) {
    992                 $_post = get_post( $_post );
    993         } else {
    994                 $_post =& $GLOBALS['post'];
    995         }
     1004function has_term( $term = '', $taxonomy = '', $post = null ) {
     1005        if ( $post )
     1006                $post = get_post( $post );
     1007        else
     1008                $post =& $GLOBALS['post'];
    9961009
    997         if ( !$_post )
     1010        if ( !$post )
    9981011                return false;
    9991012
    1000         $r = is_object_in_term( $_post->ID, 'post_tag', $tag );
     1013        $r = is_object_in_term( $post->ID, $taxonomy, $term );
    10011014        if ( is_wp_error( $r ) )
    10021015                return false;
    10031016        return $r;
    10041017}
    1005 
    10061018?>
    1007  No newline at end of file