<!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 => $label ) {
</span><del>-        $class = '';
</del><ins>+        $class = ( $status == $comment_status ) ? ' class="current"' : '';
</ins><span class="cx">
</span><del>-        if ( $status == $comment_status )
-                $class = ' class="current"';
</del><span class="cx">         if ( !isset( $num_comments->$status ) )
</span><span class="cx">                 $num_comments->$status = 10;
</span><ins>+        if ( empty( $num_comments->$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"> <div class="tablenav">
</span><span class="cx">
</span><ins>+<?php if ( $comments ) { ?>
</ins><span class="cx"> <?php if ( $page_links ) : ?>
</span><span class="cx"> <div class="tablenav-pages"><?php $page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%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"> <div class="clear"></div>
</span><span class="cx">
</span><del>-<?php if ( $comments ) { ?>
</del><span class="cx"> <table class="widefat comments fixed" cellspacing="0">
</span><span class="cx"> <thead>
</span><span class="cx">         <tr>
</span><span class="lines">@@ -436,7 +436,7 @@
</span><span class="cx"> </form>
</span><span class="cx">
</span><span class="cx"> <?php } else { ?>
</span><del>-<p><?php _e('No results found.') ?></p>
</del><ins>+<p><?php _e('No comments found.') ?></p>
</ins><span class="cx"> </form>
</span><span class="cx">
</span><span class="cx"> <?php } ?>
</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"> <div class="clear"></div>
</span><span class="cx"> <p><?php
</span><span class="cx"> if ( isset($_GET['post_status']) && '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"> ?></p>
</span><span class="cx"> <?php } ?>
</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"> <form id="posts-filter" action="" method="get">
</span><span class="cx"> <div class="tablenav">
</span><span class="cx">
</span><ins>+<?php
+if ( 'all' == $cat_id )
+        $cat_id = '';
+$args = array( 'category' => $cat_id, 'hide_invisible' => 0, 'orderby' => $sqlorderby, 'hide_empty' => 0 );
+if ( ! empty( $_GET['s'] ) )
+        $args['search'] = $_GET['s'];
+$links = get_bookmarks( $args );
+if ( $links ) {
+?>
+
</ins><span class="cx"> <div class="alignleft actions">
</span><span class="cx"> <select name="action">
</span><span class="cx"> <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
</span><span class="lines">@@ -135,13 +145,6 @@
</span><span class="cx"> <div class="clear"></div>
</span><span class="cx">
</span><span class="cx"> <?php
</span><del>-if ( 'all' == $cat_id )
-        $cat_id = '';
-$args = array('category' => $cat_id, 'hide_invisible' => 0, 'orderby' => $sqlorderby, 'hide_empty' => 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"> ?>
</span><span class="lines">@@ -251,10 +254,6 @@
</span><span class="cx">         </tbody>
</span><span class="cx"> </table>
</span><span class="cx">
</span><del>-<?php } else { ?>
-<p><?php _e('No links found.') ?></p>
-<?php } ?>
-
</del><span class="cx"> <div class="tablenav">
</span><span class="cx">
</span><span class="cx"> <div class="alignleft actions">
</span><span class="lines">@@ -265,6 +264,10 @@
</span><span class="cx"> <input type="submit" value="<?php esc_attr_e('Apply'); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
</span><span class="cx"> </div>
</span><span class="cx">
</span><ins>+<?php } else { ?>
+<p><?php _e( 'No links found.' ) ?></p>
+<?php } ?>
+
</ins><span class="cx"> <br class="clear" />
</span><span class="cx"> </div>
</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"> ?>
</span><span class="cx"> </ul>
</span><span class="cx">
</span><ins>+<?php if ( ! empty( $plugins ) ) { ?>
+
</ins><span class="cx"> <div class="tablenav">
</span><span class="cx"> <?php
</span><span class="cx"> if ( $page_links )
</span><span class="lines">@@ -656,9 +658,13 @@
</span><span class="cx"> print_plugin_actions($status, "action2");
</span><span class="cx"> ?>
</span><span class="cx"> </div>
</span><ins>+<?php } elseif ( ! empty( $all_plugins ) ) { ?>
+<p><?php __( 'No plugins found.' ); ?></p>
+<?php } ?>
</ins><span class="cx"> </form>
</span><span class="cx">
</span><span class="cx"> <?php if ( empty($all_plugins) ) : ?>
</span><ins>+<br class="clear" />
</ins><span class="cx"> <p><?php _e('You do not appear to have any plugins available at this time.') ?></p>
</span><span class="cx"> <?php endif; ?>
</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->get_results( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1 LIMIT %d, %d", $start, $media_per_page ) );
</span><del>-                $page_links_total = ceil($wpdb->get_var( "SELECT FOUND_ROWS()" ) / $media_per_page);
</del><ins>+                $total_orphans = $wpdb->get_var( "SELECT FOUND_ROWS()" );
+                $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->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1" );
</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 => $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']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
</span><span class="cx">                 $class = ' class="current"';
</span><ins>+        if ( !empty( $num_posts[$mime_type] ) )
+                $type_links[] = "<li><a href='upload.php?post_mime_type=$mime_type'$class>" . sprintf( _n( $label[2][0], $label[2][1], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</a>';
+}
+$type_links[] = '<li><a href="upload.php?detached=1"' . ( isset($_GET['detached']) ? ' class="current"' : '' ) . '>' . sprintf( _nx( 'Unattached <span class="count">(%s)</span>', 'Unattached <span class="count">(%s)</span>', $total_orphans, 'detached files' ), number_format_i18n( $total_orphans ) ) . '</a>';
</ins><span class="cx">
</span><del>-        $type_links[] = "<li><a href='upload.php?post_mime_type=$mime_type'$class>" . sprintf( _n( $label[2][0], $label[2][1], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '</a>';
-}
-$type_links[] = '<li><a href="upload.php?detached=1"' . ( isset($_GET['detached']) ? ' class="current"' : '' ) . '>' . __('Unattached') . '</a>';
-if ( EMPTY_TRASH_DAYS && ( MEDIA_TRASH || !empty($_num_posts['trash']) ) )
</del><ins>+if ( !empty($_num_posts['trash']) )
</ins><span class="cx">         $type_links[] = '<li><a href="upload.php?status=trash"' . ( (isset($_GET['status']) && $_GET['status'] == 'trash' ) ? ' class="current"' : '') . '>' . sprintf( _nx( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>', $_num_posts['trash'], 'uploaded files' ), number_format_i18n( $_num_posts['trash'] ) ) . '</a>';
</span><span class="cx">
</span><span class="cx"> echo implode( " |</li>\n", $type_links) . '</li>';
</span><span class="lines">@@ -255,6 +259,7 @@
</span><span class="cx"> </form>
</span><span class="cx">
</span><span class="cx"> <form id="posts-filter" action="" method="get">
</span><ins>+<?php if ( have_posts() || isset( $orphans ) ) { ?>
</ins><span class="cx"> <div class="tablenav">
</span><span class="cx"> <?php
</span><span class="cx"> if ( ! isset($page_links_total) )
</span><span class="lines">@@ -279,6 +284,7 @@
</span><span class="cx"> <?php endif; ?>
</span><span class="cx">
</span><span class="cx"> <div class="alignleft actions">
</span><ins>+<?php if ( ! isset( $orphans ) || ! empty( $orphans ) ) { ?>
</ins><span class="cx"> <select name="action" class="select-action">
</span><span class="cx"> <option value="-1" selected="selected"><?php _e('Bulk Actions'); ?></option>
</span><span class="cx"> <?php if ( $is_trash ) { ?>
</span><span class="lines">@@ -328,7 +334,11 @@
</span><span class="cx">
</span><span class="cx"> <?php } // ! is_singular ?>
</span><span class="cx">
</span><del>-<?php if ( isset($_GET['detached']) ) { ?>
</del><ins>+<?php
+
+} // ! empty( $orphans )
+
+if ( isset($_GET['detached']) ) { ?>
</ins><span class="cx">         <input type="submit" id="find_detached" name="find_detached" value="<?php esc_attr_e('Scan for lost attachments'); ?>" class="button-secondary" />
</span><span class="cx"> <?php } elseif ( isset($_GET['status']) && $_GET['status'] == 'trash' && current_user_can('edit_others_posts') ) { ?>
</span><span class="cx">         <input type="submit" id="delete_all" name="delete_all" value="<?php esc_attr_e('Empty Trash'); ?>" class="button-secondary apply" />
</span><span class="lines">@@ -339,9 +349,11 @@
</span><span class="cx"> <br class="clear" />
</span><span class="cx"> </div>
</span><span class="cx">
</span><ins>+<?php } // have_posts() || !empty( $orphans ) ?>
+
</ins><span class="cx"> <div class="clear"></div>
</span><span class="cx">
</span><del>-<?php if ( isset($orphans) ) { ?>
</del><ins>+<?php if ( ! empty( $orphans ) ) { ?>
</ins><span class="cx"> <table class="widefat" cellspacing="0">
</span><span class="cx"> <thead>
</span><span class="cx"> <tr>
</span><span class="lines">@@ -365,7 +377,6 @@
</span><span class="cx">
</span><span class="cx"> <tbody id="the-list" class="list:post">
</span><span class="cx"> <?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->ID) );
</span><span class="lines">@@ -423,11 +434,7 @@
</span><span class="cx">                 } ?>
</span><span class="cx">                 <td class="date column-date"><?php echo $h_time ?></td>
</span><span class="cx">         </tr>
</span><del>-<?php        }
-
-        } else { ?>
-        <tr><td colspan="5"><?php _e('No media attachments found.') ?></td></tr>
-<?php } ?>
</del><ins>+<?php        } ?>
</ins><span class="cx"> </tbody>
</span><span class="cx"> </table>
</span><span class="cx">
</span><span class="lines">@@ -442,6 +449,8 @@
</span><span class="cx"> <div class="tablenav">
</span><span class="cx">
</span><span class="cx"> <?php
</span><ins>+if ( have_posts() || ! empty( $orphans ) ) {
+
</ins><span class="cx"> if ( $page_links )
</span><span class="cx">         echo "<div class='tablenav-pages'>$page_links_text</div>";
</span><span class="cx"> ?>
</span><span class="lines">@@ -466,6 +475,7 @@
</span><span class="cx"> <?php } ?>
</span><span class="cx"> </div>
</span><span class="cx">
</span><ins>+<?php } ?>
</ins><span class="cx"> <br class="clear" />
</span><span class="cx"> </div>
</span><span class="cx"> <?php find_posts_div(); ?>
</span></span></pre>
</div>
</div>
</body>
</html>