Make WordPress Core


Ignore:
Timestamp:
05/08/2012 05:01:50 PM (13 years ago)
Author:
ryan
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/user.php

    r20581 r20739  
    244244
    245245    if ( 'novalue' === $reassign || null === $reassign ) {
    246         $post_ids = $wpdb->get_col( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id) );
    247 
     246        $post_types_to_delete = array();
     247        foreach ( get_post_types( array(), 'objects' ) as $post_type ) {
     248            if ( $post_type->delete_with_user ) {
     249                $post_types_to_delete[] = $post_type->name;
     250            } elseif ( null === $post_type->delete_with_user && post_type_supports( $post_type->name, 'author' ) ) {
     251                $post_types_to_delete[] = $post_type->name;
     252            }
     253        }
     254
     255        $post_types_to_delete = apply_filters( 'post_types_to_delete_with_user', $post_types_to_delete, $id );
     256        $post_types_to_delete = implode( "', '", $post_types_to_delete );
     257        $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 ) );
    248258        if ( $post_ids ) {
    249259            foreach ( $post_ids as $post_id )
    250                 wp_delete_post($post_id);
     260                wp_delete_post( $post_id );
    251261        }
    252262
Note: See TracChangeset for help on using the changeset viewer.