Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

The Filesystem API abstracts out the functionality needed for reading and writing local files to the filesystem to be done securely, on a variety of host types.

0
votes
0answers
11 views

WP_Filesystem and global $wp_filesystem;

I am using this code to unzip the file and it woks ok: WP_Filesystem(); $unzipfile = unzip_file( $upload_path.$fileName, $upload_path); But when I want to delete the folder with files, I only ...
0
votes
1answer
17 views

What functions of WP_Filesystem allow me to create a file with code-generated contents in a directory?

I'm generating a very useful .dat file, but I read that file_put_contents if frowned upon and that WP_Filesystem should be used instead. I see no methods to take dynamic input and create a file and ...
1
vote
1answer
31 views

How do I edit the php/html for a particular post?

I am new to Wordpress but I am comfortable coding in html/php and want to create custom forms on some of my posts. My site is currently running on localhost. I feel very silly because I have been ...
1
vote
1answer
30 views

wp_filesystem put_contents issue with owner/group

I am using put_contents() function to put images on the server, works fine on localhost, though on server, the user group when the file are downloaded to server is "nginx nobody" and that is causing ...
0
votes
0answers
26 views

Change default wordpress FS owner

is it possible to change the default fs owner for wordpress? In our shared dev environment, we don't have access to the www-data user. Files created by wordpress under wp-content have the owner www-...
1
vote
1answer
114 views

Why my wordpress blog files are getting changed?

I have a blog on wordpress and is hosted on godaddy. I continously getting few of the core wordpress files changed automatically. My blog project is on git so I can figure it out easily and reset the ...
1
vote
3answers
378 views

Relative file paths in CSS when linking directly (not enqueuing)

I am creating a single-page child theme, in which (apologies to the Wordpress community) I am basically trying to stay out of using PHP or the Wordpress API as much as possible, because I really just ...
5
votes
1answer
63 views

Do I need to use WP_Filesystem when creating a downloadable file on the fly?

