/wp-includes/load.php

  1. <?php 
  2. /** 
  3. * These functions are needed to load WordPress. 
  4. * 
  5. * @package WordPress 
  6. */ 
  7.  
  8. /** 
  9. * Return the HTTP protocol sent by the server. 
  10. * 
  11. * @since 4.4.0 
  12. * 
  13. * @return string The HTTP protocol. Default: HTTP/1.0. 
  14. */ 
  15. function wp_get_server_protocol() { 
  16. $protocol = $_SERVER['SERVER_PROTOCOL']; 
  17. if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ) ) ) { 
  18. $protocol = 'HTTP/1.0'; 
  19. return $protocol; 
  20.  
  21. /** 
  22. * Turn register globals off. 
  23. * 
  24. * @since 2.1.0 
  25. * @access private 
  26. */ 
  27. function wp_unregister_GLOBALS() { 
  28. if ( !ini_get( 'register_globals' ) ) 
  29. return; 
  30.  
  31. if ( isset( $_REQUEST['GLOBALS'] ) ) 
  32. die( 'GLOBALS overwrite attempt detected' ); 
  33.  
  34. // Variables that shouldn't be unset 
  35. $no_unset = array( 'GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix' ); 
  36.  
  37. $input = array_merge( $_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset( $_SESSION ) && is_array( $_SESSION ) ? $_SESSION : array() ); 
  38. foreach ( $input as $k => $v ) 
  39. if ( !in_array( $k, $no_unset ) && isset( $GLOBALS[$k] ) ) { 
  40. unset( $GLOBALS[$k] ); 
  41.  
  42. /** 
  43. * Fix `$_SERVER` variables for various setups. 
  44. * 
  45. * @since 3.0.0 
  46. * @access private 
  47. * 
  48. * @global string $PHP_SELF The filename of the currently executing script,  
  49. * relative to the document root. 
  50. */ 
  51. function wp_fix_server_vars() { 
  52. global $PHP_SELF; 
  53.  
  54. $default_server_values = array( 
  55. 'SERVER_SOFTWARE' => '',  
  56. 'REQUEST_URI' => '',  
  57. ); 
  58.  
  59. $_SERVER = array_merge( $default_server_values, $_SERVER ); 
  60.  
  61. // Fix for IIS when running with PHP ISAPI 
  62. if ( empty( $_SERVER['REQUEST_URI'] ) || ( PHP_SAPI != 'cgi-fcgi' && preg_match( '/^Microsoft-IIS\//', $_SERVER['SERVER_SOFTWARE'] ) ) ) { 
  63.  
  64. // IIS Mod-Rewrite 
  65. if ( isset( $_SERVER['HTTP_X_ORIGINAL_URL'] ) ) { 
  66. $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL']; 
  67. // IIS Isapi_Rewrite 
  68. elseif ( isset( $_SERVER['HTTP_X_REWRITE_URL'] ) ) { 
  69. $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL']; 
  70. } else { 
  71. // Use ORIG_PATH_INFO if there is no PATH_INFO 
  72. if ( !isset( $_SERVER['PATH_INFO'] ) && isset( $_SERVER['ORIG_PATH_INFO'] ) ) 
  73. $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO']; 
  74.  
  75. // Some IIS + PHP configurations puts the script-name in the path-info (No need to append it twice) 
  76. if ( isset( $_SERVER['PATH_INFO'] ) ) { 
  77. if ( $_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'] ) 
  78. $_SERVER['REQUEST_URI'] = $_SERVER['PATH_INFO']; 
  79. else 
  80. $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO']; 
  81.  
  82. // Append the query string if it exists and isn't null 
  83. if ( ! empty( $_SERVER['QUERY_STRING'] ) ) { 
  84. $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; 
  85.  
  86. // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests 
  87. if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && ( strpos( $_SERVER['SCRIPT_FILENAME'], 'php.cgi' ) == strlen( $_SERVER['SCRIPT_FILENAME'] ) - 7 ) ) 
  88. $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED']; 
  89.  
  90. // Fix for Dreamhost and other PHP as CGI hosts 
  91. if ( strpos( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) !== false ) 
  92. unset( $_SERVER['PATH_INFO'] ); 
  93.  
  94. // Fix empty PHP_SELF 
  95. $PHP_SELF = $_SERVER['PHP_SELF']; 
  96. if ( empty( $PHP_SELF ) ) 
  97. $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace( '/(\?.*)?$/', '', $_SERVER["REQUEST_URI"] ); 
  98.  
  99. /** 
  100. * Check for the required PHP version, and the MySQL extension or 
  101. * a database drop-in. 
  102. * 
  103. * Dies if requirements are not met. 
  104. * 
  105. * @since 3.0.0 
  106. * @access private 
  107. * 
  108. * @global string $required_php_version The required PHP version string. 
  109. * @global string $wp_version The WordPress version string. 
  110. */ 
  111. function wp_check_php_mysql_versions() { 
  112. global $required_php_version, $wp_version; 
  113. $php_version = phpversion(); 
  114.  
  115. if ( version_compare( $required_php_version, $php_version, '>' ) ) { 
  116. wp_load_translations_early(); 
  117.  
  118. $protocol = wp_get_server_protocol(); 
  119. header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 ); 
  120. header( 'Content-Type: text/html; charset=utf-8' ); 
  121. /** translators: 1: Current PHP version number, 2: WordPress version number, 3: Minimum required PHP version number */ 
  122. die( sprintf( __( 'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.' ), $php_version, $wp_version, $required_php_version ) ); 
  123.  
  124. if ( ! extension_loaded( 'mysql' ) && ! extension_loaded( 'mysqli' ) && ! extension_loaded( 'mysqlnd' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) { 
  125. wp_load_translations_early(); 
  126.  
  127. $protocol = wp_get_server_protocol(); 
  128. header( sprintf( '%s 500 Internal Server Error', $protocol ), true, 500 ); 
  129. header( 'Content-Type: text/html; charset=utf-8' ); 
  130. die( __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ) ); 
  131.  
  132. /** 
  133. * Don't load all of WordPress when handling a favicon.ico request. 
  134. * 
  135. * Instead, send the headers for a zero-length favicon and bail. 
  136. * 
  137. * @since 3.0.0 
  138. */ 
  139. function wp_favicon_request() { 
  140. if ( '/favicon.ico' == $_SERVER['REQUEST_URI'] ) { 
  141. header('Content-Type: image/vnd.microsoft.icon'); 
  142. exit; 
  143.  
  144. /** 
  145. * Die with a maintenance message when conditions are met. 
  146. * 
  147. * Checks for a file in the WordPress root directory named ".maintenance". 
  148. * This file will contain the variable $upgrading, set to the time the file 
  149. * was created. If the file was created less than 10 minutes ago, WordPress 
  150. * enters maintenance mode and displays a message. 
  151. * 
  152. * The default message can be replaced by using a drop-in (maintenance.php in 
  153. * the wp-content directory). 
  154. * 
  155. * @since 3.0.0 
  156. * @access private 
  157. * 
  158. * @global int $upgrading the unix timestamp marking when upgrading WordPress began. 
  159. */ 
  160. function wp_maintenance() { 
  161. if ( ! file_exists( ABSPATH . '.maintenance' ) || wp_installing() ) 
  162. return; 
  163.  
  164. global $upgrading; 
  165.  
  166. include( ABSPATH . '.maintenance' ); 
  167. // If the $upgrading timestamp is older than 10 minutes, don't die. 
  168. if ( ( time() - $upgrading ) >= 600 ) 
  169. return; 
  170.  
  171. /** 
  172. * Filters whether to enable maintenance mode. 
  173. * 
  174. * This filter runs before it can be used by plugins. It is designed for 
  175. * non-web runtimes. If this filter returns true, maintenance mode will be 
  176. * active and the request will end. If false, the request will be allowed to 
  177. * continue processing even if maintenance mode should be active. 
  178. * 
  179. * @since 4.6.0 
  180. * 
  181. * @param bool $enable_checks Whether to enable maintenance mode. Default true. 
  182. * @param int $upgrading The timestamp set in the .maintenance file. 
  183. */ 
  184. if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) { 
  185. return; 
  186.  
  187. if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) { 
  188. require_once( WP_CONTENT_DIR . '/maintenance.php' ); 
  189. die(); 
  190.  
  191. wp_load_translations_early(); 
  192.  
  193. $protocol = wp_get_server_protocol(); 
  194. header( "$protocol 503 Service Unavailable", true, 503 ); 
  195. header( 'Content-Type: text/html; charset=utf-8' ); 
  196. header( 'Retry-After: 600' ); 
  197. ?> 
  198. <!DOCTYPE html> 
  199. <html xmlns="http://www.w3.org/1999/xhtml"<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>> 
  200. <head> 
  201. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  202. <title><?php _e( 'Maintenance' ); ?></title> 
  203.  
  204. </head> 
  205. <body> 
  206. <h1><?php _e( 'Briefly unavailable for scheduled maintenance. Check back in a minute.' ); ?></h1> 
  207. </body> 
  208. </html> 
  209. <?php 
  210. die(); 
  211.  
  212. /** 
  213. * Start the WordPress micro-timer. 
  214. * 
  215. * @since 0.71 
  216. * @access private 
  217. * 
  218. * @global float $timestart Unix timestamp set at the beginning of the page load. 
  219. * @see timer_stop() 
  220. * 
  221. * @return bool Always returns true. 
  222. */ 
  223. function timer_start() { 
  224. global $timestart; 
  225. $timestart = microtime( true ); 
  226. return true; 
  227.  
  228. /** 
  229. * Retrieve or display the time from the page start to when function is called. 
  230. * 
  231. * @since 0.71 
  232. * 
  233. * @global float $timestart Seconds from when timer_start() is called. 
  234. * @global float $timeend Seconds from when function is called. 
  235. * 
  236. * @param int|bool $display Whether to echo or return the results. Accepts 0|false for return,  
  237. * 1|true for echo. Default 0|false. 
  238. * @param int $precision The number of digits from the right of the decimal to display. 
  239. * Default 3. 
  240. * @return string The "second.microsecond" finished time calculation. The number is formatted 
  241. * for human consumption, both localized and rounded. 
  242. */ 
  243. function timer_stop( $display = 0, $precision = 3 ) { 
  244. global $timestart, $timeend; 
  245. $timeend = microtime( true ); 
  246. $timetotal = $timeend - $timestart; 
  247. $r = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision ); 
  248. if ( $display ) 
  249. echo $r; 
  250. return $r; 
  251.  
  252. /** 
  253. * Set PHP error reporting based on WordPress debug settings. 
  254. * 
  255. * Uses three constants: `WP_DEBUG`, `WP_DEBUG_DISPLAY`, and `WP_DEBUG_LOG`. 
  256. * All three can be defined in wp-config.php. By default, `WP_DEBUG` and 
  257. * `WP_DEBUG_LOG` are set to false, and `WP_DEBUG_DISPLAY` is set to true. 
  258. * 
  259. * When `WP_DEBUG` is true, all PHP notices are reported. WordPress will also 
  260. * display internal notices: when a deprecated WordPress function, function 
  261. * argument, or file is used. Deprecated code may be removed from a later 
  262. * version. 
  263. * 
  264. * It is strongly recommended that plugin and theme developers use `WP_DEBUG` 
  265. * in their development environments. 
  266. * 
  267. * `WP_DEBUG_DISPLAY` and `WP_DEBUG_LOG` perform no function unless `WP_DEBUG` 
  268. * is true. 
  269. * 
  270. * When `WP_DEBUG_DISPLAY` is true, WordPress will force errors to be displayed. 
  271. * `WP_DEBUG_DISPLAY` defaults to true. Defining it as null prevents WordPress 
  272. * from changing the global configuration setting. Defining `WP_DEBUG_DISPLAY` 
  273. * as false will force errors to be hidden. 
  274. * 
  275. * When `WP_DEBUG_LOG` is true, errors will be logged to debug.log in the content 
  276. * directory. 
  277. * 
  278. * Errors are never displayed for XML-RPC, REST, and Ajax requests. 
  279. * 
  280. * @since 3.0.0 
  281. * @access private 
  282. */ 
  283. function wp_debug_mode() { 
  284. /** 
  285. * Filters whether to allow the debug mode check to occur. 
  286. * 
  287. * This filter runs before it can be used by plugins. It is designed for 
  288. * non-web run-times. Returning false causes the `WP_DEBUG` and related 
  289. * constants to not be checked and the default php values for errors 
  290. * will be used unless you take care to update them yourself. 
  291. * 
  292. * @since 4.6.0 
  293. * 
  294. * @param bool $enable_debug_mode Whether to enable debug mode checks to occur. Default true. 
  295. */ 
  296. if ( ! apply_filters( 'enable_wp_debug_mode_checks', true ) ) { 
  297. return; 
  298.  
  299. if ( WP_DEBUG ) { 
  300. error_reporting( E_ALL ); 
  301.  
  302. if ( WP_DEBUG_DISPLAY ) 
  303. ini_set( 'display_errors', 1 ); 
  304. elseif ( null !== WP_DEBUG_DISPLAY ) 
  305. ini_set( 'display_errors', 0 ); 
  306.  
  307. if ( WP_DEBUG_LOG ) { 
  308. ini_set( 'log_errors', 1 ); 
  309. ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' ); 
  310. } else { 
  311. error_reporting( E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR ); 
  312.  
  313. if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) || wp_doing_ajax() ) { 
  314. @ini_set( 'display_errors', 0 ); 
  315.  
  316. /** 
  317. * Set the location of the language directory. 
  318. * 
  319. * To set directory manually, define the `WP_LANG_DIR` constant 
  320. * in wp-config.php. 
  321. * 
  322. * If the language directory exists within `WP_CONTENT_DIR`, it 
  323. * is used. Otherwise the language directory is assumed to live 
  324. * in `WPINC`. 
  325. * 
  326. * @since 3.0.0 
  327. * @access private 
  328. */ 
  329. function wp_set_lang_dir() { 
  330. if ( !defined( 'WP_LANG_DIR' ) ) { 
  331. if ( file_exists( WP_CONTENT_DIR . '/languages' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) || !@is_dir(ABSPATH . WPINC . '/languages') ) { 
  332. /** 
  333. * Server path of the language directory. 
  334. * 
  335. * No leading slash, no trailing slash, full path, not relative to ABSPATH 
  336. * 
  337. * @since 2.1.0 
  338. */ 
  339. define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' ); 
  340. if ( !defined( 'LANGDIR' ) ) { 
  341. // Old static relative path maintained for limited backward compatibility - won't work in some cases. 
  342. define( 'LANGDIR', 'wp-content/languages' ); 
  343. } else { 
  344. /** 
  345. * Server path of the language directory. 
  346. * 
  347. * No leading slash, no trailing slash, full path, not relative to `ABSPATH`. 
  348. * 
  349. * @since 2.1.0 
  350. */ 
  351. define( 'WP_LANG_DIR', ABSPATH . WPINC . '/languages' ); 
  352. if ( !defined( 'LANGDIR' ) ) { 
  353. // Old relative path maintained for backward compatibility. 
  354. define( 'LANGDIR', WPINC . '/languages' ); 
  355.  
  356. /** 
  357. * Load the database class file and instantiate the `$wpdb` global. 
  358. * 
  359. * @since 2.5.0 
  360. * 
  361. * @global wpdb $wpdb The WordPress database class. 
  362. */ 
  363. function require_wp_db() { 
  364. global $wpdb; 
  365.  
  366. require_once( ABSPATH . WPINC . '/wp-db.php' ); 
  367. if ( file_exists( WP_CONTENT_DIR . '/db.php' ) ) 
  368. require_once( WP_CONTENT_DIR . '/db.php' ); 
  369.  
  370. if ( isset( $wpdb ) ) { 
  371. return; 
  372.  
  373. $wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST ); 
  374.  
  375. /** 
  376. * Set the database table prefix and the format specifiers for database 
  377. * table columns. 
  378. * 
  379. * Columns not listed here default to `%s`. 
  380. * 
  381. * @since 3.0.0 
  382. * @access private 
  383. * 
  384. * @global wpdb $wpdb The WordPress database class. 
  385. * @global string $table_prefix The database table prefix. 
  386. */ 
  387. function wp_set_wpdb_vars() { 
  388. global $wpdb, $table_prefix; 
  389. if ( !empty( $wpdb->error ) ) 
  390. dead_db(); 
  391.  
  392. $wpdb->field_types = array( 'post_author' => '%d', 'post_parent' => '%d', 'menu_order' => '%d', 'term_id' => '%d', 'term_group' => '%d', 'term_taxonomy_id' => '%d',  
  393. 'parent' => '%d', 'count' => '%d', 'object_id' => '%d', 'term_order' => '%d', 'ID' => '%d', 'comment_ID' => '%d', 'comment_post_ID' => '%d', 'comment_parent' => '%d',  
  394. 'user_id' => '%d', 'link_id' => '%d', 'link_owner' => '%d', 'link_rating' => '%d', 'option_id' => '%d', 'blog_id' => '%d', 'meta_id' => '%d', 'post_id' => '%d',  
  395. 'user_status' => '%d', 'umeta_id' => '%d', 'comment_karma' => '%d', 'comment_count' => '%d',  
  396. // multisite: 
  397. 'active' => '%d', 'cat_id' => '%d', 'deleted' => '%d', 'lang_id' => '%d', 'mature' => '%d', 'public' => '%d', 'site_id' => '%d', 'spam' => '%d',  
  398. ); 
  399.  
  400. $prefix = $wpdb->set_prefix( $table_prefix ); 
  401.  
  402. if ( is_wp_error( $prefix ) ) { 
  403. wp_load_translations_early(); 
  404. wp_die( 
  405. /** translators: 1: $table_prefix 2: wp-config.php */ 
  406. sprintf( __( '<strong>ERROR</strong>: %1$s in %2$s can only contain numbers, letters, and underscores.' ),  
  407. '<code>$table_prefix</code>',  
  408. '<code>wp-config.php</code>' 
  409. ); 
  410.  
  411. /** 
  412. * Toggle `$_wp_using_ext_object_cache` on and off without directly 
  413. * touching global. 
  414. * 
  415. * @since 3.7.0 
  416. * 
  417. * @global bool $_wp_using_ext_object_cache 
  418. * 
  419. * @param bool $using Whether external object cache is being used. 
  420. * @return bool The current 'using' setting. 
  421. */ 
  422. function wp_using_ext_object_cache( $using = null ) { 
  423. global $_wp_using_ext_object_cache; 
  424. $current_using = $_wp_using_ext_object_cache; 
  425. if ( null !== $using ) 
  426. $_wp_using_ext_object_cache = $using; 
  427. return $current_using; 
  428.  
  429. /** 
  430. * Start the WordPress object cache. 
  431. * 
  432. * If an object-cache.php file exists in the wp-content directory,  
  433. * it uses that drop-in as an external object cache. 
  434. * 
  435. * @since 3.0.0 
  436. * @access private 
  437. */ 
  438. function wp_start_object_cache() { 
  439. global $wp_filter; 
  440.  
  441. $first_init = false; 
  442. if ( ! function_exists( 'wp_cache_init' ) ) { 
  443. if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) { 
  444. require_once ( WP_CONTENT_DIR . '/object-cache.php' ); 
  445. if ( function_exists( 'wp_cache_init' ) ) { 
  446. wp_using_ext_object_cache( true ); 
  447.  
  448. // Re-initialize any hooks added manually by object-cache.php 
  449. if ( $wp_filter ) { 
  450. $wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter ); 
  451.  
  452. $first_init = true; 
  453. } elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) { 
  454. /** 
  455. * Sometimes advanced-cache.php can load object-cache.php before 
  456. * it is loaded here. This breaks the function_exists check above 
  457. * and can result in `$_wp_using_ext_object_cache` being set 
  458. * incorrectly. Double check if an external cache exists. 
  459. */ 
  460. wp_using_ext_object_cache( true ); 
  461.  
  462. if ( ! wp_using_ext_object_cache() ) { 
  463. require_once ( ABSPATH . WPINC . '/cache.php' ); 
  464.  
  465. /** 
  466. * If cache supports reset, reset instead of init if already 
  467. * initialized. Reset signals to the cache that global IDs 
  468. * have changed and it may need to update keys and cleanup caches. 
  469. */ 
  470. if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) ) { 
  471. wp_cache_switch_to_blog( get_current_blog_id() ); 
  472. } elseif ( function_exists( 'wp_cache_init' ) ) { 
  473. wp_cache_init(); 
  474.  
  475. if ( function_exists( 'wp_cache_add_global_groups' ) ) { 
  476. wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) ); 
  477. wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 
  478.  
  479. /** 
  480. * Redirect to the installer if WordPress is not installed. 
  481. * 
  482. * Dies with an error message when Multisite is enabled. 
  483. * 
  484. * @since 3.0.0 
  485. * @access private 
  486. */ 
  487. function wp_not_installed() { 
  488. if ( is_multisite() ) { 
  489. if ( ! is_blog_installed() && ! wp_installing() ) { 
  490. nocache_headers(); 
  491.  
  492. wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) ); 
  493. } elseif ( ! is_blog_installed() && ! wp_installing() ) { 
  494. nocache_headers(); 
  495.  
  496. require( ABSPATH . WPINC . '/kses.php' ); 
  497. require( ABSPATH . WPINC . '/pluggable.php' ); 
  498. require( ABSPATH . WPINC . '/formatting.php' ); 
  499.  
  500. $link = wp_guess_url() . '/wp-admin/install.php'; 
  501.  
  502. wp_redirect( $link ); 
  503. die(); 
  504.  
  505. /** 
  506. * Retrieve an array of must-use plugin files. 
  507. * 
  508. * The default directory is wp-content/mu-plugins. To change the default 
  509. * directory manually, define `WPMU_PLUGIN_DIR` and `WPMU_PLUGIN_URL` 
  510. * in wp-config.php. 
  511. * 
  512. * @since 3.0.0 
  513. * @access private 
  514. * 
  515. * @return array Files to include. 
  516. */ 
  517. function wp_get_mu_plugins() { 
  518. $mu_plugins = array(); 
  519. if ( !is_dir( WPMU_PLUGIN_DIR ) ) 
  520. return $mu_plugins; 
  521. if ( ! $dh = opendir( WPMU_PLUGIN_DIR ) ) 
  522. return $mu_plugins; 
  523. while ( ( $plugin = readdir( $dh ) ) !== false ) { 
  524. if ( substr( $plugin, -4 ) == '.php' ) 
  525. $mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin; 
  526. closedir( $dh ); 
  527. sort( $mu_plugins ); 
  528.  
  529. return $mu_plugins; 
  530.  
  531. /** 
  532. * Retrieve an array of active and valid plugin files. 
  533. * 
  534. * While upgrading or installing WordPress, no plugins are returned. 
  535. * 
  536. * The default directory is wp-content/plugins. To change the default 
  537. * directory manually, define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL` 
  538. * in wp-config.php. 
  539. * 
  540. * @since 3.0.0 
  541. * @access private 
  542. * 
  543. * @return array Files. 
  544. */ 
  545. function wp_get_active_and_valid_plugins() { 
  546. $plugins = array(); 
  547. $active_plugins = (array) get_option( 'active_plugins', array() ); 
  548.  
  549. // Check for hacks file if the option is enabled 
  550. if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) { 
  551. _deprecated_file( 'my-hacks.php', '1.5.0' ); 
  552. array_unshift( $plugins, ABSPATH . 'my-hacks.php' ); 
  553.  
  554. if ( empty( $active_plugins ) || wp_installing() ) 
  555. return $plugins; 
  556.  
  557. $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false; 
  558.  
  559. foreach ( $active_plugins as $plugin ) { 
  560. if ( ! validate_file( $plugin ) // $plugin must validate as file 
  561. && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php' 
  562. && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist 
  563. // not already included as a network plugin 
  564. && ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins ) ) 
  565. $plugins[] = WP_PLUGIN_DIR . '/' . $plugin; 
  566. return $plugins; 
  567.  
  568. /** 
  569. * Set internal encoding. 
  570. * 
  571. * In most cases the default internal encoding is latin1, which is 
  572. * of no use, since we want to use the `mb_` functions for `utf-8` strings. 
  573. * 
  574. * @since 3.0.0 
  575. * @access private 
  576. */ 
  577. function wp_set_internal_encoding() { 
  578. if ( function_exists( 'mb_internal_encoding' ) ) { 
  579. $charset = get_option( 'blog_charset' ); 
  580. if ( ! $charset || ! @mb_internal_encoding( $charset ) ) 
  581. mb_internal_encoding( 'UTF-8' ); 
  582.  
  583. /** 
  584. * Add magic quotes to `$_GET`, `$_POST`, `$_COOKIE`, and `$_SERVER`. 
  585. * 
  586. * Also forces `$_REQUEST` to be `$_GET + $_POST`. If `$_SERVER`,  
  587. * `$_COOKIE`, or `$_ENV` are needed, use those superglobals directly. 
  588. * 
  589. * @since 3.0.0 
  590. * @access private 
  591. */ 
  592. function wp_magic_quotes() { 
  593. // If already slashed, strip. 
  594. if ( get_magic_quotes_gpc() ) { 
  595. $_GET = stripslashes_deep( $_GET ); 
  596. $_POST = stripslashes_deep( $_POST ); 
  597. $_COOKIE = stripslashes_deep( $_COOKIE ); 
  598.  
  599. // Escape with wpdb. 
  600. $_GET = add_magic_quotes( $_GET ); 
  601. $_POST = add_magic_quotes( $_POST ); 
  602. $_COOKIE = add_magic_quotes( $_COOKIE ); 
  603. $_SERVER = add_magic_quotes( $_SERVER ); 
  604.  
  605. // Force REQUEST to be GET + POST. 
  606. $_REQUEST = array_merge( $_GET, $_POST ); 
  607.  
  608. /** 
  609. * Runs just before PHP shuts down execution. 
  610. * 
  611. * @since 1.2.0 
  612. * @access private 
  613. */ 
  614. function shutdown_action_hook() { 
  615. /** 
  616. * Fires just before PHP shuts down execution. 
  617. * 
  618. * @since 1.2.0 
  619. */ 
  620. do_action( 'shutdown' ); 
  621.  
  622. wp_cache_close(); 
  623.  
  624. /** 
  625. * Copy an object. 
  626. * 
  627. * @since 2.7.0 
  628. * @deprecated 3.2.0 
  629. * 
  630. * @param object $object The object to clone. 
  631. * @return object The cloned object. 
  632. */ 
  633. function wp_clone( $object ) { 
  634. // Use parens for clone to accommodate PHP 4. See #17880 
  635. return clone( $object ); 
  636.  
  637. /** 
  638. * Whether the current request is for an administrative interface page. 
  639. * 
  640. * Does not check if the user is an administrator; current_user_can() 
  641. * for checking roles and capabilities. 
  642. * 
  643. * @since 1.5.1 
  644. * 
  645. * @global WP_Screen $current_screen 
  646. * 
  647. * @return bool True if inside WordPress administration interface, false otherwise. 
  648. */ 
  649. function is_admin() { 
  650. if ( isset( $GLOBALS['current_screen'] ) ) 
  651. return $GLOBALS['current_screen']->in_admin(); 
  652. elseif ( defined( 'WP_ADMIN' ) ) 
  653. return WP_ADMIN; 
  654.  
  655. return false; 
  656.  
  657. /** 
  658. * Whether the current request is for a site's admininstrative interface. 
  659. * 
  660. * e.g. `/wp-admin/` 
  661. * 
  662. * Does not check if the user is an administrator; current_user_can() 
  663. * for checking roles and capabilities. 
  664. * 
  665. * @since 3.1.0 
  666. * 
  667. * @global WP_Screen $current_screen 
  668. * 
  669. * @return bool True if inside WordPress blog administration pages. 
  670. */ 
  671. function is_blog_admin() { 
  672. if ( isset( $GLOBALS['current_screen'] ) ) 
  673. return $GLOBALS['current_screen']->in_admin( 'site' ); 
  674. elseif ( defined( 'WP_BLOG_ADMIN' ) ) 
  675. return WP_BLOG_ADMIN; 
  676.  
  677. return false; 
  678.  
  679. /** 
  680. * Whether the current request is for the network administrative interface. 
  681. * 
  682. * e.g. `/wp-admin/network/` 
  683. * 
  684. * Does not check if the user is an administrator; current_user_can() 
  685. * for checking roles and capabilities. 
  686. * 
  687. * @since 3.1.0 
  688. * 
  689. * @global WP_Screen $current_screen 
  690. * 
  691. * @return bool True if inside WordPress network administration pages. 
  692. */ 
  693. function is_network_admin() { 
  694. if ( isset( $GLOBALS['current_screen'] ) ) 
  695. return $GLOBALS['current_screen']->in_admin( 'network' ); 
  696. elseif ( defined( 'WP_NETWORK_ADMIN' ) ) 
  697. return WP_NETWORK_ADMIN; 
  698.  
  699. return false; 
  700.  
  701. /** 
  702. * Whether the current request is for a user admin screen. 
  703. * 
  704. * e.g. `/wp-admin/user/` 
  705. * 
  706. * Does not inform on whether the user is an admin! Use capability 
  707. * checks to tell if the user should be accessing a section or not 
  708. * current_user_can(). 
  709. * 
  710. * @since 3.1.0 
  711. * 
  712. * @global WP_Screen $current_screen 
  713. * 
  714. * @return bool True if inside WordPress user administration pages. 
  715. */ 
  716. function is_user_admin() { 
  717. if ( isset( $GLOBALS['current_screen'] ) ) 
  718. return $GLOBALS['current_screen']->in_admin( 'user' ); 
  719. elseif ( defined( 'WP_USER_ADMIN' ) ) 
  720. return WP_USER_ADMIN; 
  721.  
  722. return false; 
  723.  
  724. /** 
  725. * If Multisite is enabled. 
  726. * 
  727. * @since 3.0.0 
  728. * 
  729. * @return bool True if Multisite is enabled, false otherwise. 
  730. */ 
  731. function is_multisite() { 
  732. if ( defined( 'MULTISITE' ) ) 
  733. return MULTISITE; 
  734.  
  735. if ( defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) ) 
  736. return true; 
  737.  
  738. return false; 
  739.  
  740. /** 
  741. * Retrieve the current site ID. 
  742. * 
  743. * @since 3.1.0 
  744. * 
  745. * @global int $blog_id 
  746. * 
  747. * @return int Site ID. 
  748. */ 
  749. function get_current_blog_id() { 
  750. global $blog_id; 
  751. return absint($blog_id); 
  752.  
  753. /** 
  754. * Retrieves the current network ID. 
  755. * 
  756. * @since 4.6.0 
  757. * 
  758. * @return int The ID of the current network. 
  759. */ 
  760. function get_current_network_id() { 
  761. if ( ! is_multisite() ) { 
  762. return 1; 
  763.  
  764. $current_network = get_network(); 
  765.  
  766. if ( ! isset( $current_network->id ) ) { 
  767. return get_main_network_id(); 
  768.  
  769. return absint( $current_network->id ); 
  770.  
  771. /** 
  772. * Attempt an early load of translations. 
  773. * 
  774. * Used for errors encountered during the initial loading process, before 
  775. * the locale has been properly detected and loaded. 
  776. * 
  777. * Designed for unusual load sequences (like setup-config.php) or for when 
  778. * the script will then terminate with an error, otherwise there is a risk 
  779. * that a file can be double-included. 
  780. * 
  781. * @since 3.4.0 
  782. * @access private 
  783. * 
  784. * @global WP_Locale $wp_locale The WordPress date and time locale object. 
  785. * 
  786. * @staticvar bool $loaded 
  787. */ 
  788. function wp_load_translations_early() { 
  789. global $wp_locale; 
  790.  
  791. static $loaded = false; 
  792. if ( $loaded ) 
  793. return; 
  794. $loaded = true; 
  795.  
  796. if ( function_exists( 'did_action' ) && did_action( 'init' ) ) 
  797. return; 
  798.  
  799. // We need $wp_local_package 
  800. require ABSPATH . WPINC . '/version.php'; 
  801.  
  802. // Translation and localization 
  803. require_once ABSPATH . WPINC . '/pomo/mo.php'; 
  804. require_once ABSPATH . WPINC . '/l10n.php'; 
  805. require_once ABSPATH . WPINC . '/class-wp-locale.php'; 
  806. require_once ABSPATH . WPINC . '/class-wp-locale-switcher.php'; 
  807.  
  808. // General libraries 
  809. require_once ABSPATH . WPINC . '/plugin.php'; 
  810.  
  811. $locales = $locations = array(); 
  812.  
  813. while ( true ) { 
  814. if ( defined( 'WPLANG' ) ) { 
  815. if ( '' == WPLANG ) 
  816. break; 
  817. $locales[] = WPLANG; 
  818.  
  819. if ( isset( $wp_local_package ) ) 
  820. $locales[] = $wp_local_package; 
  821.  
  822. if ( ! $locales ) 
  823. break; 
  824.  
  825. if ( defined( 'WP_LANG_DIR' ) && @is_dir( WP_LANG_DIR ) ) 
  826. $locations[] = WP_LANG_DIR; 
  827.  
  828. if ( defined( 'WP_CONTENT_DIR' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) ) 
  829. $locations[] = WP_CONTENT_DIR . '/languages'; 
  830.  
  831. if ( @is_dir( ABSPATH . 'wp-content/languages' ) ) 
  832. $locations[] = ABSPATH . 'wp-content/languages'; 
  833.  
  834. if ( @is_dir( ABSPATH . WPINC . '/languages' ) ) 
  835. $locations[] = ABSPATH . WPINC . '/languages'; 
  836.  
  837. if ( ! $locations ) 
  838. break; 
  839.  
  840. $locations = array_unique( $locations ); 
  841.  
  842. foreach ( $locales as $locale ) { 
  843. foreach ( $locations as $location ) { 
  844. if ( file_exists( $location . '/' . $locale . '.mo' ) ) { 
  845. load_textdomain( 'default', $location . '/' . $locale . '.mo' ); 
  846. if ( defined( 'WP_SETUP_CONFIG' ) && file_exists( $location . '/admin-' . $locale . '.mo' ) ) 
  847. load_textdomain( 'default', $location . '/admin-' . $locale . '.mo' ); 
  848. break 2; 
  849.  
  850. break; 
  851.  
  852. $wp_locale = new WP_Locale(); 
  853.  
  854. /** 
  855. * Check or set whether WordPress is in "installation" mode. 
  856. * 
  857. * If the `WP_INSTALLING` constant is defined during the bootstrap, `wp_installing()` will default to `true`. 
  858. * 
  859. * @since 4.4.0 
  860. * 
  861. * @staticvar bool $installing 
  862. * 
  863. * @param bool $is_installing Optional. True to set WP into Installing mode, false to turn Installing mode off. 
  864. * Omit this parameter if you only want to fetch the current status. 
  865. * @return bool True if WP is installing, otherwise false. When a `$is_installing` is passed, the function will 
  866. * report whether WP was in installing mode prior to the change to `$is_installing`. 
  867. */ 
  868. function wp_installing( $is_installing = null ) { 
  869. static $installing = null; 
  870.  
  871. // Support for the `WP_INSTALLING` constant, defined before WP is loaded. 
  872. if ( is_null( $installing ) ) { 
  873. $installing = defined( 'WP_INSTALLING' ) && WP_INSTALLING; 
  874.  
  875. if ( ! is_null( $is_installing ) ) { 
  876. $old_installing = $installing; 
  877. $installing = $is_installing; 
  878. return (bool) $old_installing; 
  879.  
  880. return (bool) $installing; 
  881.  
  882. /** 
  883. * Determines if SSL is used. 
  884. * 
  885. * @since 2.6.0 
  886. * @since 4.6.0 Moved from functions.php to load.php. 
  887. * 
  888. * @return bool True if SSL, otherwise false. 
  889. */ 
  890. function is_ssl() { 
  891. if ( isset( $_SERVER['HTTPS'] ) ) { 
  892. if ( 'on' == strtolower( $_SERVER['HTTPS'] ) ) { 
  893. return true; 
  894.  
  895. if ( '1' == $_SERVER['HTTPS'] ) { 
  896. return true; 
  897. } elseif ( isset($_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) { 
  898. return true; 
  899. return false; 
  900.  
  901. /** 
  902. * Converts a shorthand byte value to an integer byte value. 
  903. * 
  904. * @since 2.3.0 
  905. * @since 4.6.0 Moved from media.php to load.php. 
  906. * 
  907. * @link https://secure.php.net/manual/en/function.ini-get.php 
  908. * @link https://secure.php.net/manual/en/faq.using.php#faq.using.shorthandbytes 
  909. * 
  910. * @param string $value A (PHP ini) byte value, either shorthand or ordinary. 
  911. * @return int An integer byte value. 
  912. */ 
  913. function wp_convert_hr_to_bytes( $value ) { 
  914. $value = strtolower( trim( $value ) ); 
  915. $bytes = (int) $value; 
  916.  
  917. if ( false !== strpos( $value, 'g' ) ) { 
  918. $bytes *= GB_IN_BYTES; 
  919. } elseif ( false !== strpos( $value, 'm' ) ) { 
  920. $bytes *= MB_IN_BYTES; 
  921. } elseif ( false !== strpos( $value, 'k' ) ) { 
  922. $bytes *= KB_IN_BYTES; 
  923.  
  924. // Deal with large (float) values which run into the maximum integer size. 
  925. return min( $bytes, PHP_INT_MAX ); 
  926.  
  927. /** 
  928. * Determines whether a PHP ini value is changeable at runtime. 
  929. * 
  930. * @since 4.6.0 
  931. * 
  932. * @link https://secure.php.net/manual/en/function.ini-get-all.php 
  933. * 
  934. * @param string $setting The name of the ini setting to check. 
  935. * @return bool True if the value is changeable at runtime. False otherwise. 
  936. */ 
  937. function wp_is_ini_value_changeable( $setting ) { 
  938. static $ini_all; 
  939.  
  940. if ( ! isset( $ini_all ) ) { 
  941. $ini_all = false; 
  942. // Sometimes `ini_get_all()` is disabled via the `disable_functions` option for "security purposes". 
  943. if ( function_exists( 'ini_get_all' ) ) { 
  944. $ini_all = ini_get_all(); 
  945.  
  946. // Bit operator to workaround https://bugs.php.net/bug.php?id=44936 which changes access level to 63 in PHP 5.2.6 - 5.2.17. 
  947. if ( isset( $ini_all[ $setting ]['access'] ) && ( INI_ALL === ( $ini_all[ $setting ]['access'] & 7 ) || INI_USER === ( $ini_all[ $setting ]['access'] & 7 ) ) ) { 
  948. return true; 
  949.  
  950. // If we were unable to retrieve the details, fail gracefully to assume it's changeable. 
  951. if ( ! is_array( $ini_all ) ) { 
  952. return true; 
  953.  
  954. return false; 
  955.  
  956. /** 
  957. * Determines whether the current request is a WordPress Ajax request. 
  958. * 
  959. * @since 4.7.0 
  960. * 
  961. * @return bool True if it's a WordPress Ajax request, false otherwise. 
  962. */ 
  963. function wp_doing_ajax() { 
  964. /** 
  965. * Filters whether the current request is a WordPress Ajax request. 
  966. * 
  967. * @since 4.7.0 
  968. * 
  969. * @param bool $wp_doing_ajax Whether the current request is a WordPress Ajax request. 
  970. */ 
  971. return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX ); 
  972.  
  973. /** 
  974. * Check whether variable is a WordPress Error. 
  975. * 
  976. * Returns true if $thing is an object of the WP_Error class. 
  977. * 
  978. * @since 2.1.0 
  979. * 
  980. * @param mixed $thing Check if unknown variable is a WP_Error object. 
  981. * @return bool True, if WP_Error. False, if not WP_Error. 
  982. */ 
  983. function is_wp_error( $thing ) { 
  984. return ( $thing instanceof WP_Error ); 
.