home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress / wp-includes / default-constants.php < prev    next >
Encoding:
PHP Script  |  2017-10-20  |  9.3 KB  |  364 lines

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