Make WordPress Core

Opened 14 years ago

Closed 14 years ago

#12555 closed defect (bug) (fixed)

PHP warning on Users screen when post count = 0

Reported by: kpdesign's profile kpdesign Owned by: nacin's profile nacin
Milestone: 3.0 Priority: normal
Severity: normal Version: 3.0
Component: Administration Keywords: has-patch commit
Focuses: Cc:


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 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;

Attachments (2)

12555.proper.diff (1.3 KB) - added by miqrogroove 14 years ago.
Reverts [13617]. Improves style.
10607-and-12555.diff (2.5 KB) - added by miqrogroove 14 years ago.
Unified patch, if needed.

Download all attachments as: .zip

Change History (7)

#1 @nacin
14 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [13617]) Fix warning in users.php. Fixes #12555

#2 @miqrogroove
14 years ago

  • Keywords needs-patch added
  • Resolution fixed deleted
  • Status changed from closed to reopened

14 years ago

Reverts [13617]. Improves style.

#3 @miqrogroove
14 years ago

  • Keywords has-patch added; needs-patch removed
  • Owner set to nacin
  • Status changed from reopened to assigned

Please revert [13617] and close as a duplicate of #10607.

I added some style improvements if you'd like to throw those in as well.

14 years ago

Unified patch, if needed.

#4 @miqrogroove
14 years ago

  • Keywords commit added

12555.proper.diff is ready to go since other ticket is now closed.

#5 @nacin
14 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [13680]) Fix notice on users admin panel. More or less reverts earlier fix, [13617]. props miqrogroove. fixes #12555

Note: See TracTickets for help on using tickets.