[ Index ]

PHP Cross Reference of WordPress

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


Generated: Thu Mar 28 01:00:02 2024 Cross-referenced by PHPXref 0.7.1