default-constants.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <?php
  2. /**
  3. * Defines constants and global variables that can be overridden, generally in wp-config.php.
  4. *
  5. * @package WordPress
  6. */
  7. /**
  8. * Defines initial WordPress constants
  9. *
  10. * @see wp_debug_mode()
  11. *
  12. * @since 3.0.0
  13. *
  14. * @global int $blog_id The current site ID.
  15. * @global string $wp_version The WordPress version string.
  16. */
  17. function wp_initial_constants() {
  18. global $blog_id;
  19. /**#@+
  20. * Constants for expressing human-readable data sizes in their respective number of bytes.
  21. *
  22. * @since 4.4.0
  23. */
  24. define( 'KB_IN_BYTES', 1024 );
  25. define( 'MB_IN_BYTES', 1024 * KB_IN_BYTES );
  26. define( 'GB_IN_BYTES', 1024 * MB_IN_BYTES );
  27. define( 'TB_IN_BYTES', 1024 * GB_IN_BYTES );
  28. /**#@-*/
  29. // Start of run timestamp.
  30. if ( ! defined( 'WP_START_TIMESTAMP' ) ) {
  31. define( 'WP_START_TIMESTAMP', microtime( true ) );
  32. }
  33. $current_limit = ini_get( 'memory_limit' );
  34. $current_limit_int = wp_convert_hr_to_bytes( $current_limit );
  35. // Define memory limits.
  36. if ( ! defined( 'WP_MEMORY_LIMIT' ) ) {
  37. if ( false === wp_is_ini_value_changeable( 'memory_limit' ) ) {
  38. define( 'WP_MEMORY_LIMIT', $current_limit );
  39. } elseif ( is_multisite() ) {
  40. define( 'WP_MEMORY_LIMIT', '64M' );
  41. } else {
  42. define( 'WP_MEMORY_LIMIT', '40M' );
  43. }
  44. }
  45. if ( ! defined( 'WP_MAX_MEMORY_LIMIT' ) ) {
  46. if ( false === wp_is_ini_value_changeable( 'memory_limit' ) ) {
  47. define( 'WP_MAX_MEMORY_LIMIT', $current_limit );
  48. } elseif ( -1 === $current_limit_int || $current_limit_int > 268435456 /* = 256M */ ) {
  49. define( 'WP_MAX_MEMORY_LIMIT', $current_limit );
  50. } else {
  51. define( 'WP_MAX_MEMORY_LIMIT', '256M' );
  52. }
  53. }
  54. // Set memory limits.
  55. $wp_limit_int = wp_convert_hr_to_bytes( WP_MEMORY_LIMIT );
  56. if ( -1 !== $current_limit_int && ( -1 === $wp_limit_int || $wp_limit_int > $current_limit_int ) ) {
  57. ini_set( 'memory_limit', WP_MEMORY_LIMIT );
  58. }
  59. if ( ! isset( $blog_id ) ) {
  60. $blog_id = 1;
  61. }
  62. if ( ! defined( 'WP_CONTENT_DIR' ) ) {
  63. define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); // no trailing slash, full paths only - WP_CONTENT_URL is defined further down
  64. }
  65. // Add define( 'WP_DEBUG', true ); to wp-config.php to enable display of notices during development.
  66. if ( ! defined( 'WP_DEBUG' ) ) {
  67. define( 'WP_DEBUG', false );
  68. }
  69. // Add define( 'WP_DEBUG_DISPLAY', null ); to wp-config.php use the globally configured setting for
  70. // display_errors and not force errors to be displayed. Use false to force display_errors off.
  71. if ( ! defined( 'WP_DEBUG_DISPLAY' ) ) {
  72. define( 'WP_DEBUG_DISPLAY', true );
  73. }
  74. // Add define( 'WP_DEBUG_LOG', true ); to enable error logging to wp-content/debug.log.
  75. if ( ! defined( 'WP_DEBUG_LOG' ) ) {
  76. define( 'WP_DEBUG_LOG', false );
  77. }
  78. if ( ! defined( 'WP_CACHE' ) ) {
  79. define( 'WP_CACHE', false );
  80. }
  81. // Add define( 'SCRIPT_DEBUG', true ); to wp-config.php to enable loading of non-minified,
  82. // non-concatenated scripts and stylesheets.
  83. if ( ! defined( 'SCRIPT_DEBUG' ) ) {
  84. if ( ! empty( $GLOBALS['wp_version'] ) ) {
  85. $develop_src = false !== strpos( $GLOBALS['wp_version'], '-src' );
  86. } else {
  87. $develop_src = false;
  88. }
  89. define( 'SCRIPT_DEBUG', $develop_src );
  90. }
  91. /**
  92. * Private
  93. */
  94. if ( ! defined( 'MEDIA_TRASH' ) ) {
  95. define( 'MEDIA_TRASH', false );
  96. }
  97. if ( ! defined( 'SHORTINIT' ) ) {
  98. define( 'SHORTINIT', false );
  99. }
  100. // Constants for features added to WP that should short-circuit their plugin implementations
  101. define( 'WP_FEATURE_BETTER_PASSWORDS', true );
  102. /**#@+
  103. * Constants for expressing human-readable intervals
  104. * in their respective number of seconds.
  105. *
  106. * Please note that these values are approximate and are provided for convenience.
  107. * For example, MONTH_IN_SECONDS wrongly assumes every month has 30 days and
  108. * YEAR_IN_SECONDS does not take leap years into account.
  109. *
  110. * If you need more accuracy please consider using the DateTime class (https://secure.php.net/manual/en/class.datetime.php).
  111. *
  112. * @since 3.5.0
  113. * @since 4.4.0 Introduced `MONTH_IN_SECONDS`.
  114. */
  115. define( 'MINUTE_IN_SECONDS', 60 );
  116. define( 'HOUR_IN_SECONDS', 60 * MINUTE_IN_SECONDS );
  117. define( 'DAY_IN_SECONDS', 24 * HOUR_IN_SECONDS );
  118. define( 'WEEK_IN_SECONDS', 7 * DAY_IN_SECONDS );
  119. define( 'MONTH_IN_SECONDS', 30 * DAY_IN_SECONDS );
  120. define( 'YEAR_IN_SECONDS', 365 * DAY_IN_SECONDS );
  121. /**#@-*/
  122. }
  123. /**
  124. * Defines plugin directory WordPress constants
  125. *
  126. * Defines must-use plugin directory constants, which may be overridden in the sunrise.php drop-in
  127. *
  128. * @since 3.0.0
  129. */
  130. function wp_plugin_directory_constants() {
  131. if ( ! defined( 'WP_CONTENT_URL' ) ) {
  132. define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' ); // full url - WP_CONTENT_DIR is defined further up
  133. }
  134. /**
  135. * Allows for the plugins directory to be moved from the default location.
  136. *
  137. * @since 2.6.0
  138. */
  139. if ( ! defined( 'WP_PLUGIN_DIR' ) ) {
  140. define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' ); // full path, no trailing slash
  141. }
  142. /**
  143. * Allows for the plugins directory to be moved from the default location.
  144. *
  145. * @since 2.6.0
  146. */
  147. if ( ! defined( 'WP_PLUGIN_URL' ) ) {
  148. define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' ); // full url, no trailing slash
  149. }
  150. /**
  151. * Allows for the plugins directory to be moved from the default location.
  152. *
  153. * @since 2.1.0
  154. * @deprecated
  155. */
  156. if ( ! defined( 'PLUGINDIR' ) ) {
  157. define( 'PLUGINDIR', 'wp-content/plugins' ); // Relative to ABSPATH. For back compat.
  158. }
  159. /**
  160. * Allows for the mu-plugins directory to be moved from the default location.
  161. *
  162. * @since 2.8.0
  163. */
  164. if ( ! defined( 'WPMU_PLUGIN_DIR' ) ) {
  165. define( 'WPMU_PLUGIN_DIR', WP_CONTENT_DIR . '/mu-plugins' ); // full path, no trailing slash
  166. }
  167. /**
  168. * Allows for the mu-plugins directory to be moved from the default location.
  169. *
  170. * @since 2.8.0
  171. */
  172. if ( ! defined( 'WPMU_PLUGIN_URL' ) ) {
  173. define( 'WPMU_PLUGIN_URL', WP_CONTENT_URL . '/mu-plugins' ); // full url, no trailing slash
  174. }
  175. /**
  176. * Allows for the mu-plugins directory to be moved from the default location.
  177. *
  178. * @since 2.8.0
  179. * @deprecated
  180. */
  181. if ( ! defined( 'MUPLUGINDIR' ) ) {
  182. define( 'MUPLUGINDIR', 'wp-content/mu-plugins' ); // Relative to ABSPATH. For back compat.
  183. }
  184. }
  185. /**
  186. * Defines cookie related WordPress constants
  187. *
  188. * Defines constants after multisite is loaded.
  189. *
  190. * @since 3.0.0
  191. */
  192. function wp_cookie_constants() {
  193. /**
  194. * Used to guarantee unique hash cookies
  195. *
  196. * @since 1.5.0
  197. */
  198. if ( ! defined( 'COOKIEHASH' ) ) {
  199. $siteurl = get_site_option( 'siteurl' );
  200. if ( $siteurl ) {
  201. define( 'COOKIEHASH', md5( $siteurl ) );
  202. } else {
  203. define( 'COOKIEHASH', '' );
  204. }
  205. }
  206. /**
  207. * @since 2.0.0
  208. */
  209. if ( ! defined( 'USER_COOKIE' ) ) {
  210. define( 'USER_COOKIE', 'wordpressuser_' . COOKIEHASH );
  211. }
  212. /**
  213. * @since 2.0.0
  214. */
  215. if ( ! defined( 'PASS_COOKIE' ) ) {
  216. define( 'PASS_COOKIE', 'wordpresspass_' . COOKIEHASH );
  217. }
  218. /**
  219. * @since 2.5.0
  220. */
  221. if ( ! defined( 'AUTH_COOKIE' ) ) {
  222. define( 'AUTH_COOKIE', 'wordpress_' . COOKIEHASH );
  223. }
  224. /**
  225. * @since 2.6.0
  226. */
  227. if ( ! defined( 'SECURE_AUTH_COOKIE' ) ) {
  228. define( 'SECURE_AUTH_COOKIE', 'wordpress_sec_' . COOKIEHASH );
  229. }
  230. /**
  231. * @since 2.6.0
  232. */
  233. if ( ! defined( 'LOGGED_IN_COOKIE' ) ) {
  234. define( 'LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH );
  235. }
  236. /**
  237. * @since 2.3.0
  238. */
  239. if ( ! defined( 'TEST_COOKIE' ) ) {
  240. define( 'TEST_COOKIE', 'wordpress_test_cookie' );
  241. }
  242. /**
  243. * @since 1.2.0
  244. */
  245. if ( ! defined( 'COOKIEPATH' ) ) {
  246. define( 'COOKIEPATH', preg_replace( '|https?://[^/]+|i', '', get_option( 'home' ) . '/' ) );
  247. }
  248. /**
  249. * @since 1.5.0
  250. */
  251. if ( ! defined( 'SITECOOKIEPATH' ) ) {
  252. define( 'SITECOOKIEPATH', preg_replace( '|https?://[^/]+|i', '', get_option( 'siteurl' ) . '/' ) );
  253. }
  254. /**
  255. * @since 2.6.0
  256. */
  257. if ( ! defined( 'ADMIN_COOKIE_PATH' ) ) {
  258. define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' );
  259. }
  260. /**
  261. * @since 2.6.0
  262. */
  263. if ( ! defined( 'PLUGINS_COOKIE_PATH' ) ) {
  264. define( 'PLUGINS_COOKIE_PATH', preg_replace( '|https?://[^/]+|i', '', WP_PLUGIN_URL ) );
  265. }
  266. /**
  267. * @since 2.0.0
  268. */
  269. if ( ! defined( 'COOKIE_DOMAIN' ) ) {
  270. define( 'COOKIE_DOMAIN', false );
  271. }
  272. if ( ! defined( 'RECOVERY_MODE_COOKIE' ) ) {
  273. /**
  274. * @since 5.2.0
  275. */
  276. define( 'RECOVERY_MODE_COOKIE', 'wordpress_rec_' . COOKIEHASH );
  277. }
  278. }
  279. /**
  280. * Defines SSL-related WordPress constants.
  281. *
  282. * @since 3.0.0
  283. */
  284. function wp_ssl_constants() {
  285. /**
  286. * @since 2.6.0
  287. */
  288. if ( ! defined( 'FORCE_SSL_ADMIN' ) ) {
  289. if ( 'https' === parse_url( get_option( 'siteurl' ), PHP_URL_SCHEME ) ) {
  290. define( 'FORCE_SSL_ADMIN', true );
  291. } else {
  292. define( 'FORCE_SSL_ADMIN', false );
  293. }
  294. }
  295. force_ssl_admin( FORCE_SSL_ADMIN );
  296. /**
  297. * @since 2.6.0
  298. * @deprecated 4.0.0
  299. */
  300. if ( defined( 'FORCE_SSL_LOGIN' ) && FORCE_SSL_LOGIN ) {
  301. force_ssl_admin( true );
  302. }
  303. }
  304. /**
  305. * Defines functionality related WordPress constants
  306. *
  307. * @since 3.0.0
  308. */
  309. function wp_functionality_constants() {
  310. /**
  311. * @since 2.5.0
  312. */
  313. if ( ! defined( 'AUTOSAVE_INTERVAL' ) ) {
  314. define( 'AUTOSAVE_INTERVAL', 60 );
  315. }
  316. /**
  317. * @since 2.9.0
  318. */
  319. if ( ! defined( 'EMPTY_TRASH_DAYS' ) ) {
  320. define( 'EMPTY_TRASH_DAYS', 30 );
  321. }
  322. if ( ! defined( 'WP_POST_REVISIONS' ) ) {
  323. define( 'WP_POST_REVISIONS', true );
  324. }
  325. /**
  326. * @since 3.3.0
  327. */
  328. if ( ! defined( 'WP_CRON_LOCK_TIMEOUT' ) ) {
  329. define( 'WP_CRON_LOCK_TIMEOUT', 60 ); // In seconds
  330. }
  331. }
  332. /**
  333. * Defines templating related WordPress constants
  334. *
  335. * @since 3.0.0
  336. */
  337. function wp_templating_constants() {
  338. /**
  339. * Filesystem path to the current active template directory
  340. *
  341. * @since 1.5.0
  342. */
  343. define( 'TEMPLATEPATH', get_template_directory() );
  344. /**
  345. * Filesystem path to the current active template stylesheet directory
  346. *
  347. * @since 2.1.0
  348. */
  349. define( 'STYLESHEETPATH', get_stylesheet_directory() );
  350. /**
  351. * Slug of the default theme for this installation.
  352. * Used as the default theme when installing new sites.
  353. * It will be used as the fallback if the current theme doesn't exist.
  354. *
  355. * @since 3.0.0
  356. * @see WP_Theme::get_core_default_theme()
  357. */
  358. if ( ! defined( 'WP_DEFAULT_THEME' ) ) {
  359. define( 'WP_DEFAULT_THEME', 'twentytwenty' );
  360. }
  361. }