delete( $dir, true ); return; } $items = @scandir( $dir ); if ( false === $items ) { return; } foreach ( $items as $item ) { if ( '.' === $item || '..' === $item ) { continue; } $path = $dir . DIRECTORY_SEPARATOR . $item; if ( is_dir( $path ) && ! is_link( $path ) ) { wpzm_uninstall_delete_dir( $path ); } else { wp_delete_file( $path ); } } // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir @rmdir( $dir ); } /** * Clean temporary directories and files created by the plugin inside wp_upload_dir(). * * @return void */ function wpzm_uninstall_cleanup() { $upload_dir = wp_upload_dir(); $dirs_to_check = array(); if ( ! empty( $upload_dir['basedir'] ) && is_dir( $upload_dir['basedir'] ) ) { $upload_items = @scandir( $upload_dir['basedir'] ); if ( false !== $upload_items ) { foreach ( $upload_items as $u_item ) { if ( 0 === strpos( $u_item, 'marn-easy-migrate' ) || 0 === strpos( $u_item, 'marn-zip-backups' ) ) { $candidate = trailingslashit( $upload_dir['basedir'] ) . $u_item; if ( is_dir( $candidate ) ) { $dirs_to_check[] = $candidate; } } } } } // Clean temporary items from all found directories. foreach ( array_unique( $dirs_to_check ) as $b_dir ) { $items = @scandir( $b_dir ); if ( false !== $items ) { foreach ( $items as $item ) { $path = $b_dir . DIRECTORY_SEPARATOR . $item; if ( ( 0 === strpos( $item, 'tmp_' ) || 0 === strpos( $item, 'wpzm_tmp_' ) ) && is_dir( $path ) ) { wpzm_uninstall_delete_dir( $path ); } elseif ( ( 0 === strpos( $item, 'tmp_upload_' ) || in_array( $item, array( '.import_progress.php', '.export_active.php', '.import_progress.json', '.export_active.json' ), true ) ) && is_file( $path ) ) { wp_delete_file( $path ); } } } } } wpzm_uninstall_cleanup();