/wp-includes/ms-default-constants.php

https://bitbucket.org/skyarch-iijima/wordpress · PHP · 162 lines · 78 code · 17 blank · 67 comment · 27 complexity · 55fad8b8f4cd83131c4841ac4e9ea48d MD5 · raw file

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