I'm wondering when it is recommended to use the Filesystem API, and whether it's useful at all?

WordPress seems a little inconsistent when it comes to Filesystem API usage, it uses the API only in a few places when uploading and unpacking files, and that doesn't make much sense to me, I mean, where's to point in using it at all when there are a lot of other situations where the PHP filesystem functions are used for direct access? Uploading packages would work even when there are ownership "problems", however I'm pretty sure that these "problems" won't go away 5 minutes later when I'm utilizing any of the functions that are using for example fwrite directly.

So why should I as a plugin/theme developer care about it anyways when half of the WordPress functions I'm using does not rely on the Filesystem API, my plugin/theme wouldn't work correctly anyways, wouldn't it?


There is a bit of practical split about where WP can write files and if Filesystem API is invoked. It might be easier to see this divide not as technical, but as administrative.

There is user space.

Users must be able to do things like create attachments and must not need to have admin access credentials.

For these requirements uploads directory typically requires lax permissions and code that works with it is usually not using Filesystem API.

Rest is admin space.

Administrators/developers must be able to (over)write anything (plugins, themes, WP core itself) and have admin credentials.

For such functionality code is using Filesystem API and will prompt for credentials, if it can't accomplish task without them.

So rule of a thumb for development distributable code is roughly - uploads directory is one and only place in WP installation where you can expect to perform writes without using Filesystem API.

  • I thougt the problem is more about ownership rather than about being able to write files at all? Looking at the code in get_filesystem_method() it's both, however as you said, one can expect the uploads folder to be writeable, and so only the ownership thingy is left. – ndm Jun 6 '13 at 0:26
  • After reading this and this ticket comment, I think I finally understood the intention of the whole thing. So I guess one could say FTP usage is only for edge cases, and I should try using the Filesystem API in the admin space whenever possible, and otherwise there's not much need to care about? – ndm Jun 6 '13 at 0:26
  • @ndm as above - "much need to care" depends on where you want to write. In uploads just use PHP, outside uploads - use Filesystem API. Of course for private code in controlled environment you might just ignore Filesystem API indeed. – Rarst Jun 6 '13 at 6:46
  • Of course, if it were just for me I wouldn't care at all, my servers are set up corretly so that there won't be any ownership issues :) This is just for plugins/themes that I'm going to publish publicly. Thanks for your input. – ndm Jun 6 '13 at 15:23

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.