1

When developing a plugin, should I includes the blank index.php file and then add my functions in the plugin-name.php? Or is that unnecessary? What file structure is recommended?

This?

/some-plugin/some-plugin.php (functions)
/some-plugin/index.php (blank)

Or this?

/some-plugin/index.php (functions)

From doing some research on WPSE, I have found a Q&A related to my own question:

However, this question is over four years ago and I wanted to know if this is still a recommendation for ethical plugin development nowadays.

The answers that were given by Wyck and toscho bring up interesting points on both sides of the spectrum:

  1. For: security through obscurity works, bots compile the plugin lists right off WordPress.org and crawl the plugin's URL directly
  2. Against: unused PHP files in that directory are wasting time and memory when WordPress is searching for plugins

Are these two statements true? What's the latest update?

  • In my opinion, this question is an exact duplicate. Are the answers to X still valid?, is not a good question here, because it would result in many, many duplicates. – fuxia Aug 30 '16 at 9:15
  • @toscho On questions that are dated, how do we check if the answers still apply to the latest version of WordPress? – Ethan Jinks O'Sullivan Aug 30 '16 at 10:50
  • By testing it against the latest release. If there are no new issues, no need to re-ask. Otherwise, add a bounty to the existing question, asking for new answers. – fuxia Aug 30 '16 at 10:55
4

It is a good practice to include index.php, with and without a wordpress context. Appach 2.4+ IIRC will add a log message about a missing file if someone access the directory itself, which makes reading the error log more annoying.

As for the reason you quote, obviously this do not have any security related impact, and the "wordpress will have to parse one more file once a year".... you are a great developer if that is the only performance issue you have in your code, and with php 5.6 code caching even that claim might not be true any longer.

You can put your code in the index.php file but by now people have expectations about the naming of the "main" plugin file, and therefor it might create pointless confusion as most people will assume index.php is an empty file

|improve this answer|||||
  • When you say confusion are you referring to when people want to run a function to check if a plugin is activated by using is_plugin_active( 'some-plugin/some-plugin.php' ) because that is the expected format? From what I understand with your answer, adding at an index.php prevents unnecessary logging of a false error from Apache and using 'some-plugin/some-plugin.php' is a widely accepted practice in plugin development? – Ethan Jinks O'Sullivan Aug 31 '16 at 1:13
  • yes, you got it right. The confusion is from it being the widely accepted practice. People that do not pay attention to details like file size might assume for a moment that there are some files missing if you include your main code in index.php – Mark Kaplun Aug 31 '16 at 6:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.