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

Seems like you have several misconceptions/misunderstanding about when/why and how you should write to files. In general never write to any directory in which code resides, either core code or themes and plugins code. Those directories might be shared between different wordpress instances, and therefor they are not appropriate to be used for data related … Read more

Running rmdir function on post save

Add this to your theme’s functions.php file: function wpse202681_save_post_action($post_id, $post_object, $update) { $folder = “/temp/files/”; delFolder($folder); } add_action( ‘save_post’, ‘wpse202681_save_post_action’, 10, 3 ); // + delFolder() function definition You will probably have to alter folder paths depending on your /temp/files/ location. This will execute everytime any post is saved. You can restrict it to only … Read more