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