ms-default-constants.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. /**
  3. * Defines constants and global variables that can be overridden, generally in wp-config.php.
  4. *
  5. * @package WordPress
  6. * @subpackage Multisite
  7. * @since 3.0.0
  8. */
  9. /**
  10. * Defines Multisite upload constants.
  11. *
  12. * Exists for backward compatibility with legacy file-serving through
  13. * wp-includes/ms-files.php (wp-content/blogs.php in MU).
  14. *
  15. * @since 3.0.0
  16. */
  17. function ms_upload_constants() {
  18. // This filter is attached in ms-default-filters.php but that file is not included during SHORTINIT.
  19. add_filter( 'default_site_option_ms_files_rewriting', '__return_true' );
  20. if ( ! get_site_option( 'ms_files_rewriting' ) ) {
  21. return;
  22. }
  23. // Base uploads dir relative to ABSPATH.
  24. if ( ! defined( 'UPLOADBLOGSDIR' ) ) {
  25. define( 'UPLOADBLOGSDIR', 'wp-content/blogs.dir' );
  26. }
  27. // Note, the main site in a post-MU network uses wp-content/uploads.
  28. // This is handled in wp_upload_dir() by ignoring UPLOADS for this case.
  29. if ( ! defined( 'UPLOADS' ) ) {
  30. $site_id = get_current_blog_id();
  31. define( 'UPLOADS', UPLOADBLOGSDIR . '/' . $site_id . '/files/' );
  32. // Uploads dir relative to ABSPATH.
  33. if ( 'wp-content/blogs.dir' === UPLOADBLOGSDIR && ! defined( 'BLOGUPLOADDIR' ) ) {
  34. define( 'BLOGUPLOADDIR', WP_CONTENT_DIR . '/blogs.dir/' . $site_id . '/files/' );
  35. }
  36. }
  37. }
  38. /**
  39. * Defines Multisite cookie constants.
  40. *
  41. * @since 3.0.0
  42. */
  43. function ms_cookie_constants() {
  44. $current_network = get_network();
  45. /**
  46. * @since 1.2.0
  47. */
  48. if ( ! defined( 'COOKIEPATH' ) ) {
  49. define( 'COOKIEPATH', $current_network->path );
  50. }
  51. /**
  52. * @since 1.5.0
  53. */
  54. if ( ! defined( 'SITECOOKIEPATH' ) ) {
  55. define( 'SITECOOKIEPATH', $current_network->path );
  56. }
  57. /**
  58. * @since 2.6.0
  59. */
  60. if ( ! defined( 'ADMIN_COOKIE_PATH' ) ) {
  61. $site_path = parse_url( get_option( 'siteurl' ), PHP_URL_PATH );
  62. if ( ! is_subdomain_install() || is_string( $site_path ) && trim( $site_path, '/' ) ) {
  63. define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH );
  64. } else {
  65. define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' );
  66. }
  67. }
  68. /**
  69. * @since 2.0.0
  70. */
  71. if ( ! defined( 'COOKIE_DOMAIN' ) && is_subdomain_install() ) {
  72. if ( ! empty( $current_network->cookie_domain ) ) {
  73. define( 'COOKIE_DOMAIN', '.' . $current_network->cookie_domain );
  74. } else {
  75. define( 'COOKIE_DOMAIN', '.' . $current_network->domain );
  76. }
  77. }
  78. }
  79. /**
  80. * Defines Multisite file constants.
  81. *
  82. * Exists for backward compatibility with legacy file-serving through
  83. * wp-includes/ms-files.php (wp-content/blogs.php in MU).
  84. *
  85. * @since 3.0.0
  86. */
  87. function ms_file_constants() {
  88. /**
  89. * Optional support for X-Sendfile header
  90. *
  91. * @since 3.0.0
  92. */
  93. if ( ! defined( 'WPMU_SENDFILE' ) ) {
  94. define( 'WPMU_SENDFILE', false );
  95. }
  96. /**
  97. * Optional support for X-Accel-Redirect header
  98. *
  99. * @since 3.0.0
  100. */
  101. if ( ! defined( 'WPMU_ACCEL_REDIRECT' ) ) {
  102. define( 'WPMU_ACCEL_REDIRECT', false );
  103. }
  104. }
  105. /**
  106. * Defines Multisite subdomain constants and handles warnings and notices.
  107. *
  108. * VHOST is deprecated in favor of SUBDOMAIN_INSTALL, which is a bool.
  109. *
  110. * On first call, the constants are checked and defined. On second call,
  111. * we will have translations loaded and can trigger warnings easily.
  112. *
  113. * @since 3.0.0
  114. */
  115. function ms_subdomain_constants() {
  116. static $subdomain_error = null;
  117. static $subdomain_error_warn = null;
  118. if ( false === $subdomain_error ) {
  119. return;
  120. }
  121. if ( $subdomain_error ) {
  122. $vhost_deprecated = sprintf(
  123. /* translators: 1: VHOST, 2: SUBDOMAIN_INSTALL, 3: wp-config.php, 4: is_subdomain_install() */
  124. __( 'The constant %1$s <strong>is deprecated</strong>. Use the boolean constant %2$s in %3$s to enable a subdomain configuration. Use %4$s to check whether a subdomain configuration is enabled.' ),
  125. '<code>VHOST</code>',
  126. '<code>SUBDOMAIN_INSTALL</code>',
  127. '<code>wp-config.php</code>',
  128. '<code>is_subdomain_install()</code>'
  129. );
  130. if ( $subdomain_error_warn ) {
  131. trigger_error(
  132. sprintf(
  133. /* translators: 1: VHOST, 2: SUBDOMAIN_INSTALL */
  134. __( '<strong>Conflicting values for the constants %1$s and %2$s.</strong> The value of %2$s will be assumed to be your subdomain configuration setting.' ),
  135. '<code>VHOST</code>',
  136. '<code>SUBDOMAIN_INSTALL</code>'
  137. ) . ' ' . $vhost_deprecated,
  138. E_USER_WARNING
  139. );
  140. } else {
  141. _deprecated_argument( 'define()', '3.0.0', $vhost_deprecated );
  142. }
  143. return;
  144. }
  145. if ( defined( 'SUBDOMAIN_INSTALL' ) && defined( 'VHOST' ) ) {
  146. $subdomain_error = true;
  147. if ( SUBDOMAIN_INSTALL !== ( 'yes' === VHOST ) ) {
  148. $subdomain_error_warn = true;
  149. }
  150. } elseif ( defined( 'SUBDOMAIN_INSTALL' ) ) {
  151. $subdomain_error = false;
  152. define( 'VHOST', SUBDOMAIN_INSTALL ? 'yes' : 'no' );
  153. } elseif ( defined( 'VHOST' ) ) {
  154. $subdomain_error = true;
  155. define( 'SUBDOMAIN_INSTALL', 'yes' === VHOST );
  156. } else {
  157. $subdomain_error = false;
  158. define( 'SUBDOMAIN_INSTALL', false );
  159. define( 'VHOST', 'no' );
  160. }
  161. }