WordPress.org

Make WordPress Core

Ticket #17542: 17542.diff

File 17542.diff, 1.5 KB (added by kawauso, 7 years ago)

Delete on reset and check for attachment ID

  • wp-admin/custom-background.php

     
    105105                        check_admin_referer('custom-background-reset', '_wpnonce-custom-background-reset');
    106106                        remove_theme_mod('background_image');
    107107                        remove_theme_mod('background_image_thumb');
     108                        $attachment_id = get_theme_mod('background_image_attachment_id');
     109                        if ( $attachment_id )
     110                                wp_delete_attachment( $attachment_id, true );
     111                        remove_theme_mod('background_image_attachment_id');
    108112                        $this->updated = true;
    109113                        return;
    110114                }
    111115
    112116                if ( isset($_POST['remove-background']) ) {
    113                         // @TODO: Uploaded files are not removed here.
    114117                        check_admin_referer('custom-background-remove', '_wpnonce-custom-background-remove');
    115118                        set_theme_mod('background_image', '');
    116119                        set_theme_mod('background_image_thumb', '');
     120                        $attachment_id = get_theme_mod('background_image_attachment_id');
     121                        if ( $attachment_id )
     122                                wp_delete_attachment( $attachment_id, true );
     123                        set_theme_mod('background_image_attachment_id', '');
    117124                        $this->updated = true;
    118125                        return;
    119126                }
     
    354361                $thumbnail = wp_get_attachment_image_src( $id, 'thumbnail' );
    355362                set_theme_mod('background_image_thumb', esc_url( $thumbnail[0] ) );
    356363
     364                set_theme_mod( 'background_image_attachment_id', $id );
     365
    357366                do_action('wp_create_file_in_uploads', $file, $id); // For replication
    358367                $this->updated = true;
    359368        }