index.php // 每个文件夹的沉默都是金?

index.php // Silence is golden in every folder?

我是否应该在我的插件中的每个文件夹中包含一个带有 //silence is golden 的 index.php?甚至 css、js 和图像文件夹?或者它只是包含代码/ php 文件的文件夹应该有 index.php 文件吗?

这篇来自 InMotion 的文章解释了为什么存在这样的文件:Silence is Golden

在此引用相关部分以防 link 将来出现故障:

The entire file is a placeholder. Whenever someone visits a web page, the server attempts to run index.php or index.html. If you take a look at your site directory’s index.php, you’ll see the code that generates a WordPress site.

Without index.php, anyone could just visit your site’s /wp-content folder and see all of the media, files, and directories it contains.

The index.php file functions like a privacy screen: it blocks visitors from directly accessing your directories.

或者您可以在 .htaccess 文件中使用以下代码来阻止目录列表,即使该 index.php 文件不存在也是如此:

Options –Indexes