<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[15677] trunk/wp-includes/category-template.php: has_term().</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/15677">15677</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-10-01 17:44:53 +0000 (Fri, 01 Oct 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>has_term(). Props ptahdunbar. fixes <a href="http://trac.wordpress.org/ticket/12526">#12526</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludescategorytemplatephp">trunk/wp-includes/category-template.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludescategorytemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/category-template.php (15676 => 15677)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/category-template.php        2010-10-01 01:32:31 UTC (rev 15676)
+++ trunk/wp-includes/category-template.php        2010-10-01 17:44:53 UTC (rev 15677)
</span><span class="lines">@@ -248,29 +248,14 @@
</span><span class="cx">  *
</span><span class="cx">  * @since 1.2.0
</span><span class="cx">  *
</span><del>- * @uses is_object_in_term()
</del><ins>+ * @uses has_term()
</ins><span class="cx">  *
</span><span class="cx">  * @param int|string|array $category Category ID, name or slug, or array of said.
</span><span class="cx">  * @param int|object $_post Optional. Post to check instead of the current post. (since 2.7.0)
</span><span class="cx">  * @return bool True if the current post is in any of the given categories.
</span><span class="cx">  */
</span><del>-function in_category( $category, $_post = null ) {
-        if ( empty( $category ) )
-                return false;
-
-        if ( $_post ) {
-                $_post = get_post( $_post );
-        } else {
-                $_post =&amp; $GLOBALS['post'];
-        }
-
-        if ( !$_post )
-                return false;
-
-        $r = is_object_in_term( $_post-&gt;ID, 'category', $category );
-        if ( is_wp_error( $r ) )
-                return false;
-        return $r;
</del><ins>+function in_category( $category, $post = null ) {
+        return has_term( $category, 'category', $post );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -971,7 +956,23 @@
</span><span class="cx">         echo apply_filters('the_terms', $term_list, $taxonomy, $before, $sep, $after);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx"> /**
</span><ins>+ * Check if the current post has any of given category.
+ *
+ * @since 3.1.0
+ *
+ * @uses has_term()
+ *
+ * @param string|int|array $tag Optional. The category name/term_id/slug or array of them to check for.
+ * @param int|object $post Optional. Post to check instead of the current post.
+ * @return bool True if the current post has any of the given categories (or any category, if no category specified).
+ */
+function has_category( $category = '', $post = null ) {
+        return has_term( $category, 'category', $post );
+}
+
+/**
</ins><span class="cx">  * Check if the current post has any of given tags.
</span><span class="cx">  *
</span><span class="cx">  * The given tags are checked against the post's tags' term_ids, names and slugs.
</span><span class="lines">@@ -984,25 +985,42 @@
</span><span class="cx">  *
</span><span class="cx">  * @since 2.6.0
</span><span class="cx">  *
</span><del>- * @uses is_object_in_term()
</del><ins>+ * @uses has_term()
</ins><span class="cx">  *
</span><span class="cx">  * @param string|int|array $tag Optional. The tag name/term_id/slug or array of them to check for.
</span><del>- * @param int|object $_post Optional. Post to check instead of the current post. (since 2.7.0)
- * @return bool True if the current post has any of the the given tags (or any tag, if no tag specified).
</del><ins>+ * @param int|object $post Optional. Post to check instead of the current post. (since 2.7.0)
+ * @return bool True if the current post has any of the given tags (or any tag, if no tag specified).
</ins><span class="cx">  */
</span><del>-function has_tag( $tag = '', $_post = null ) {
-        if ( $_post ) {
-                $_post = get_post( $_post );
-        } else {
-                $_post =&amp; $GLOBALS['post'];
-        }
</del><ins>+function has_tag( $tag = '', $post = null ) {
+        return has_term( $tag, 'post_tag', $post );
+}
</ins><span class="cx"> 
</span><del>-        if ( !$_post )
</del><ins>+/**
+ * Check if the current post has any of given terms.
+ * 
+ * The given terms are checked against the post's terms' term_ids, names and slugs.
+ * Terms given as integers will only be checked against the post's terms' term_ids.
+ * If no terms are given, determines if post has any terms.
+ *
+ * @since 3.1.0
+ *
+ * @uses is_object_in_term()
+ *
+ * @param string|int|array $term Optional. The term name/term_id/slug or array of them to check for.
+ * @param int|post object Optional.  Post to check instead of the current post.
+ * @since 2.7.0
+ * @return bool True if the current post has any of the given tags (or any tag, if no tag specified).
+ */
+function has_term( $term = '', $taxonomy = '', $post = null ) {
+        $post = get_post($post);
+
+        if ( !$post )
</ins><span class="cx">                 return false;
</span><span class="cx"> 
</span><del>-        $r = is_object_in_term( $_post-&gt;ID, 'post_tag', $tag );
</del><ins>+        $r = is_object_in_term( $post-&gt;ID, $taxonomy, $term );
</ins><span class="cx">         if ( is_wp_error( $r ) )
</span><span class="cx">                 return false;
</span><ins>+
</ins><span class="cx">         return $r;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>