WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 15 months ago

#36860 closed enhancement

Introduce filter for users_have_content within delete action of users.php — at Version 6

Reported by: garrett-eclipse Owned by: garrett-eclipse
Milestone: 5.2 Priority: normal
Severity: normal Version: 4.6
Component: Users Keywords: has-patch needs-testing has-dev-note
Focuses: administration Cc:

Description (last modified by garrett-eclipse)

Hello,

I'd like to request an enhancement on the delete action for users.
Idea - https://wordpress.org/ideas/topic/introduce-filter-for-users_have_content-within-delete-action-of-usersphp?replies=1#post-30346

The addition of a filter for $users_have_content in the users.php
https://core.trac.wordpress.org/browser/tags/4.9.8/src/wp-admin/users.php#L214

Proposed filter;

<?php
/**
  * Filter the users_have_content, also known as the users have content flag, before use.
  *
  * @since ###
  *
  * @param boolean $users_have_content The flag for users have content.
  */
$users_have_content = apply_filters( 'users_have_content', $users_have_content, $userids ) );

Allows for plugins to introduce reassign capabilities when their user relational data isn't handled through the posts_author or link_owner database checks.
Example: Co Authors Plus saves additional author information in taxonomy terms. If a co-author is removed currently no reassignment can be made. With the filter the userids can be checked for coauthor relationships so as to enable the reassign user ability.

Thank you

Change History (9)

#1 @lukecavanagh
4 years ago

Seems like a useful fix for users who are using Co-Authors Plus plugin on a live site.

@garrett-eclipse
23 months ago

Initial Concept

#2 @garrett-eclipse
23 months ago

  • Keywords has-patch 2nd-opinion needs-testing needs-unit-tests added
  • Owner set to garrett-eclipse
  • Status changed from new to accepted

Thanks @lukecavanagh

I've put together an initial patch for this but will require review and unit tests.

I placed the filter prior to the WordPress checks to avoid plugins suppressing them and possibly losing users content. If needed another filter can be added after to support suppression but I fear that may have negative consequences.

If you could review and help me with next steps I'd appreciate the help.

Cheers

#3 @birgire
23 months ago

In 36860.diff I noticed a typo with an extra closing ).

@garrett-eclipse
23 months ago

Remove extra bracket

#4 @garrett-eclipse
23 months ago

  • Keywords 2nd-opinion removed

Thanks @birgire, Uploaded fix.

This ticket was mentioned in Slack in #core by garrett-eclipse. View the logs.


23 months ago

#6 @garrett-eclipse
23 months ago

  • Description modified (diff)
  • Milestone changed from Awaiting Review to 4.9.9

@garrett-eclipse
23 months ago

Wrap SQL checks in conditional to avoid unnecessary database calls

Note: See TracTickets for help on using tickets.