How to append_contents using WP_Filesystem?

WP_Filesystem abstraction is primarily meant for performing plugin/theme/core updates, especially in environments with restricted writes. As such it doesn’t really implement full range of possible file operations, as you noted there is no ability to write to the end of file in declared API. More so some possible implementations (depending on file system) might not … Read more

How do you use unzip_file()?

require_once(ABSPATH .’/wp-admin/includes/file.php’); global $wp_filesystem; if ( ! $filesystem ) { WP_Filesystem(); if ( ! $wp_filesystem ) nuke_the_world_because_wpfs_cannot_be_initialized_in_case_of_missing_arguments(‘!’); } $result = unzip_file( $zip, $dest ); if ( is_wp_error( $result ) ) nuke_the_world(); Maybe some error handling make it easier.

Copy a file from a plugin into my theme directory

To answer your question, you have specified the paths incorrectly: plugin_dir_path( __FILE__ ) already has a trailing slash at the end (having two trailing slashes should not be a problem, but safer is to have one) and get_stylesheet_directory() comes with no trailing slash at the end, so you have to add one before adding the … Read more

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

Initialize the WP filesystem and no more using file_put_contents function. Try this: […] global $wp_filesystem; // Initialize the WP filesystem, no more using ‘file-put-contents’ function if (empty($wp_filesystem)) { require_once (ABSPATH . ‘/wp-admin/includes/file.php’); WP_Filesystem(); } if(!$wp_filesystem->put_contents( $path, $css, 0644) ) { return __(‘Failed to create css file’); }