<!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>[16332] trunk: Replace get_the_category() with get_the_categories().</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/16332">16332</a></dd>
<dt>Author</dt> <dd>scribu</dd>
<dt>Date</dt> <dd>2010-11-12 20:05:37 +0000 (Fri, 12 Nov 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Replace get_the_category() with get_the_categories(). Props filosofo. Fixes <a href="http://trac.wordpress.org/ticket/15407">#15407</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesclasswppostslisttablephp">trunk/wp-admin/includes/class-wp-posts-list-table.php</a></li>
<li><a href="#trunkwpcontentthemestwentytenloopphp">trunk/wp-content/themes/twentyten/loop.php</a></li>
<li><a href="#trunkwpincludescategorytemplatephp">trunk/wp-includes/category-template.php</a></li>
<li><a href="#trunkwpincludesdeprecatedphp">trunk/wp-includes/deprecated.php</a></li>
<li><a href="#trunkwpincludesfeedphp">trunk/wp-includes/feed.php</a></li>
<li><a href="#trunkwpincludeslinktemplatephp">trunk/wp-includes/link-template.php</a></li>
<li><a href="#trunkwpincludesposttemplatephp">trunk/wp-includes/post-template.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesclasswppostslisttablephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-posts-list-table.php (16331 => 16332)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-posts-list-table.php        2010-11-12 18:40:51 UTC (rev 16331)
+++ trunk/wp-admin/includes/class-wp-posts-list-table.php        2010-11-12 20:05:37 UTC (rev 16332)
</span><span class="lines">@@ -596,7 +596,7 @@
</span><span class="cx">                         case 'categories':
</span><span class="cx">                         ?>
</span><span class="cx">                         <td <?php echo $attributes ?>><?php
</span><del>-                                $categories = get_the_category();
</del><ins>+                                $categories = get_the_categories();
</ins><span class="cx">                                 if ( !empty( $categories ) ) {
</span><span class="cx">                                         $out = array();
</span><span class="cx">                                         foreach ( $categories as $c ) {
</span></span></pre></div>
<a id="trunkwpcontentthemestwentytenloopphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-content/themes/twentyten/loop.php (16331 => 16332)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-content/themes/twentyten/loop.php        2010-11-12 18:40:51 UTC (rev 16331)
+++ trunk/wp-content/themes/twentyten/loop.php        2010-11-12 20:05:37 UTC (rev 16332)
</span><span class="lines">@@ -141,7 +141,7 @@
</span><span class="cx">         <?php endif; ?>
</span><span class="cx">
</span><span class="cx">                         <div class="entry-utility">
</span><del>-                                <?php if ( count( get_the_category() ) ) : ?>
</del><ins>+                                <?php if ( count( get_the_categories() ) ) : ?>
</ins><span class="cx">                                         <span class="cat-links">
</span><span class="cx">                                                 <?php printf( __( '<span class="%1$s">Posted in</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); ?>
</span><span class="cx">                                         </span>
</span></span></pre></div>
<a id="trunkwpincludescategorytemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/category-template.php (16331 => 16332)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/category-template.php        2010-11-12 18:40:51 UTC (rev 16331)
+++ trunk/wp-includes/category-template.php        2010-11-12 20:05:37 UTC (rev 16332)
</span><span class="lines">@@ -57,35 +57,19 @@
</span><span class="cx"> /**
</span><span class="cx"> * Retrieve post categories.
</span><span class="cx"> *
</span><del>- * @since 0.71
- * @uses $post
</del><ins>+ * @since 3.1
</ins><span class="cx"> *
</span><span class="cx"> * @param int $id Optional, default to current post ID. The post ID.
</span><span class="cx"> * @return array
</span><span class="cx"> */
</span><del>-function get_the_category( $id = false ) {
-        global $post;
</del><ins>+function get_the_categories( $id = false ) {
+        $categories = get_the_terms( $id, 'category' );
</ins><span class="cx">
</span><del>-        $id = (int) $id;
-        if ( !$id )
-                $id = (int) $post->ID;
-
-        $categories = get_object_term_cache( $id, 'category' );
-        if ( false === $categories ) {
-                $categories = wp_get_object_terms( $id, 'category' );
-                wp_cache_add($id, $categories, 'category_relationships');
-        }
-
-        if ( !empty( $categories ) )
-                usort( $categories, '_usort_terms_by_name' );
-        else
-                $categories = array();
-
</del><span class="cx">         foreach ( (array) array_keys( $categories ) as $key ) {
</span><span class="cx">                 _make_cat_compat( $categories[$key] );
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        return $categories;
</del><ins>+        return apply_filters( 'get_the_categories', $categories );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -155,7 +139,7 @@
</span><span class="cx"> */
</span><span class="cx"> function get_the_category_list( $separator = '', $parents='', $post_id = false ) {
</span><span class="cx">         global $wp_rewrite;
</span><del>-        $categories = get_the_category( $post_id );
</del><ins>+        $categories = get_the_categories( $post_id );
</ins><span class="cx">         if ( !is_object_in_taxonomy( get_post_type( $post_id ), 'category' ) )
</span><span class="cx">                 return apply_filters( 'the_category', '', $separator, $parents );
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpincludesdeprecatedphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/deprecated.php (16331 => 16332)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/deprecated.php        2010-11-12 18:40:51 UTC (rev 16331)
+++ trunk/wp-includes/deprecated.php        2010-11-12 20:05:37 UTC (rev 16332)
</span><span class="lines">@@ -72,17 +72,17 @@
</span><span class="cx"> *
</span><span class="cx"> * @since 0.71
</span><span class="cx"> * @deprecated 0.71
</span><del>- * @deprecated use get_the_category()
- * @see get_the_category()
</del><ins>+ * @deprecated use get_the_categories()
+ * @see get_the_categories()
</ins><span class="cx"> *
</span><span class="cx"> * @param bool $echo
</span><span class="cx"> * @return null|int
</span><span class="cx"> */
</span><span class="cx"> function the_category_ID($echo = true) {
</span><del>-        _deprecated_function( __FUNCTION__, '0.71', 'get_the_category()' );
</del><ins>+        _deprecated_function( __FUNCTION__, '0.71', 'get_the_categories()' );
</ins><span class="cx">
</span><span class="cx">         // Grab the first cat in the list.
</span><del>-        $categories = get_the_category();
</del><ins>+        $categories = get_the_categories();
</ins><span class="cx">         $cat = $categories[0]->term_id;
</span><span class="cx">
</span><span class="cx">         if ( $echo )
</span><span class="lines">@@ -108,7 +108,7 @@
</span><span class="cx">         _deprecated_function( __FUNCTION__, '0.71', 'get_the_category_by_ID()' );
</span><span class="cx">
</span><span class="cx">         // Grab the first cat in the list.
</span><del>-        $categories = get_the_category();
</del><ins>+        $categories = get_the_categories();
</ins><span class="cx">         $currentcat = $categories[0]->category_id;
</span><span class="cx">         if ( $currentcat != $previouscat ) {
</span><span class="cx">                 echo $before;
</span><span class="lines">@@ -2556,3 +2556,19 @@
</span><span class="cx">
</span><span class="cx">         return false;
</span><span class="cx"> }
</span><ins>+
+/**
+ * Retrieve post categories.
+ *
+ * @since 0.71
+ * @uses $post
+ * @deprecated 3.1
+ * @deprecated Use get_post_categories() instead.
+ *
+ * @param int $id Optional, default to current post ID. The post ID.
+ * @return array
+ */
+function get_the_category( $id = false ) {
+        _deprecated_function( __FUNCTION__, '3.1', 'get_the_categories()' );
+        return get_the_categories( $id );
+}
</ins></span></pre></div>
<a id="trunkwpincludesfeedphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/feed.php (16331 => 16332)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/feed.php        2010-11-12 18:40:51 UTC (rev 16331)
+++ trunk/wp-includes/feed.php        2010-11-12 20:05:37 UTC (rev 16332)
</span><span class="lines">@@ -299,7 +299,7 @@
</span><span class="cx"> function get_the_category_rss($type = null) {
</span><span class="cx">         if ( empty($type) )
</span><span class="cx">                 $type = get_default_feed();
</span><del>-        $categories = get_the_category();
</del><ins>+        $categories = get_the_categories();
</ins><span class="cx">         $tags = get_the_tags();
</span><span class="cx">         $the_list = '';
</span><span class="cx">         $cat_names = array();
</span></span></pre></div>
<a id="trunkwpincludeslinktemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/link-template.php (16331 => 16332)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/link-template.php        2010-11-12 18:40:51 UTC (rev 16331)
+++ trunk/wp-includes/link-template.php        2010-11-12 20:05:37 UTC (rev 16332)
</span><span class="lines">@@ -119,7 +119,7 @@
</span><span class="cx">
</span><span class="cx">                 $category = '';
</span><span class="cx">                 if ( strpos($permalink, '%category%') !== false ) {
</span><del>-                        $cats = get_the_category($post->ID);
</del><ins>+                        $cats = get_the_categories($post->ID);
</ins><span class="cx">                         if ( $cats ) {
</span><span class="cx">                                 usort($cats, '_usort_terms_by_ID'); // order by ID
</span><span class="cx">                                 $category = $cats[0]->slug;
</span></span></pre></div>
<a id="trunkwpincludesposttemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post-template.php (16331 => 16332)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post-template.php        2010-11-12 18:40:51 UTC (rev 16331)
+++ trunk/wp-includes/post-template.php        2010-11-12 20:05:37 UTC (rev 16332)
</span><span class="lines">@@ -349,7 +349,7 @@
</span><span class="cx">
</span><span class="cx">         // Categories
</span><span class="cx">         if ( is_object_in_taxonomy( $post->post_type, 'category' ) ) {
</span><del>-                foreach ( (array) get_the_category($post->ID) as $cat ) {
</del><ins>+                foreach ( (array) get_the_categories($post->ID) as $cat ) {
</ins><span class="cx">                         if ( empty($cat->slug ) )
</span><span class="cx">                                 continue;
</span><span class="cx">                         $classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->term_id);
</span></span></pre>
</div>
</div>
</body>
</html>