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