diff --git a/src/wp-includes/ms-site.php b/src/wp-includes/ms-site.php
index 6d854e3fb457..0b5a6e9c77b1 100644
|
a
|
b
|
function wp_uninitialize_site( $site_id ) { |
| 799 | 799 | switch_to_blog( $site->id ); |
| 800 | 800 | } |
| 801 | 801 | |
| 802 | | $uploads = wp_get_upload_dir(); |
| 803 | | |
| 804 | | $tables = $wpdb->tables( 'blog' ); |
| | 802 | $prep_query = $wpdb->prepare( 'SELECT table_name FROM information_schema.TABLES WHERE table_name LIKE %s;', $wpdb->esc_like( "{$wpdb->base_prefix}{$site->id}_" ) . '%' ); |
| | 803 | $tables = $wpdb->get_results( $prep_query, ARRAY_A ); |
| 805 | 804 | |
| 806 | 805 | /** |
| 807 | 806 | * Filters the tables to drop when the site is deleted. |
| 808 | 807 | * |
| 809 | 808 | * @since MU (3.0.0) |
| 810 | 809 | * |
| 811 | | * @param string[] $tables Array of names of the site tables to be dropped. |
| 812 | | * @param int $site_id The ID of the site to drop tables for. |
| | 810 | * @param string[] $drop_tables Array of names of the site tables to be dropped. |
| | 811 | * @param onject $site Contains the objects related to the subsite like the multisite site id that will be used to reference the drop tables for. |
| 813 | 812 | */ |
| 814 | 813 | $drop_tables = apply_filters( 'wpmu_drop_tables', $tables, $site->id ); |
| 815 | 814 | |
| 816 | 815 | foreach ( (array) $drop_tables as $table ) { |
| 817 | | $wpdb->query( "DROP TABLE IF EXISTS `$table`" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| | 816 | $table_name = $table['table_name']; |
| | 817 | |
| | 818 | $wpdb->query( "DROP TABLE IF EXISTS `$table_name`" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 818 | 819 | } |
| 819 | 820 | |
| 820 | 821 | /** |
| … |
… |
function wp_uninitialize_site( $site_id ) { |
| 822 | 823 | * |
| 823 | 824 | * @since MU (3.0.0) |
| 824 | 825 | * |
| 825 | | * @param string $basedir Uploads path without subdirectory. @see wp_upload_dir() |
| 826 | | * @param int $site_id The site ID. |
| | 826 | * @param object $uploads Uploads path object. @see wp_upload_dir() |
| | 827 | * @param string $dir Filtered actual subsite directory path to be deleted. |
| 827 | 828 | */ |
| | 829 | $uploads = wp_get_upload_dir(); |
| 828 | 830 | $dir = apply_filters( 'wpmu_delete_blog_upload_dir', $uploads['basedir'], $site->id ); |
| 829 | | $dir = rtrim( $dir, DIRECTORY_SEPARATOR ); |
| 830 | | $top_dir = $dir; |
| 831 | | $stack = array( $dir ); |
| 832 | | $index = 0; |
| 833 | | |
| 834 | | while ( $index < count( $stack ) ) { |
| 835 | | // Get indexed directory from stack. |
| 836 | | $dir = $stack[ $index ]; |
| 837 | | |
| 838 | | // phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged |
| 839 | | $dh = @opendir( $dir ); |
| 840 | | if ( $dh ) { |
| 841 | | $file = @readdir( $dh ); |
| 842 | | while ( false !== $file ) { |
| 843 | | if ( '.' === $file || '..' === $file ) { |
| 844 | | $file = @readdir( $dh ); |
| 845 | | continue; |
| 846 | | } |
| 847 | | |
| 848 | | if ( @is_dir( $dir . DIRECTORY_SEPARATOR . $file ) ) { |
| 849 | | $stack[] = $dir . DIRECTORY_SEPARATOR . $file; |
| 850 | | } elseif ( @is_file( $dir . DIRECTORY_SEPARATOR . $file ) ) { |
| 851 | | @unlink( $dir . DIRECTORY_SEPARATOR . $file ); |
| 852 | | } |
| 853 | | |
| 854 | | $file = @readdir( $dh ); |
| 855 | | } |
| 856 | | @closedir( $dh ); |
| 857 | | } |
| 858 | | $index++; |
| 859 | | } |
| 860 | 831 | |
| 861 | | $stack = array_reverse( $stack ); // Last added directories are deepest. |
| 862 | | foreach ( (array) $stack as $dir ) { |
| 863 | | if ( $dir != $top_dir ) { |
| 864 | | @rmdir( $dir ); |
| 865 | | } |
| 866 | | } |
| | 832 | require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'; |
| | 833 | require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php'; |
| | 834 | |
| | 835 | $fileSystemDirect = new WP_Filesystem_Direct( false ); |
| | 836 | |
| | 837 | $fileSystemDirect->rmdir( $dir, true ); |
| 867 | 838 | |
| 868 | 839 | // phpcs:enable WordPress.PHP.NoSilencedErrors.Discouraged |
| 869 | 840 | if ( $switch ) { |
diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php
index 9c189bd96d8f..cb8b8646c15e 100644
|
a
|
b
|
public function rmdir( $path ) { |
| 1386 | 1386 | */ |
| 1387 | 1387 | public function remove_added_uploads() { |
| 1388 | 1388 | $uploads = wp_upload_dir(); |
| 1389 | | $this->rmdir( $uploads['basedir'] ); |
| | 1389 | if ( is_dir( $uploads['basedir'] ) ) { |
| | 1390 | $this->rmdir( $uploads['basedir'] ); |
| | 1391 | } |
| 1390 | 1392 | } |
| 1391 | 1393 | |
| 1392 | 1394 | /** |