I think looking at
https://codex.wordpress.org/Filesystem_API
could solve this, esp. “The WP Filesystem API Methodology” where tests are described to see if direct file writing permission is available or not.
Because when using the correct file writing methods from WP then if it can not write directly to file it should try FTP to write (and I have all FTP credentials in wp-config.php).
What do you think?
I think you should use
$wp_filesystem->put_contents()
Anonymous User 357386
(@anonymized-357386)
ok, i’ve make some change in makecss()
function makecss()
{
// make my_style.css and write write css code!
$mycustomcss = mycustomcss();
global $wp_filesystem;
if (empty($wp_filesystem))
{
require_once (ABSPATH . '/wp-admin/includes/file.php');
WP_Filesystem();
}
$makecss = $wp_filesystem->put_contents(css_path(), "/********* Do not edit this file *********/\n/*\nMy Custom CSS - Maked by Salvatore Noschese\na.k.a. DarkWolf - http://www://darkwolf.it/\n*/\n\n".mycustomcss(), 0644);
return $makecss;
}
if i send u track version, can u test?
Hi
I tested it with your function, does not seem to work.
Can you have a look at this:
http://ottopress.com/2011/tutorial-using-the-wp_filesystem/
And also maybe it would be possible to inject the custom css code from the db into wordpress when the .css file is not there?
Anonymous User 357386
(@anonymized-357386)
as u can see, i’ve used wp_filesystem.
the error when I open the page is:
Warning: mkdir(): Permission denied in /home/xyz/public_html/wp-content/plugins/my-custom-css/my-custom-css.php on line 31
so maybe also mkdir($dirpath, 0755, true); has to be replaced by a wp function?
Anonymous User 357386
(@anonymized-357386)
can u post line 31 code block?
or maybe the backups should be placed in the uploads folder because that will always have write permission.
// Fix no backup folder
$dirpath = plugin_dir_path(__FILE__).’_backup/’;
if (!is_dir($dirpath))
{
mkdir($dirpath, 0755, true);
}
===
Line 31 is: mkdir($dirpath, 0755, true);
Anonymous User 357386
(@anonymized-357386)
Anonymous User 357386
(@anonymized-357386)
I’ve test in local web server, and make more test.
A new info for me: WordPress delete plugin folder on upgrade. So, plugin try to re-create immediately thanks to some code fix, but isn’t a good way to work and isn’t compatible with backup feature.
Cause of it, i’ve rewrite to save style and backup i,side Content folder, and now, obviously, isn’t plus delete on upgrade and also backup list is maintained.
I’ve test more, and now release.
Sorry for this issue…
I hope now all can work fine (and best) 🙂
Hi
Thanks for the update.
But as stated above I think you should use the /wp-content/uploads/ folder for the css file and backups.
Because with my server configuration (apache running as wwwrun and not the owner of the webfiles) your script can not write to /wp-content/
Warning: filemtime(): stat failed for /home/xyz/public_html/wp-content/my_custom_css/my_style.css in /home/xyz/public_html/wp-content/plugins/my-custom-css/my-custom-css.php on line 199
So that means it still does not work for me.
But I think it would work if you write to /wp-content/uploads/ because WP has write permission for that directory
Thanks
To be more precise:
the folders
/wp-content/my_custom_css
and
/wp-content/my_custom_css/bkk
have been created, but there are no files in them, even when I click “save” on the my css settings page many times.
Anonymous User 357386
(@anonymized-357386)
Can u check your actual permission folder in this folder?
I’ve used wp* method… Now permission well be set correctly :/