It’s not working at all
-
I tested without any plugins. If select Analytics.js no js file is generated in the CAOS cache. If I select gtag.js a js file is generated in the cache, but it is empty.
-
Hey! Thanks for reaching out. Sorry to hear it’s not working for you!
I’m carefully assuming it’s a permission issue. Yuo can try a few things:
– Change the cache directory under Advanced Settings to e.g. /caos/ (mind the trailing slash)
– Enable debug logging and click Save & Update, then share the debug log here (do not copy paste please ??)
– Check your PHP error log for any warnings and/or errors.Looking forward to your reply!
Thanks for the fast reply!
Where does the plugin require permissions?
It created created the cash folder and it has full access to it as it can create files. The js files are just empty, so it seems CAOS fails to download the analytics files from Google.
Yes, writing contents to a file also requires PHP to have certain permissions on your filesystem.
Have you tried the suggestions I gave you?
Yeah of course it requires “certain permission”, but which? We don’t allow write access for plugins in wp-content for obvious reason. So I can’t use the debug feature.
Okay, and the PHP error log? Does that give you anything useful?
This is in the PHP error log:
PHP Warning: ftp_pwd() expects parameter 1 to be resource, null given in /vl/www/xxx/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230
[13-May-2022 14:30:13 UTC] PHP Warning: filemtime(): stat failed for /vl/www/xxx/wp-content/uploads/caos/34c262ba.js in /vl/www/xx/wp-content/plugins/host-analyticsjs-local/includes/admin/class-settings.php on line 242Okay, the ftp_pwd() error is probably what’s causing it.
I’d have to do some debugging (and understand why it tries to use FTP, instead of cURL) and get back to you. Probably Monday, alright?
curl was disabled, but enabling it, didn’t solve the problem. Still the same errors.
If I click Regenerate Alias(es) no new js file is created in the CAOS cache.
Hope you can solve the issue on Monday.
Thanks! ??
I found the issue. You use WP_Filesystem to write the js files. This does not work in our environment because our web server user is not allowed to modify files in wp-content for security reasons. So, for instance, whenever we update plugins the webmaster has to provide credentials.
It is the first time in 15 years we had such an issue. We use several caching plugins that do not have an issue with our filesystem configuration. If you use file_put_contents like you do for the debug log file, it will work because this way we only need to grant write access to the caching folder.
I’m sorry for not getting back to you earlier. My (almost) 2yo started getting her last set of molars over the weekend, so that took up some time/sleep/patience/focus, etc. Haha
Anyway, the issue you’re having is weird to me, because
file_put_contents()
(which is basically a wrapper forfopen()
fwrite()
fclose()
, AFAIK) does basically the same as theWP_Filemanager
class.Can’t you grant access to CAOS’ newly created folder?
Otherwise, could you provide some more explanation why writing to the wp-contents file using error_log() does work, and WP_Filemanager in a deeper folder doesn’t, using your security configuration?
There are big differences between WP_Filesystem and file_put_contents(). You can find more info here: https://codex.www.ads-software.com/Filesystem_API
The main point about WP_FileSystem is that you can use different protocols to write files (FTP, SSH) thereby allowing write access even if the web server account has no access. It is useful for updating plugins because admins can provide FTP credentials to write to wp-content without giving the web server account write access. In my view, giving the web server account write access to executables is insanely insecure.
Thus, your plugin will only work if WP_FileSystem has write access to wp-content (no matter where you store your file) which many installations don’t allow. It is the first time I see a plugin to use WP_FileSystem to cache data.
On the other hand, if you use file_put_contents(), users of your plugin only have to give write access to the folder where the file is actually stored which obviously is much more secure.
Aha! I had no idea!
Sorry about that. I’ll refactor it and release an update soon!
Thanks for the info!
Hi @michael8888,
I released an update today which no longer uses WP_Filesystem. Are you willing to give it another try?
That was fast! Works now. Thanks a lot!
Good to hear! Thanks for getting back to me! Whenever you have the time, It’d help me greatly if you’d review my plugin and support.
Have a great day!
- The topic ‘It’s not working at all’ is closed to new replies.