Opened 5 years ago

Closed 4 years ago

#7774 closed defect (bug) (fixed)

Deleting a user does not update link category count

Reported by: TimButterfield Owned by: TimButterfield
Priority: normal Milestone: 2.8
Component: Administration Version: 2.6.1
Severity: normal Keywords: has-patch
Cc: TimButterfield, wp@…

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 4 years ago.

Download all attachments as: .zip

Change History (5)

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);
		}
  • Cc TimButterfield added
  • Component changed from General to Administration
  • Owner changed from anonymous to TimButterfield
  • Cc wp@… added
  • Keywords has-patch added

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

comment:4   ryan4 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.