WordPress.org

Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#7774 closed defect (bug) (fixed)

Deleting a user does not update link category count

Reported by: TimButterfield Owned by: TimButterfield
Milestone: 2.8 Priority: normal
Severity: normal Version: 2.6.1
Component: Administration Keywords: has-patch
Focuses: Cc:
PR Number:

Description

I created an administrator user, logged in as that user, created a link category, and then created four pages assigned to that category. Later, when I deleted the user (not reassigning to admin), the links were deleted, but the link category still showed the count of four. The link category should have been decremented by the count of deleted links.

FYI: This was with version 2.6.2, though that was not available in the version drop-down for creating the ticket.

Attachments (1)

7774.diff (785 bytes) - added by scohoust 11 years ago.

Download all attachments as: .zip

Change History (5)

#1 @TimButterfield
11 years ago

The fix for this is to modify wp-admin\includes\user.php. In the wp_delete_user function, replace this code:

		// Clean links
		$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->links WHERE link_owner = %d", $id) );

with this code:

		// Clean links
		$link_ids = $wpdb->get_col( $wpdb->prepare("SELECT LINK_ID FROM $wpdb->links WHERE link_owner = %d", $id) );

		if ($link_ids) {
			foreach ($link_ids as $link_id)
				wp_delete_link($link_id);
		}

#2 @TimButterfield
11 years ago

  • Cc TimButterfield added
  • Component changed from General to Administration
  • Owner changed from anonymous to TimButterfield

#3 @scohoust
11 years ago

  • Cc wp@… added
  • Keywords has-patch added

Still present in r10963 but the above patch sorts it. I've added it as a diff.

@scohoust
11 years ago

#4 @ryan
11 years ago

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

(In [10975]) Use API to delete links when deleting a user. Props TimButterfield, scohoust. fixes #7774

Note: See TracTickets for help on using tickets.