$directory, 'file' => '.htaccess', 'content' => 'deny from all', ), array( 'base' => $directory, 'file' => 'index.html', 'content' => '', ), ); foreach ( $files as $file ) { $file_path = trailingslashit( $file['base'] ) . $file['file']; if ( ! file_exists( $file_path ) ) { $wp_filesystem->put_contents( $file_path, $file['content'] ); } } } }