WP_Filesystem usage within a block of code

Reading and writing to a file is going to be dicey. You are going to be fighting with file permissions if you save anywhere but the wp-content/uploads directory (and it looks like you want to save to the plugins directory). If you have sufficient control of the server, you may get this to work by editing permissions in the plugins directory, but I wouldn’t. It introduces, potentially, security problems. At any rate, requiring that directory permissions be edited will make your code very non-portable.

  1. You can save your file to wp-content/uploads but it may well
    accessible to snooping.
  2. You can use WP_Filesystem but you will need to get
    request_filesystem_credentials() working most likely. I don’t know
    what you mean by using it without admin_menu() but I am thinking
    you mean without the dialogue. If I remember correctly, if you
    hardcode credentials in to wp-config.php you won’t get the popup
    dialogue
    . You may be requiring users to edit files, which makes
    your code less portable.
  3. The best option to me is to simply not try to juggle data into and
    out of a file. Save your data as user meta in the database.