Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use WP_Filesystem outside WP_admin

In the functions.php I included an file called ThemeOptions.php where I load options and generate the custom css. I did it very simple with file_get_contents, fopen and fwrite. Of course this approach triggered several warnings in Theme Check and thats why I am trying to implement in ThemeOptions.php the WP_Filesystem approach.

At the moment I get an ugly error from the site :Fatal error: Call to undefined function WP_Filesystem() in , and from what i understood its because i call WP_Filesystem outside WP_admin.

Is there any way of calling WP_Filesystem from outside WP_admin ? More specifically from a file included in functions.php ?

Thank you

like image 399
Arizona2014 Avatar asked Jun 29 '26 16:06

Arizona2014


1 Answers

use require_once(ABSPATH . 'wp-admin/includes/file.php');

like image 186
user1502679 Avatar answered Jul 04 '26 15:07

user1502679



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!