[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> default-constants.php (source)

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


Generated : Tue Dec 24 08:20:01 2024 Cross-referenced by PHPXref