From c86ff5da2dc040e9a5982b09a53cef274e3b50cf Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 21 Mar 2019 20:11:29 +0000 Subject: [PATCH] Users: Introduce `users_have_additional_content` filter to indicate whether the users being deleted have additional content associated with them outside of the `post_author` and `link_owner` relationships. Props garrett-eclipse, xkon, birgire. Fixes #36860. git-svn-id: https://develop.svn.wordpress.org/trunk@44967 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/users.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/wp-admin/users.php b/src/wp-admin/users.php index b79e5a8672..7ba4aed006 100644 --- a/src/wp-admin/users.php +++ b/src/wp-admin/users.php @@ -234,11 +234,23 @@ switch ( $wp_list_table->current_action() ) { $userids = array_map( 'intval', (array) $_REQUEST['users'] ); } - $users_have_content = false; - if ( $wpdb->get_var( "SELECT ID FROM {$wpdb->posts} WHERE post_author IN( " . implode( ',', $userids ) . ' ) LIMIT 1' ) ) { - $users_have_content = true; - } elseif ( $wpdb->get_var( "SELECT link_id FROM {$wpdb->links} WHERE link_owner IN( " . implode( ',', $userids ) . ' ) LIMIT 1' ) ) { - $users_have_content = true; + /** + * Filters whether the users being deleted have additional content + * associated with them outside of the `post_author` and `link_owner` relationships. + * + * @since 5.2.0 + * + * @param boolean $users_have_additional_content Whether the users have additional content. Default false. + * @param int[] $userids Array of IDs for users being deleted. + */ + $users_have_content = (bool) apply_filters( 'users_have_additional_content', false, $userids ); + + if ( ! $users_have_content ) { + if ( $wpdb->get_var( "SELECT ID FROM {$wpdb->posts} WHERE post_author IN( " . implode( ',', $userids ) . ' ) LIMIT 1' ) ) { + $users_have_content = true; + } elseif ( $wpdb->get_var( "SELECT link_id FROM {$wpdb->links} WHERE link_owner IN( " . implode( ',', $userids ) . ' ) LIMIT 1' ) ) { + $users_have_content = true; + } } if ( $users_have_content ) {