<!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>[13100] trunk/wp-admin: Consistently hide bulk actions, filters,
  and subpage links on admin panels when there are no items to show.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13100">13100</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2010-02-13 08:49:27 +0000 (Sat, 13 Feb 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Consistently hide bulk actions, filters, and subpage links on admin panels when there are no items to show. Fixes <a href="http://trac.wordpress.org/ticket/12086">#12086</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadmineditcommentsphp">trunk/wp-admin/edit-comments.php</a></li>
<li><a href="#trunkwpadmineditphp">trunk/wp-admin/edit.php</a></li>
<li><a href="#trunkwpadminlinkmanagerphp">trunk/wp-admin/link-manager.php</a></li>
<li><a href="#trunkwpadminpluginsphp">trunk/wp-admin/plugins.php</a></li>
<li><a href="#trunkwpadminuploadphp">trunk/wp-admin/upload.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadmineditcommentsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/edit-comments.php (13099 => 13100)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/edit-comments.php        2010-02-13 08:29:55 UTC (rev 13099)
+++ trunk/wp-admin/edit-comments.php        2010-02-13 08:49:27 UTC (rev 13100)
</span><span class="lines">@@ -192,12 +192,12 @@
</span><span class="cx">         $link = add_query_arg( 'comment_type', $comment_type, $link );
</span><span class="cx"> 
</span><span class="cx"> foreach ( $stati as $status =&gt; $label ) {
</span><del>-        $class = '';
</del><ins>+        $class = ( $status == $comment_status ) ? ' class=&quot;current&quot;' : '';
</ins><span class="cx"> 
</span><del>-        if ( $status == $comment_status )
-                $class = ' class=&quot;current&quot;';
</del><span class="cx">         if ( !isset( $num_comments-&gt;$status ) )
</span><span class="cx">                 $num_comments-&gt;$status = 10;
</span><ins>+        if ( empty( $num_comments-&gt;$status ) )
+                continue;
</ins><span class="cx">         $link = add_query_arg( 'comment_status', $status, $link );
</span><span class="cx">         if ( $post_id )
</span><span class="cx">                 $link = add_query_arg( 'p', absint( $post_id ), $link );
</span><span class="lines">@@ -270,6 +270,7 @@
</span><span class="cx"> 
</span><span class="cx"> &lt;div class=&quot;tablenav&quot;&gt;
</span><span class="cx"> 
</span><ins>+&lt;?php if ( $comments ) { ?&gt;
</ins><span class="cx"> &lt;?php if ( $page_links ) : ?&gt;
</span><span class="cx"> &lt;div class=&quot;tablenav-pages&quot;&gt;&lt;?php $page_links_text = sprintf( '&lt;span class=&quot;displaying-num&quot;&gt;' . __( 'Displaying %s&amp;#8211;%s of %s' ) . '&lt;/span&gt;%s',
</span><span class="cx">         number_format_i18n( $start + 1 ),
</span><span class="lines">@@ -346,7 +347,6 @@
</span><span class="cx"> 
</span><span class="cx"> &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
</span><span class="cx"> 
</span><del>-&lt;?php if ( $comments ) { ?&gt;
</del><span class="cx"> &lt;table class=&quot;widefat comments fixed&quot; cellspacing=&quot;0&quot;&gt;
</span><span class="cx"> &lt;thead&gt;
</span><span class="cx">         &lt;tr&gt;
</span><span class="lines">@@ -436,7 +436,7 @@
</span><span class="cx"> &lt;/form&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;?php } else { ?&gt;
</span><del>-&lt;p&gt;&lt;?php _e('No results found.') ?&gt;&lt;/p&gt;
</del><ins>+&lt;p&gt;&lt;?php _e('No comments found.') ?&gt;&lt;/p&gt;
</ins><span class="cx"> &lt;/form&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;?php } ?&gt;
</span></span></pre></div>
<a id="trunkwpadmineditphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/edit.php (13099 => 13100)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/edit.php        2010-02-13 08:29:55 UTC (rev 13099)
+++ trunk/wp-admin/edit.php        2010-02-13 08:49:27 UTC (rev 13100)
</span><span class="lines">@@ -399,9 +399,9 @@
</span><span class="cx"> &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
</span><span class="cx"> &lt;p&gt;&lt;?php
</span><span class="cx"> if ( isset($_GET['post_status']) &amp;&amp; 'trash' == $_GET['post_status'] )
</span><del>-        _e('No posts found in the trash');
</del><ins>+        _e( 'No posts found in the Trash.' );
</ins><span class="cx"> else
</span><del>-        _e('No posts found');
</del><ins>+        _e( 'No posts found.' );
</ins><span class="cx"> ?&gt;&lt;/p&gt;
</span><span class="cx"> &lt;?php } ?&gt;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminlinkmanagerphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/link-manager.php (13099 => 13100)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/link-manager.php        2010-02-13 08:29:55 UTC (rev 13099)
+++ trunk/wp-admin/link-manager.php        2010-02-13 08:49:27 UTC (rev 13100)
</span><span class="lines">@@ -99,6 +99,16 @@
</span><span class="cx"> &lt;form id=&quot;posts-filter&quot; action=&quot;&quot; method=&quot;get&quot;&gt;
</span><span class="cx"> &lt;div class=&quot;tablenav&quot;&gt;
</span><span class="cx"> 
</span><ins>+&lt;?php
+if ( 'all' == $cat_id )
+        $cat_id = '';
+$args = array( 'category' =&gt; $cat_id, 'hide_invisible' =&gt; 0, 'orderby' =&gt; $sqlorderby, 'hide_empty' =&gt; 0 );
+if ( ! empty( $_GET['s'] ) )
+        $args['search'] = $_GET['s'];
+$links = get_bookmarks( $args );
+if ( $links ) {
+?&gt;
+
</ins><span class="cx"> &lt;div class=&quot;alignleft actions&quot;&gt;
</span><span class="cx"> &lt;select name=&quot;action&quot;&gt;
</span><span class="cx"> &lt;option value=&quot;&quot; selected=&quot;selected&quot;&gt;&lt;?php _e('Bulk Actions'); ?&gt;&lt;/option&gt;
</span><span class="lines">@@ -135,13 +145,6 @@
</span><span class="cx"> &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;?php
</span><del>-if ( 'all' == $cat_id )
-        $cat_id = '';
-$args = array('category' =&gt; $cat_id, 'hide_invisible' =&gt; 0, 'orderby' =&gt; $sqlorderby, 'hide_empty' =&gt; 0);
-if ( !empty($_GET['s']) )
-        $args['search'] = $_GET['s'];
-$links = get_bookmarks( $args );
-if ( $links ) {
</del><span class="cx">         $link_columns = get_column_headers('link-manager');
</span><span class="cx">         $hidden = get_hidden_columns('link-manager');
</span><span class="cx"> ?&gt;
</span><span class="lines">@@ -251,10 +254,6 @@
</span><span class="cx">         &lt;/tbody&gt;
</span><span class="cx"> &lt;/table&gt;
</span><span class="cx"> 
</span><del>-&lt;?php } else { ?&gt;
-&lt;p&gt;&lt;?php _e('No links found.') ?&gt;&lt;/p&gt;
-&lt;?php } ?&gt;
-
</del><span class="cx"> &lt;div class=&quot;tablenav&quot;&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;div class=&quot;alignleft actions&quot;&gt;
</span><span class="lines">@@ -265,6 +264,10 @@
</span><span class="cx"> &lt;input type=&quot;submit&quot; value=&quot;&lt;?php esc_attr_e('Apply'); ?&gt;&quot; name=&quot;doaction2&quot; id=&quot;doaction2&quot; class=&quot;button-secondary action&quot; /&gt;
</span><span class="cx"> &lt;/div&gt;
</span><span class="cx"> 
</span><ins>+&lt;?php } else { ?&gt;
+&lt;p&gt;&lt;?php _e( 'No links found.' ) ?&gt;&lt;/p&gt;
+&lt;?php } ?&gt;
+
</ins><span class="cx"> &lt;br class=&quot;clear&quot; /&gt;
</span><span class="cx"> &lt;/div&gt;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminpluginsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/plugins.php (13099 => 13100)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/plugins.php        2010-02-13 08:29:55 UTC (rev 13099)
+++ trunk/wp-admin/plugins.php        2010-02-13 08:49:27 UTC (rev 13100)
</span><span class="lines">@@ -633,6 +633,8 @@
</span><span class="cx"> ?&gt;
</span><span class="cx"> &lt;/ul&gt;
</span><span class="cx"> 
</span><ins>+&lt;?php if ( ! empty( $plugins ) ) { ?&gt;
+
</ins><span class="cx"> &lt;div class=&quot;tablenav&quot;&gt;
</span><span class="cx"> &lt;?php
</span><span class="cx"> if ( $page_links )
</span><span class="lines">@@ -656,9 +658,13 @@
</span><span class="cx"> print_plugin_actions($status, &quot;action2&quot;);
</span><span class="cx"> ?&gt;
</span><span class="cx"> &lt;/div&gt;
</span><ins>+&lt;?php } elseif ( ! empty( $all_plugins ) ) { ?&gt;
+&lt;p&gt;&lt;?php __( 'No plugins found.' ); ?&gt;&lt;/p&gt;
+&lt;?php } ?&gt;
</ins><span class="cx"> &lt;/form&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;?php if ( empty($all_plugins) ) : ?&gt;
</span><ins>+&lt;br class=&quot;clear&quot; /&gt;
</ins><span class="cx"> &lt;p&gt;&lt;?php _e('You do not appear to have any plugins available at this time.') ?&gt;&lt;/p&gt;
</span><span class="cx"> &lt;?php endif; ?&gt;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminuploadphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/upload.php (13099 => 13100)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/upload.php        2010-02-13 08:29:55 UTC (rev 13099)
+++ trunk/wp-admin/upload.php        2010-02-13 08:49:27 UTC (rev 13100)
</span><span class="lines">@@ -143,7 +143,8 @@
</span><span class="cx">         } else {
</span><span class="cx">                 $start = ( (int) $_GET['paged'] - 1 ) * $media_per_page;
</span><span class="cx">                 $orphans = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb-&gt;posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent &lt; 1 LIMIT %d, %d&quot;, $start, $media_per_page ) );
</span><del>-                $page_links_total = ceil($wpdb-&gt;get_var( &quot;SELECT FOUND_ROWS()&quot; ) / $media_per_page);
</del><ins>+                $total_orphans = $wpdb-&gt;get_var( &quot;SELECT FOUND_ROWS()&quot; );
+                $page_links_total = ceil( $total_orphans / $media_per_page );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         $post_mime_types = get_post_mime_types();
</span><span class="lines">@@ -219,6 +220,8 @@
</span><span class="cx"> $type_links = array();
</span><span class="cx"> $_num_posts = (array) wp_count_attachments();
</span><span class="cx"> $_total_posts = array_sum($_num_posts) - $_num_posts['trash'];
</span><ins>+if ( !isset( $total_orphans ) )
+                $total_orphans = $wpdb-&gt;get_var( &quot;SELECT COUNT( * ) FROM $wpdb-&gt;posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent &lt; 1&quot; );
</ins><span class="cx"> $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
</span><span class="cx"> foreach ( $matches as $type =&gt; $reals )
</span><span class="cx">         foreach ( $reals as $real )
</span><span class="lines">@@ -234,11 +237,12 @@
</span><span class="cx"> 
</span><span class="cx">         if ( !empty($_GET['post_mime_type']) &amp;&amp; wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
</span><span class="cx">                 $class = ' class=&quot;current&quot;';
</span><ins>+        if ( !empty( $num_posts[$mime_type] ) )
+                $type_links[] = &quot;&lt;li&gt;&lt;a href='upload.php?post_mime_type=$mime_type'$class&gt;&quot; . sprintf( _n( $label[2][0], $label[2][1], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '&lt;/a&gt;';
+}
+$type_links[] = '&lt;li&gt;&lt;a href=&quot;upload.php?detached=1&quot;' . ( isset($_GET['detached']) ? ' class=&quot;current&quot;' : '' ) . '&gt;' . sprintf( _nx( 'Unattached &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Unattached &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', $total_orphans, 'detached files' ), number_format_i18n( $total_orphans ) ) . '&lt;/a&gt;';
</ins><span class="cx"> 
</span><del>-        $type_links[] = &quot;&lt;li&gt;&lt;a href='upload.php?post_mime_type=$mime_type'$class&gt;&quot; . sprintf( _n( $label[2][0], $label[2][1], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '&lt;/a&gt;';
-}
-$type_links[] = '&lt;li&gt;&lt;a href=&quot;upload.php?detached=1&quot;' . ( isset($_GET['detached']) ? ' class=&quot;current&quot;' : '' ) . '&gt;' . __('Unattached') . '&lt;/a&gt;';
-if ( EMPTY_TRASH_DAYS &amp;&amp; ( MEDIA_TRASH || !empty($_num_posts['trash']) ) )
</del><ins>+if ( !empty($_num_posts['trash']) )
</ins><span class="cx">         $type_links[] = '&lt;li&gt;&lt;a href=&quot;upload.php?status=trash&quot;' . ( (isset($_GET['status']) &amp;&amp; $_GET['status'] == 'trash' ) ? ' class=&quot;current&quot;' : '') . '&gt;' . sprintf( _nx( 'Trash &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Trash &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', $_num_posts['trash'], 'uploaded files' ), number_format_i18n( $_num_posts['trash'] ) ) . '&lt;/a&gt;';
</span><span class="cx"> 
</span><span class="cx"> echo implode( &quot; |&lt;/li&gt;\n&quot;, $type_links) . '&lt;/li&gt;';
</span><span class="lines">@@ -255,6 +259,7 @@
</span><span class="cx"> &lt;/form&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;form id=&quot;posts-filter&quot; action=&quot;&quot; method=&quot;get&quot;&gt;
</span><ins>+&lt;?php if ( have_posts() || isset( $orphans ) ) { ?&gt;
</ins><span class="cx"> &lt;div class=&quot;tablenav&quot;&gt;
</span><span class="cx"> &lt;?php
</span><span class="cx"> if ( ! isset($page_links_total) )
</span><span class="lines">@@ -279,6 +284,7 @@
</span><span class="cx"> &lt;?php endif; ?&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;div class=&quot;alignleft actions&quot;&gt;
</span><ins>+&lt;?php if ( ! isset( $orphans ) || ! empty( $orphans ) ) { ?&gt;
</ins><span class="cx"> &lt;select name=&quot;action&quot; class=&quot;select-action&quot;&gt;
</span><span class="cx"> &lt;option value=&quot;-1&quot; selected=&quot;selected&quot;&gt;&lt;?php _e('Bulk Actions'); ?&gt;&lt;/option&gt;
</span><span class="cx"> &lt;?php if ( $is_trash ) { ?&gt;
</span><span class="lines">@@ -328,7 +334,11 @@
</span><span class="cx"> 
</span><span class="cx"> &lt;?php } // ! is_singular ?&gt;
</span><span class="cx"> 
</span><del>-&lt;?php if ( isset($_GET['detached']) ) { ?&gt;
</del><ins>+&lt;?php
+
+} // ! empty( $orphans )
+
+if ( isset($_GET['detached']) ) { ?&gt;
</ins><span class="cx">         &lt;input type=&quot;submit&quot; id=&quot;find_detached&quot; name=&quot;find_detached&quot; value=&quot;&lt;?php esc_attr_e('Scan for lost attachments'); ?&gt;&quot; class=&quot;button-secondary&quot; /&gt;
</span><span class="cx"> &lt;?php } elseif ( isset($_GET['status']) &amp;&amp; $_GET['status'] == 'trash' &amp;&amp; current_user_can('edit_others_posts') ) { ?&gt;
</span><span class="cx">         &lt;input type=&quot;submit&quot; id=&quot;delete_all&quot; name=&quot;delete_all&quot; value=&quot;&lt;?php esc_attr_e('Empty Trash'); ?&gt;&quot; class=&quot;button-secondary apply&quot; /&gt;
</span><span class="lines">@@ -339,9 +349,11 @@
</span><span class="cx"> &lt;br class=&quot;clear&quot; /&gt;
</span><span class="cx"> &lt;/div&gt;
</span><span class="cx"> 
</span><ins>+&lt;?php } // have_posts() || !empty( $orphans ) ?&gt;
+
</ins><span class="cx"> &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
</span><span class="cx"> 
</span><del>-&lt;?php if ( isset($orphans) ) { ?&gt;
</del><ins>+&lt;?php if ( ! empty( $orphans ) ) { ?&gt;
</ins><span class="cx"> &lt;table class=&quot;widefat&quot; cellspacing=&quot;0&quot;&gt;
</span><span class="cx"> &lt;thead&gt;
</span><span class="cx"> &lt;tr&gt;
</span><span class="lines">@@ -365,7 +377,6 @@
</span><span class="cx"> 
</span><span class="cx"> &lt;tbody id=&quot;the-list&quot; class=&quot;list:post&quot;&gt;
</span><span class="cx"> &lt;?php
</span><del>-        if ( $orphans ) {
</del><span class="cx">                 foreach ( $orphans as $post ) {
</span><span class="cx">                         $class = 'alternate' == $class ? '' : 'alternate';
</span><span class="cx">                         $att_title = esc_html( _draft_or_post_title($post-&gt;ID) );
</span><span class="lines">@@ -423,11 +434,7 @@
</span><span class="cx">                 } ?&gt;
</span><span class="cx">                 &lt;td class=&quot;date column-date&quot;&gt;&lt;?php echo $h_time ?&gt;&lt;/td&gt;
</span><span class="cx">         &lt;/tr&gt;
</span><del>-&lt;?php        }
-
-        } else { ?&gt;
-        &lt;tr&gt;&lt;td colspan=&quot;5&quot;&gt;&lt;?php _e('No media attachments found.') ?&gt;&lt;/td&gt;&lt;/tr&gt;
-&lt;?php } ?&gt;
</del><ins>+&lt;?php        } ?&gt;
</ins><span class="cx"> &lt;/tbody&gt;
</span><span class="cx"> &lt;/table&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -442,6 +449,8 @@
</span><span class="cx"> &lt;div class=&quot;tablenav&quot;&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;?php
</span><ins>+if ( have_posts() || ! empty( $orphans ) ) {
+
</ins><span class="cx"> if ( $page_links )
</span><span class="cx">         echo &quot;&lt;div class='tablenav-pages'&gt;$page_links_text&lt;/div&gt;&quot;;
</span><span class="cx"> ?&gt;
</span><span class="lines">@@ -466,6 +475,7 @@
</span><span class="cx"> &lt;?php } ?&gt;
</span><span class="cx"> &lt;/div&gt;
</span><span class="cx"> 
</span><ins>+&lt;?php } ?&gt;
</ins><span class="cx"> &lt;br class=&quot;clear&quot; /&gt;
</span><span class="cx"> &lt;/div&gt;
</span><span class="cx"> &lt;?php find_posts_div(); ?&gt;
</span></span></pre>
</div>
</div>

</body>
</html>