1. I'm trying to write to create a file in my plugin directory but I'm getting permission issues on plugin activation.
  2. I'm also trying to create/modify a file in the wordpress root directory (it's ads.txt so it needs to be in the root dir to work)


How can I create both of these files in my WP plugin activation without changing permissions / owners of files?


  • I can get past #1 by including empty files at chmod 666 which I'd much rather leave at 664 - not sure how much of an issue this could be
  • I can get past #2 by manually by chmod theuser:theserver but of course I want to avoid users needing to do this.
  • I always have a define('FS_METHOD','direct'); in my wp-config.php but that's for sure no way to go in production. Why using files instead of pushing it to wp_options table? – seot Aug 30 '18 at 16:51
  • @seot Good point, I could do that for my config but the ads.txt needs to be available for search engines. I could potentially leverage mod rewrite module to make a virtual ads.txt, do you know if that's possible? – Jacksonkr Aug 30 '18 at 17:40

I can think here of two possibillites.

  1. Use the wp-content/uploads maybe for your text-file because the file permission restriction are more or less bypassed in this directory.
  2. Put all stuff to wp_options and write a page Template imitating the text-file like page_text.php

    /* Template Name: Text-Template */ 
    echo get_option('ads', false);

Create a page and asign the Text-Template and you have a virtual text-file

  • So ads.txt is an seo though for ads. It HAS to be on the web root for search engines to pick it up. Will option #2 allow for that? – Jacksonkr Aug 31 '18 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.