mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Don't delete nav menu items when the user that owns them is deleted.
* Introduce delete_with_user flag to register_post_type
* Set delete_with_user to false for the nav_menu_item post type
* Set it to true for all other core post types
* If delete_with_user is not set, fallback to post_type_supports('author')
Props nacin
Fixes #16358
git-svn-id: https://develop.svn.wordpress.org/trunk@20739 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -243,11 +243,21 @@ function wp_delete_user( $id, $reassign = 'novalue' ) {
|
||||
do_action('delete_user', $id);
|
||||
|
||||
if ( 'novalue' === $reassign || null === $reassign ) {
|
||||
$post_ids = $wpdb->get_col( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id) );
|
||||
$post_types_to_delete = array();
|
||||
foreach ( get_post_types( array(), 'objects' ) as $post_type ) {
|
||||
if ( $post_type->delete_with_user ) {
|
||||
$post_types_to_delete[] = $post_type->name;
|
||||
} elseif ( null === $post_type->delete_with_user && post_type_supports( $post_type->name, 'author' ) ) {
|
||||
$post_types_to_delete[] = $post_type->name;
|
||||
}
|
||||
}
|
||||
|
||||
$post_types_to_delete = apply_filters( 'post_types_to_delete_with_user', $post_types_to_delete, $id );
|
||||
$post_types_to_delete = implode( "', '", $post_types_to_delete );
|
||||
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d AND post_type IN ('$post_types_to_delete')", $id ) );
|
||||
if ( $post_ids ) {
|
||||
foreach ( $post_ids as $post_id )
|
||||
wp_delete_post($post_id);
|
||||
wp_delete_post( $post_id );
|
||||
}
|
||||
|
||||
// Clean links
|
||||
|
||||
Reference in New Issue
Block a user