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


Generated : Thu Apr 25 08:20:02 2024 Cross-referenced by PHPXref