• Resolved Venutius

    (@venutius)


    Hi there,

    I’m writing a plugin that creates site specific data files and I’m wondering where best to locate those files? Looking around the WordPress directory structure I’m thinking that it might be best to create a directory in wp-content. however I need to be able to determine the file path to that directory and that does not seem trivial.

    What’s best practice?

    Thanks in advance.

Viewing 5 replies - 1 through 5 (of 5 total)
  • WP-Content goes first and followed by the uploads directory that is the only place where you can avoid file permission issues. by default, the directory is given write permission and for security reasons, the other directory might be locked down.

    Regarding determining the path to that directory, you can use the WP_CONTENT_DIR constant.

    For ways to discover this and other directories in WordPress refer to this codex article: https://codex.www.ads-software.com/Determining_Plugin_and_Content_Directories

    Thread Starter Venutius

    (@venutius)

    Thanks!

    I sometimes use directory where plugin constants self. You can use too. In root folder create /data folder.

    Another option is to put the data into the database. If it is a very little bit of data then it might fit into the options table under a few keys related to your plugin name, otherwise you can create a new table or tables, you will have complete control over them, the rest of WordPress never need know about them. You then use SQL to fetch your data.
    It all depends upon the data, how it is organized and what you want to do with it. Is it static or substantially static, or does it get updated ? Does it get updated by user interactions ? Updates could be difficult with a file organisation, routine with SQL.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Where to locate plugin data files?’ is closed to new replies.