ru-se.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

default-constants.php (10257B)


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