Move some files of plugin to the root directory with plugin activation

There is no safe way to do that, and even if you succeed, you will cause a lot of trouble for your users.

  • The root directory for the web site is $_SERVER['DOCUMENT_ROOT']. You might not have write access here, because that can, and maybe should, be turned off.

  • WordPress might be installed in a subdirectory; now it’s unclear what the “root” is from your point of view.

  • There might be other files with the same name already in that place, because your plugin might be active in some sites of a multisite, or one WP installation is used for multiple, separate sites.

If you need an address on the root level, use one of the better options:

  • register an endpoint
  • use a page template
  • hook into template_redirect to deliver your custom code