Articles of wp filesystem

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 that once you set FS_METHOD to anything else but direct , you need credentials to read/write to […]

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 use wp_filesystem?

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 […]

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 can i moved these files into the footer, currently both files are loading in header.

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 $file) //takes the content of the given folder { if(is_dir($file)) //check if it is another folder then recursively call itself on it delFolder($file); else unlink($file); […]

why there is a large file named core in wpmu's directory?

why the file named core is here? can i delete it? ls -lh total 37M -rw-rw-r– 1 hugemeow pg 16 2012-03-04 04:22 a.php -rw——- 1 hugemeow pg 30M 2012-10-16 10:41 core // this is the large file -rw-r–r– 1 hugemeow pg 397 2012-01-26 07:53 index.php -rw-r–r– 1 hugemeow pg 17K 2012-01-26 07:53 license.txt -rw-r–r– 1 […]

How do you use unzip_file()?

I have been trying to use the unzip_file() function. It says undefined so I looked into it and the WP_Filesystem() must be called and set up. So easy, right? require_once(ABSPATH .’/wp-admin/includes/file.php’); WP_Filesystem(); unzip_file( $zip, $dest ); Even this shows as undefined, and I don’t see any documentation on it. I am trying to use the […]

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’; if( !file_exists($filepath) ){ mkdir($dirpath); $fh = fopen($filepath, “w”); fclose($fh); } But I want to use native wp filesystem .I have tried if(!$wp_filesystem->is_dir( $dirpath) { $wp_filesystem->mkdir( $dirpath); } Now […]

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 organisational and version control purposes. The obvious candidate would be file_get_contents(), but its usage with WordPress is generally frowned upon. I’ve […]

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 directories, but I don’t understand it. How i made it and is it a .php file? Maybe the following code will […]