I have a method that creates a downloadable CSV on the fly when a button is clicked: header( 'Content-type: text/csv' ); header( 'Cache-Control: no-store, no-cache' ); header( 'Content-Disposition: ...
0
votes
0answers
19 views

Pushing Files to Wordpress

Can one mass migrate and update documents on a WordPress site. I think it would be best to explain via an example: Suppose I am running a WordPress site for an annual workshop. On a page of the ...
0
votes
0answers
43 views

Allowing all/different file type uploads

I've looked through a number of previously accepted answers, but none seem to work/apply to the latest versions of WordPress. I'm trying to allow .rfa file types to be uploaded to the media library. ...
0
votes
1answer
18 views

Is there a name for trivial WP PHP files like functions.php, archive php entry.php, page.php and so forth?

Is there a name for trivial WP PHP files like functions.php, archive php entry.php, page.php and so forth? Is there a "category" (in the general sense of the term) they all fall into? I want to know ...
1
vote
1answer
61 views

What to use , set_transient, set_option or file system? [closed]

I have a shortcode that can parse page contents. For example you give it a link to a GitHub md file , it reads it and saves the page content for you. $parse_atts = array( 'id' => $id, ...
0
votes
0answers
72 views

How to list files from specific directory

I am trying to list PDF files from specific directory, and I have tried solutions that I found online but they didn't work. Basically, admin will upload pdf files via FTP and I need to list them on ...
0
votes
0answers
13 views

Downloadable content file structure

I have a bunch of files that will be used as downloadable content. Do I have to upload it as media or can I just upload to a folder through FTP? If yes, which folder?
0
votes
1answer
73 views

Media Upload to custom database and Custom Directory

I started developing a Plugin.I wanted to keep a form where the user can send an input text and a video/image to the website.The image should enter into the folder and the URL of the image/video ...
0
votes
2answers
17 views

trying to locate the correct file to edit my internal linking anchor tags

I am trying to locate the correct file to edit my internal linking anchor tags i.e.<a href= Can anyone point me to to the correct file? When I view the source code I see about 50 of them but I am ...
3
votes
1answer
447 views

How to append_contents using WP_Filesystem?

I have scenario that appends the contents into the files, I was using normal file system function of PHP Now I have decided to use WordPress WP_Filesystem but I cannot see any methods of it which do ...
0
votes
1answer
341 views

Download a zip folder of selected files

I'm trying to download multiple files from the server in a zipped folder. Here is the code I have thus far: HTML <form method="post"> <input type="checkbox" name="checked[]" value="<?...
3
votes
2answers
527 views

How to fix the error “file_get_contents was found in the file functions.php”?

I am building a wordpress theme, I reach the step of finalization. Right now, I am struggling to fix an error raised by Theme Check, : file_get_contents was found in the file functions.php File ...
1
vote
0answers
82 views

Copy Folder to another Folder using WP Filesystem

I want to copy a plugin folder to another folder, outside the WordPress installation, but in the same host, accessible via the same FTP account. Is there a way? I read something about copying ...
0
votes
1answer
196 views

Right way to download file from source to destination

I'm trying to download a file from one location to another. The code is working perfect. Here is the code snippet: Helper Function - Create directory in /uploads/{$dir_name}/ and return paths. /** *...
4
votes
1answer
204 views

What exactly does $wp_filesystem->abspath() return?

The real problem I have when using the $wp_filesystem is defining the correct paths. In the documentation of the filesystem the path (for example for the plugins directory) is usually set like this: $...
0
votes
1answer
153 views

Why does unzip_file always return true but nothing happens?

I am trying to use the $wp_filesystem of WordPress to unzip a file located inside the wp-content/plugins and place it at the same location. However whatever I try the WordPress method unzip_file() ...
0
votes
1answer
143 views

Why WordPress not using WP_Filesystem

On wp-admin/plugin-editor.php and wp-admin/theme-editor.php, why WordPress not using $wp_filesystem to read and modify the file? if writing and modifying file do not require wp_filesystem then when to ...
2
votes
2answers
529 views

What's a simple but secure method to get file contents into WordPress?

The scenario I'm developing a plugin, and part of it requires lots of text content (help descriptions) that I would prefer to keep as separate text files (in a subdirectory within the plugin) for ...
0
votes
1answer
13 views

Wordpress upload path decalration

I am trying to use wp-filesystem to write css data.I have things working perfect here. $filepath = get_template_directory() . '/dynamic/'; $wp_filesystem->mkdir($filepath); But this ...
0
votes
1answer
100 views

Error Copying Directory On Plugin Activation

I am trying to copy directory using WP_Filesystem API with the method copy_dir() on plugin activation, but it is give me the following error message: Plugin could not be activated because it ...
1
vote
1answer
126 views

Should I use Filesystem API for reading files or listing directories?

I know that i should use Filesystem API to write files and I understand why but is there any difference if I read file with wp_filesystem or plain PHP? And what about listing directories? Consider ...
0
votes
1answer
151 views

Is there a way to use WP filesystem without credentials when FS_METHOD is NOT set to direct?

The title is handful but so is the issue. I am building a theme than can generate/compress CSS files . So I need to move some files around etc. All this was working flawlessly until I figured out ...
1
vote
2answers
1k views

Downloading File from Outside Web Root

I've set up some code to download zip files that exist in a folder above the web root. The download will be triggered from a user account page within WordPress. They don't need to be bank-level secure,...
1
vote
1answer
306 views

Creating directory and file using native wordpress file system

I am creating directory and a css file using conventional php method. Here it is $upload_dir = wp_upload_dir(); $dirpath = $upload_dir['basedir'] . '/dynamic/'; $filepath = $dirpath. 'dynamic.css'; ...
0
votes
1answer
200 views

Running rmdir function on post save

How can I make wordpress call this function when a post is saved? $folder = "/temp/files/"; //path of the folder to be removed function delFolder($folder) { foreach(glob($folder . '/*') as $...
2
votes
1answer
311 views

Can't access wp_filesystem in cron function

I'm writing a plugin for integrating WP with Visma. It will basically spit out an XML file every third hour using wp cron (going to setup server cron for wp-cron.php on the live site) and save it to ...
0
votes
1answer
65 views

WP_Filesystem usage within a block of code

What i am trying to do is to have this function working within my plugin block of code without having it as plugin on it own. My current and working solution outside wordpress is Save contents $...
0
votes
0answers
76 views

version control for wordpress? (wordpress folder and database at same time)

I am familiar with version control to some extent. I have been using git and github for school purposes. Now when I use wordpress it makes sense that I can use git when developing on my local ...
7
votes
3answers
1k views

Standard location for plugin to save/cache files?

Are there official guidelines on where a plugin should cache files? If not, is there a best-practice out there that I can follow? For example, a plugin grabs content from a back-end system ...
2
votes
4answers
1k views

Why cant the WP Filesystem API read googlefonts.json?

I've inherited a site built with a theme by Highgrade (southcentral) which is built using the Redux framework. I'm seeing the following error in the frontend and admin panel: Warning: Invalid ...
0
votes
1answer
4k views

Use WP_Filesystem to list files in directory

Is there a way to list files in a directory using WP_filesystem instead of something like: function listFolderFiles($dir){ $ffs = scandir($dir); echo '<ol>'; foreach($ffs as $ff){ ...
2
votes
1answer
2k views

Copy and delete a directory with WordPress functions

I have successfully used copy_dir() to copy a directory to a new location. How can I delete a directory using WordPress functions?
3
votes
1answer
722 views

Convenient way to use wp_filesystem

I'd like to use $wp_filesystem which seems to be the recommended way to manipulate file system objects in WordPress but compare this: plain PHP code: mkdir('abc'); WP Filesystem API code: $url = ...
0
votes
1answer
449 views

WP_Filesystem in custom customize control

I'm currently trying to edit the following file so it uses the WP_Filesystem methods instead of direct PHP filesystem calls: google-font-dropdown-custom-control.php My current code looks as follows: ...
0
votes
0answers
276 views

how to create or rewrite files in wordpress plugin folder

i'm developing my own plugin. in that i used a simple php file to generate contact vcards in the plugin folder. for this i used fopen & fwrite. but the file is not creating in the plugin folder. ...
0
votes
1answer
212 views

How to display dialog box to save file from wp_filesystem->put_contents function?

I have this fragment: if(!$wp_filesystem->put_contents( $file_path, $file_content, FS_CHMOD_FILE )) { echo 'error during creating the file'; } This code works properly, but instead of saving ...
2
votes
1answer
3k views

Copy a file from a plugin into my theme directory

I coded a wordpress plugin using php's 'copy()' to copy a file from my plugin directory to my theme directory, but it's not working: <? function file_replace() { $plugin_dir = plugin_dir_path(...
0
votes
1answer
434 views

How to include form for WP_Filesystem()?

I've used a bit of code to try and write a dynamic.css file to a theme folder and it works fine. BUT, it doesn't work on certain shared hosting situations so the request_filesystem_credentials() ...
3
votes
1answer
2k views

Convert PHP readfile to WP_Filesystem

In the script below, I need to convert the readfile to the WP_filesytem equivalent. However, I can't find same in Codex. Any help much appreciated. This script saves the settings.ini file to the user'...
4
votes
2answers
3k views

Call to a member function put_contents() on a non-object

I have a plugin and I am creating a css file in wp_content. I used this: $this->content_dir = WP_CONTENT_DIR . "/some_folder"; $path = $this->content_dir . 'options.css'; $css='some string'; ...
0
votes
3answers
517 views

How to move core js files into the footer

while testing for page speed, i found 2 js files that causes the speed delay, according to PageSpeed Insight. files names are /wp-includes/js/swfobject.js /wp-includes/js/comment-reply.min.js how ...
2
votes
2answers
2k views

Using wp_filesystem in Plugins to store customizer settings

I try to fix my plugin with the answers i got here: Using wp_filesystem in Plugins Background i wrote a theme (https://github.com/bassjobsen/jamedo-bootstrap-start-theme) and a plugin (https://github....
0
votes
1answer
617 views

Enabling XSendFile causes 404 for images on Wordpress Multisite / Network

I've compiled and installed the XSendFile module and added the following lines to my .htaccess: XSendFile On It shows up as being activated in <?php info() ?> under loaded modules. The ...