WordPress.org

Make WordPress Core

Ticket #16358: 16358.3.diff

File 16358.3.diff, 3.8 KB (added by ryan, 6 years ago)

Use trash instead of force delete. Add phpdoc.

  • wp-includes/post.php

     
    2929                'hierarchical' => false,
    3030                'rewrite' => false,
    3131                'query_var' => false,
     32                'delete_with_user' => true,
    3233                'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ),
    3334        ) );
    3435
     
    4546                'hierarchical' => true,
    4647                'rewrite' => false,
    4748                'query_var' => false,
     49                'delete_with_user' => true,
    4850                'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ),
    4951        ) );
    5052
     
    6365                'rewrite' => false,
    6466                'query_var' => false,
    6567                'show_in_nav_menus' => false,
    66                 'supports' => array( 'comments' ),
     68                'delete_with_user' => true,
     69                'supports' => array( 'comments', 'author' ),
    6770        ) );
    6871
    6972        register_post_type( 'revision', array(
     
    8083                'rewrite' => false,
    8184                'query_var' => false,
    8285                'can_export' => false,
     86                'delete_with_user' => true,
     87                'supports' => array( 'author' ),
    8388        ) );
    8489
    8590        register_post_type( 'nav_menu_item', array(
     
    9196                '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
    9297                'hierarchical' => false,
    9398                'rewrite' => false,
     99                'delete_with_user' => false,
    94100                'query_var' => false,
    95101        ) );
    96102
     
    933939 *     * If false, a post type cannot be loaded at ?{query_var}={post_slug}
    934940 *     * If specified as a string, the query ?{query_var_string}={post_slug} will be valid.
    935941 * - can_export - Allows this post type to be exported. Defaults to true.
     942 * - delete_with_user - Whether to delete posts of this type when deleting a user.
     943 *     * If true, posts of this type belonging to the user will be moved to trash when then user is deleted.
     944 *     * If false, posts of this type belonging to the user will *not* be trashed or deleted.
     945 *     * If not set (the default), posts are trashed if post_type_supports('author'). Otherwise posts are not trashed or deleted.
    936946 * - _builtin - true if this post type is a native or "built-in" post_type. THIS IS FOR INTERNAL USE ONLY!
    937947 * - _edit_link - URL segement to use for edit link of this post type. THIS IS FOR INTERNAL USE ONLY!
    938948 *
     
    959969                'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null,
    960970                'can_export' => true,
    961971                'show_in_nav_menus' => null, 'show_in_menu' => null, 'show_in_admin_bar' => null,
     972                'delete_with_user' => null,
    962973        );
    963974        $args = wp_parse_args($args, $defaults);
    964975        $args = (object) $args;
  • wp-admin/includes/user.php

     
    243243        do_action('delete_user', $id);
    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) );
     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                }
    247254
     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
    253263                // Clean links