Does WordPress still ask for FTP credentials for each file operation?

There is a reply from 2014, that is a great answer to a question I have, but WordPress changes, and I'm wondering if this is still true, "WP Filesystem API will ask for FTP credentials, but it will do so for each operation. They aren't stored persistently." Where does wordpress store the FTP credentials? If this is still true, I'm guessing that the interaction between WordPress and the host would be that the host would send the default (main) FTP …
Category: Web

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 append the contents into the files. It has only the put_contents(), Is there any way to append the file content using WordPress's FS?
Category: Web

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. /** * Create folder in /uploads/{$dir_name}/ * @return array() */ function get_dirpath( $dir_name = 'test' ) { $wp_info = wp_upload_dir(); // SSL workaround. if ( is_ssl() ) { $wp_info['baseurl'] = str_ireplace( 'http://', 'https://', $wp_info['baseurl'] ); } // Build the paths. $dir_info = array( 'path' => $wp_info['basedir'] . '/' . …
Category: Web

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 this example: In wp-content I have my-plugin-templates-folder which has to be listed by my-plugin. Does anybody met with configuration which disallow webserver process list this directory so I should use wp_filesystem?
Category: Web

Why doesn't WP_Image_Editor save images using the Filesystem API?

I was in the process checking some of my existing plugins for any unsafe filesystem accesses, when I ran across WP_Image_Editor's save function, which calls _save, which finally calls make_image (below). WP_Image_Editor was released in WP 3.5, while the Filesystem API has been around since WP 2.6, so I would presume that the reasoning is related to the specifics of the use-case rather than just not being changed to meet new standards. protected function make_image( $filename, $function, $arguments ) { …
Category: Web

How to set path with WP_Filesystem and ftp base / chroot

In my theme i will use the WP_Filesystem to write a file to for example: $file = get_template_directory().'/library/assets/css/wpless2css.css'; Which outputs something like /home/user/domain/http_docs/wp-contents/theme/mytheme/library/assets/css/wpless2css.css This will work unless the ftp user will be chroot to /home/user/domain/ (on some servers?). In the case of a chroot the WP_Filesystem can't find $file. A solution seems to define FTP_PATH in wp-config.php into /home/user/domain/ and use: if(FTP_BASE) $file = str_replace(FTP_BASE,'',get_template_directory()).'/library/assets/css/wpless2css.css'; I'm looking for a solution more robust and support for the different possible permissions systems.
Category: Web

Is there function similar to wp_upload_bits() that will allow uploading to a specific path?

wp_upload_bits() allows you to put arbitrary binary data into a file, but it selects the path where the file is placed and doesn't allow configuration of this destination besides the basename. There's always the option of playing with the Filesystem API directly, but I was wondering if there is a similar function to wp_upload_bits() that would wrap the logic for me. Last thing I want is to reinvent the wheel. It's probably not relevant, but the bits being uploaded are …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.