• I am coming to completion on a plugin, and have a couple of questions for a seasoned plugin dev.

    Of course my plugin works on my default install, but I am wondering about people who have custom installs. Specifically:

    1. I am displaying a seperate page from my plugin. Which is better: To include the page in the plugin directory, so that it is easy to remove the entire plugin by removing one directory, or include it in the wp root directory, so that it is easy to call?
    2. If it is better to keep all pages in the plugin directory, how do I confidently reference files in the root? (I’ve seen installs where all WP files are in their own dir, with index.php in the root)
    3. How can I reference files in the plugin directory, when people can move the directory anywhere, or copy the files directly into the /plugins dir?
Viewing 3 replies - 1 through 3 (of 3 total)
  • I am not sure if this is the right way to do, but for one of my plugins I had the same problem. I did review some other quite popular plugins (like Subscribe 2 Comments) and they stored their additional pages in the WP root. So I did the same. This was back in good ol’ WP 1.5 days.

    For WP 2.0 you are now allowed to have your own plugins subdirectory in the /plugins dir. If I would release a brand new plugin, I would store _all_ of the plugin files into the plugins subdir, just to keep the files together and separating the WP install from the plugin.

    Thread Starter kennethwsmith

    (@kennethwsmith)

    Thanks, I want to keep them all in the plugin folder. But that raises the other part of my question:

    How can I reference files in the plugin directory, when people can move the directory anywhere, or copy the files directly into the /plugins dir?

    Solution is: They don’t. It’s simply not allowed. Your files must rely on the internal directory structure of your plugin. So the structure inside the /plugins/myplugin dir is fixed. The only thing that can change is the name of your plugin dir itself.

    Look into the PHP documentation at php.net and search for __FILE__, dirname() and basename() to see how to avoid hardcoded names.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Plugin almost finished, I have a couple of questions on Best Practices and such’ is closed to new replies.