Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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/ than site/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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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