When developing it is necessary to test a lot both on the local and remote servers, and the paths to files and folders are different on these servers. Suppose WP_PLUGIN_DIR or WP_PLUGIN_URL, or in wp_upload_dir () there are basedir and baseurl return different results, i.e. Let's say that the path starting with http does not work on the local server.
Sometimes I confuse these paths, and I forget to change when moving from local to remote, then it is difficult to look for errors that appear.
Tell me, is there a universal solution so that you can register the path to files or folders once, so that it works equally on the local and remote servers?

  • Well, let's say a configuration file or environment variables. Cheap and angry. Also tested by time ... - Akina
  • @Akina can you give an example? - word
  • Why doesn't http work on the local server? What kind of server is he then ... - labris

1 answer 1

Constants and functions containing _DIR are designed to display the path to the folder on the server, whether it is local or remote.

Constants and functions containing _URL are designed to output a url (uniform resource locator) - Internet addresses.

With the correct use of these entities - you don’t need to change anything in the code when transferring a site from a local server to a remote one.

  • please tell me, let's say I am writing an image parser. I use copy for copying. How to specify the path to save on your server? those. You say that there are two types of paths (_DIR, _URL), which one should be indicated to save the image from the source site to your site? let's say copy (sourceSite, destSite) - word
  • > With the proper use of these entities - you don’t need to change anything in the code when transferring a site from a local server to a remote one. - word
  • When do you need to specify the path with .._ DIR, and in what case ..._ URL? - word
  • I have a lot of mistakes because of this confusion - word
  • you write the file file operations php: fopen, fclose, fwrite. They, of course, need to specify file paths. Well, for example: fopen( dirname(__FILE__) . '/cache/gmap.js') - KAGG Design