I’m developing a plugin, that is meant to work on external requests to a wordpress site.
The plugin will generate a .json
file, and will come with 2 default .css
style and 1 .css
file that will contain the common styling rules (I will combine them later).
My concerns stands at, where should I place the files and is it safe to create a simlink
between plugin’s assets folder and where the .json
file is generated at.
Plugin folder structure:
plugin/
assets/
common.css
blue.css
clear.css
plugin.php
plugin-class.php
And were currently the json
file is generated:
$dir = wp_upload_dir();
$dir = $dir['basedir'].'/plugin';
WP_Filesystem();
global $wp_filesystem;
if (wp_mkdir_p($dir))
$wp_filesystem->put_contents($dir.'/latestArticles.json', 'callback('.json_encode($toExport).')', 0644);
On a future release, I will allow the possibility for the files to be uploaded to a S3 Bucket, but meanwhile, I am currently placing them to the path mentioned above, mainly because all may requests to mm.site.com/...
are going through CloudFront
So, I am asking that if is safe to have (or recommended) a simlink
from site/wp-content/plugins/plugin/assets/
to site/wp-content/uploads/plugin/assets
? If not, where should I place my file, so they can be available from external requests?
I have used symbolic links for convenience for awhile on a dev server but they are not 100% reliable as some PHP functions will return the filesystem path of the target instead of the path to the symlink itself. The most notable example (though not really a function) is the magic constant
__FILE__
. (Also https://bugs.php.net/bug.php?id=46260) That can cause trouble, and it can be frustrating to sort out. For that reason I am moving away from symlinks even on the dev server. Perhaps with some combination of this and related functions you can make this work reliably, but I don’t think I would.If you are distributing this plugin publicly you have the additional problem of creating those symlinks on the various servers where the code needs to run.
Your files should not be any less accessible at
site/wp-content/plugins/plugin/assets/
thansite/wp-content/uploads/plugin/assets
if you get the permissions right, but I’d make them accessible over some other mechanism, like the AJAX API, if it were me.