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’); }

Creating directory in uploads – wp_mkdir_p() or WP_Filesystem?

wp-content/uploads/ should be writable for the server (otherwise it would be impossible to upload a file, no?). If you are going to create something under this directory, it is safe to use wp_mkdir_p(). I would only use WP_Filesystem if there is a chance the server does not have permissions to write to the location, like … Read more