[wp-trac] [WordPress Trac] #12555: PHP warning on Users screen when post count = 0

WordPress Trac wp-trac at lists.automattic.com
Mon Mar 8 13:13:00 UTC 2010


#12555: PHP warning on Users screen when post count = 0
----------------------------+-----------------------------------------------
 Reporter:  kpdesign        |       Owner:     
     Type:  defect (bug)    |      Status:  new
 Priority:  normal          |   Milestone:  3.0
Component:  Administration  |     Version:  3.0
 Severity:  normal          |    Keywords:     
----------------------------+-----------------------------------------------
 I'm developing a wiki site that will consist of all pages (no posts).

 When viewing the Users screen, there is a PHP warning at the top of the
 page:

 {{{
 Warning: Invalid argument supplied for foreach() in
 /home/xxx/public_html/xxx/wp-includes/user.php on line 180
 }}}

 If posts have a status other than "Published" or there are no posts at
 all, the warning displays. As soon as I publish one post, the warning goes
 away.

 This happens in both single and multi-site 3.0 installs.

 This is a result of the change to user.php in
 [http://core.trac.wordpress.org/changeset/13576#file2 changeset 13576] in
 '''function count_many_users_posts()'''.

 {{{
 function count_many_users_posts($users) {
         global $wpdb;

         if (0 == count($users))
                 return array();

         $userlist = implode(',', $users);
         $where = get_posts_by_author_sql('post');

         $result = $wpdb->get_results( "SELECT post_author, COUNT(*) FROM
 $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author",
 ARRAY_N );

         $count = array();
         foreach($result as $row) {
                 $count[$row[0]] = $row[1];
         }

         foreach($users as $id) {
                 $id = (string) $id;
                 if (!isset($count[$id]))
                         $count[$id] = 0;
         }

         return $count;
 }
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/12555>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list