/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. $first_init = false; 
  440. if ( ! function_exists( 'wp_cache_init' ) ) { 
  441. if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) { 
  442. require_once ( WP_CONTENT_DIR . '/object-cache.php' ); 
  443. if ( function_exists( 'wp_cache_init' ) ) { 
  444. wp_using_ext_object_cache( true ); 
  445.  
  446. $first_init = true; 
  447. } elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) { 
  448. /** 
  449. * Sometimes advanced-cache.php can load object-cache.php before 
  450. * it is loaded here. This breaks the function_exists check above 
  451. * and can result in `$_wp_using_ext_object_cache` being set 
  452. * incorrectly. Double check if an external cache exists. 
  453. */ 
  454. wp_using_ext_object_cache( true ); 
  455.  
  456. if ( ! wp_using_ext_object_cache() ) { 
  457. require_once ( ABSPATH . WPINC . '/cache.php' ); 
  458.  
  459. /** 
  460. * If cache supports reset, reset instead of init if already 
  461. * initialized. Reset signals to the cache that global IDs 
  462. * have changed and it may need to update keys and cleanup caches. 
  463. */ 
  464. if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) ) { 
  465. wp_cache_switch_to_blog( get_current_blog_id() ); 
  466. } elseif ( function_exists( 'wp_cache_init' ) ) { 
  467. wp_cache_init(); 
  468.  
  469. if ( function_exists( 'wp_cache_add_global_groups' ) ) { 
  470. 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' ) ); 
  471. wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); 
  472.  
  473. /** 
  474. * Redirect to the installer if WordPress is not installed. 
  475. * 
  476. * Dies with an error message when Multisite is enabled. 
  477. * 
  478. * @since 3.0.0 
  479. * @access private 
  480. */ 
  481. function wp_not_installed() { 
  482. if ( is_multisite() ) { 
  483. if ( ! is_blog_installed() && ! wp_installing() ) { 
  484. nocache_headers(); 
  485.  
  486. wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) ); 
  487. } elseif ( ! is_blog_installed() && ! wp_installing() ) { 
  488. nocache_headers(); 
  489.  
  490. require( ABSPATH . WPINC . '/kses.php' ); 
  491. require( ABSPATH . WPINC . '/pluggable.php' ); 
  492. require( ABSPATH . WPINC . '/formatting.php' ); 
  493.  
  494. $link = wp_guess_url() . '/wp-admin/install.php'; 
  495.  
  496. wp_redirect( $link ); 
  497. die(); 
  498.  
  499. /** 
  500. * Retrieve an array of must-use plugin files. 
  501. * 
  502. * The default directory is wp-content/mu-plugins. To change the default 
  503. * directory manually, define `WPMU_PLUGIN_DIR` and `WPMU_PLUGIN_URL` 
  504. * in wp-config.php. 
  505. * 
  506. * @since 3.0.0 
  507. * @access private 
  508. * 
  509. * @return array Files to include. 
  510. */ 
  511. function wp_get_mu_plugins() { 
  512. $mu_plugins = array(); 
  513. if ( !is_dir( WPMU_PLUGIN_DIR ) ) 
  514. return $mu_plugins; 
  515. if ( ! $dh = opendir( WPMU_PLUGIN_DIR ) ) 
  516. return $mu_plugins; 
  517. while ( ( $plugin = readdir( $dh ) ) !== false ) { 
  518. if ( substr( $plugin, -4 ) == '.php' ) 
  519. $mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin; 
  520. closedir( $dh ); 
  521. sort( $mu_plugins ); 
  522.  
  523. return $mu_plugins; 
  524.  
  525. /** 
  526. * Retrieve an array of active and valid plugin files. 
  527. * 
  528. * While upgrading or installing WordPress, no plugins are returned. 
  529. * 
  530. * The default directory is wp-content/plugins. To change the default 
  531. * directory manually, define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL` 
  532. * in wp-config.php. 
  533. * 
  534. * @since 3.0.0 
  535. * @access private 
  536. * 
  537. * @return array Files. 
  538. */ 
  539. function wp_get_active_and_valid_plugins() { 
  540. $plugins = array(); 
  541. $active_plugins = (array) get_option( 'active_plugins', array() ); 
  542.  
  543. // Check for hacks file if the option is enabled 
  544. if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) { 
  545. _deprecated_file( 'my-hacks.php', '1.5.0' ); 
  546. array_unshift( $plugins, ABSPATH . 'my-hacks.php' ); 
  547.  
  548. if ( empty( $active_plugins ) || wp_installing() ) 
  549. return $plugins; 
  550.  
  551. $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false; 
  552.  
  553. foreach ( $active_plugins as $plugin ) { 
  554. if ( ! validate_file( $plugin ) // $plugin must validate as file 
  555. && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php' 
  556. && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist 
  557. // not already included as a network plugin 
  558. && ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins ) ) 
  559. $plugins[] = WP_PLUGIN_DIR . '/' . $plugin; 
  560. return $plugins; 
  561.  
  562. /** 
  563. * Set internal encoding. 
  564. * 
  565. * In most cases the default internal encoding is latin1, which is 
  566. * of no use, since we want to use the `mb_` functions for `utf-8` strings. 
  567. * 
  568. * @since 3.0.0 
  569. * @access private 
  570. */ 
  571. function wp_set_internal_encoding() { 
  572. if ( function_exists( 'mb_internal_encoding' ) ) { 
  573. $charset = get_option( 'blog_charset' ); 
  574. if ( ! $charset || ! @mb_internal_encoding( $charset ) ) 
  575. mb_internal_encoding( 'UTF-8' ); 
  576.  
  577. /** 
  578. * Add magic quotes to `$_GET`, `$_POST`, `$_COOKIE`, and `$_SERVER`. 
  579. * 
  580. * Also forces `$_REQUEST` to be `$_GET + $_POST`. If `$_SERVER`,  
  581. * `$_COOKIE`, or `$_ENV` are needed, use those superglobals directly. 
  582. * 
  583. * @since 3.0.0 
  584. * @access private 
  585. */ 
  586. function wp_magic_quotes() { 
  587. // If already slashed, strip. 
  588. if ( get_magic_quotes_gpc() ) { 
  589. $_GET = stripslashes_deep( $_GET ); 
  590. $_POST = stripslashes_deep( $_POST ); 
  591. $_COOKIE = stripslashes_deep( $_COOKIE ); 
  592.  
  593. // Escape with wpdb. 
  594. $_GET = add_magic_quotes( $_GET ); 
  595. $_POST = add_magic_quotes( $_POST ); 
  596. $_COOKIE = add_magic_quotes( $_COOKIE ); 
  597. $_SERVER = add_magic_quotes( $_SERVER ); 
  598.  
  599. // Force REQUEST to be GET + POST. 
  600. $_REQUEST = array_merge( $_GET, $_POST ); 
  601.  
  602. /** 
  603. * Runs just before PHP shuts down execution. 
  604. * 
  605. * @since 1.2.0 
  606. * @access private 
  607. */ 
  608. function shutdown_action_hook() { 
  609. /** 
  610. * Fires just before PHP shuts down execution. 
  611. * 
  612. * @since 1.2.0 
  613. */ 
  614. do_action( 'shutdown' ); 
  615.  
  616. wp_cache_close(); 
  617.  
  618. /** 
  619. * Copy an object. 
  620. * 
  621. * @since 2.7.0 
  622. * @deprecated 3.2.0 
  623. * 
  624. * @param object $object The object to clone. 
  625. * @return object The cloned object. 
  626. */ 
  627. function wp_clone( $object ) { 
  628. // Use parens for clone to accommodate PHP 4. See #17880 
  629. return clone( $object ); 
  630.  
  631. /** 
  632. * Whether the current request is for an administrative interface page. 
  633. * 
  634. * Does not check if the user is an administrator; current_user_can() 
  635. * for checking roles and capabilities. 
  636. * 
  637. * @since 1.5.1 
  638. * 
  639. * @global WP_Screen $current_screen 
  640. * 
  641. * @return bool True if inside WordPress administration interface, false otherwise. 
  642. */ 
  643. function is_admin() { 
  644. if ( isset( $GLOBALS['current_screen'] ) ) 
  645. return $GLOBALS['current_screen']->in_admin(); 
  646. elseif ( defined( 'WP_ADMIN' ) ) 
  647. return WP_ADMIN; 
  648.  
  649. return false; 
  650.  
  651. /** 
  652. * Whether the current request is for a site's admininstrative interface. 
  653. * 
  654. * e.g. `/wp-admin/` 
  655. * 
  656. * Does not check if the user is an administrator; current_user_can() 
  657. * for checking roles and capabilities. 
  658. * 
  659. * @since 3.1.0 
  660. * 
  661. * @global WP_Screen $current_screen 
  662. * 
  663. * @return bool True if inside WordPress blog administration pages. 
  664. */ 
  665. function is_blog_admin() { 
  666. if ( isset( $GLOBALS['current_screen'] ) ) 
  667. return $GLOBALS['current_screen']->in_admin( 'site' ); 
  668. elseif ( defined( 'WP_BLOG_ADMIN' ) ) 
  669. return WP_BLOG_ADMIN; 
  670.  
  671. return false; 
  672.  
  673. /** 
  674. * Whether the current request is for the network administrative interface. 
  675. * 
  676. * e.g. `/wp-admin/network/` 
  677. * 
  678. * Does not check if the user is an administrator; current_user_can() 
  679. * for checking roles and capabilities. 
  680. * 
  681. * @since 3.1.0 
  682. * 
  683. * @global WP_Screen $current_screen 
  684. * 
  685. * @return bool True if inside WordPress network administration pages. 
  686. */ 
  687. function is_network_admin() { 
  688. if ( isset( $GLOBALS['current_screen'] ) ) 
  689. return $GLOBALS['current_screen']->in_admin( 'network' ); 
  690. elseif ( defined( 'WP_NETWORK_ADMIN' ) ) 
  691. return WP_NETWORK_ADMIN; 
  692.  
  693. return false; 
  694.  
  695. /** 
  696. * Whether the current request is for a user admin screen. 
  697. * 
  698. * e.g. `/wp-admin/user/` 
  699. * 
  700. * Does not inform on whether the user is an admin! Use capability 
  701. * checks to tell if the user should be accessing a section or not 
  702. * current_user_can(). 
  703. * 
  704. * @since 3.1.0 
  705. * 
  706. * @global WP_Screen $current_screen 
  707. * 
  708. * @return bool True if inside WordPress user administration pages. 
  709. */ 
  710. function is_user_admin() { 
  711. if ( isset( $GLOBALS['current_screen'] ) ) 
  712. return $GLOBALS['current_screen']->in_admin( 'user' ); 
  713. elseif ( defined( 'WP_USER_ADMIN' ) ) 
  714. return WP_USER_ADMIN; 
  715.  
  716. return false; 
  717.  
  718. /** 
  719. * If Multisite is enabled. 
  720. * 
  721. * @since 3.0.0 
  722. * 
  723. * @return bool True if Multisite is enabled, false otherwise. 
  724. */ 
  725. function is_multisite() { 
  726. if ( defined( 'MULTISITE' ) ) 
  727. return MULTISITE; 
  728.  
  729. if ( defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) ) 
  730. return true; 
  731.  
  732. return false; 
  733.  
  734. /** 
  735. * Retrieve the current site ID. 
  736. * 
  737. * @since 3.1.0 
  738. * 
  739. * @global int $blog_id 
  740. * 
  741. * @return int Site ID. 
  742. */ 
  743. function get_current_blog_id() { 
  744. global $blog_id; 
  745. return absint($blog_id); 
  746.  
  747. /** 
  748. * Retrieves the current network ID. 
  749. * 
  750. * @since 4.6.0 
  751. * 
  752. * @return int The ID of the current network. 
  753. */ 
  754. function get_current_network_id() { 
  755. if ( ! is_multisite() ) { 
  756. return 1; 
  757.  
  758. $current_network = get_network(); 
  759.  
  760. if ( ! isset( $current_network->id ) ) { 
  761. return get_main_network_id(); 
  762.  
  763. return absint( $current_network->id ); 
  764.  
  765. /** 
  766. * Attempt an early load of translations. 
  767. * 
  768. * Used for errors encountered during the initial loading process, before 
  769. * the locale has been properly detected and loaded. 
  770. * 
  771. * Designed for unusual load sequences (like setup-config.php) or for when 
  772. * the script will then terminate with an error, otherwise there is a risk 
  773. * that a file can be double-included. 
  774. * 
  775. * @since 3.4.0 
  776. * @access private 
  777. * 
  778. * @global WP_Locale $wp_locale The WordPress date and time locale object. 
  779. * 
  780. * @staticvar bool $loaded 
  781. */ 
  782. function wp_load_translations_early() { 
  783. global $wp_locale; 
  784.  
  785. static $loaded = false; 
  786. if ( $loaded ) 
  787. return; 
  788. $loaded = true; 
  789.  
  790. if ( function_exists( 'did_action' ) && did_action( 'init' ) ) 
  791. return; 
  792.  
  793. // We need $wp_local_package 
  794. require ABSPATH . WPINC . '/version.php'; 
  795.  
  796. // Translation and localization 
  797. require_once ABSPATH . WPINC . '/pomo/mo.php'; 
  798. require_once ABSPATH . WPINC . '/l10n.php'; 
  799. require_once ABSPATH . WPINC . '/class-wp-locale.php'; 
  800. require_once ABSPATH . WPINC . '/class-wp-locale-switcher.php'; 
  801.  
  802. // General libraries 
  803. require_once ABSPATH . WPINC . '/plugin.php'; 
  804.  
  805. $locales = $locations = array(); 
  806.  
  807. while ( true ) { 
  808. if ( defined( 'WPLANG' ) ) { 
  809. if ( '' == WPLANG ) 
  810. break; 
  811. $locales[] = WPLANG; 
  812.  
  813. if ( isset( $wp_local_package ) ) 
  814. $locales[] = $wp_local_package; 
  815.  
  816. if ( ! $locales ) 
  817. break; 
  818.  
  819. if ( defined( 'WP_LANG_DIR' ) && @is_dir( WP_LANG_DIR ) ) 
  820. $locations[] = WP_LANG_DIR; 
  821.  
  822. if ( defined( 'WP_CONTENT_DIR' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) ) 
  823. $locations[] = WP_CONTENT_DIR . '/languages'; 
  824.  
  825. if ( @is_dir( ABSPATH . 'wp-content/languages' ) ) 
  826. $locations[] = ABSPATH . 'wp-content/languages'; 
  827.  
  828. if ( @is_dir( ABSPATH . WPINC . '/languages' ) ) 
  829. $locations[] = ABSPATH . WPINC . '/languages'; 
  830.  
  831. if ( ! $locations ) 
  832. break; 
  833.  
  834. $locations = array_unique( $locations ); 
  835.  
  836. foreach ( $locales as $locale ) { 
  837. foreach ( $locations as $location ) { 
  838. if ( file_exists( $location . '/' . $locale . '.mo' ) ) { 
  839. load_textdomain( 'default', $location . '/' . $locale . '.mo' ); 
  840. if ( defined( 'WP_SETUP_CONFIG' ) && file_exists( $location . '/admin-' . $locale . '.mo' ) ) 
  841. load_textdomain( 'default', $location . '/admin-' . $locale . '.mo' ); 
  842. break 2; 
  843.  
  844. break; 
  845.  
  846. $wp_locale = new WP_Locale(); 
  847.  
  848. /** 
  849. * Check or set whether WordPress is in "installation" mode. 
  850. * 
  851. * If the `WP_INSTALLING` constant is defined during the bootstrap, `wp_installing()` will default to `true`. 
  852. * 
  853. * @since 4.4.0 
  854. * 
  855. * @staticvar bool $installing 
  856. * 
  857. * @param bool $is_installing Optional. True to set WP into Installing mode, false to turn Installing mode off. 
  858. * Omit this parameter if you only want to fetch the current status. 
  859. * @return bool True if WP is installing, otherwise false. When a `$is_installing` is passed, the function will 
  860. * report whether WP was in installing mode prior to the change to `$is_installing`. 
  861. */ 
  862. function wp_installing( $is_installing = null ) { 
  863. static $installing = null; 
  864.  
  865. // Support for the `WP_INSTALLING` constant, defined before WP is loaded. 
  866. if ( is_null( $installing ) ) { 
  867. $installing = defined( 'WP_INSTALLING' ) && WP_INSTALLING; 
  868.  
  869. if ( ! is_null( $is_installing ) ) { 
  870. $old_installing = $installing; 
  871. $installing = $is_installing; 
  872. return (bool) $old_installing; 
  873.  
  874. return (bool) $installing; 
  875.  
  876. /** 
  877. * Determines if SSL is used. 
  878. * 
  879. * @since 2.6.0 
  880. * @since 4.6.0 Moved from functions.php to load.php. 
  881. * 
  882. * @return bool True if SSL, otherwise false. 
  883. */ 
  884. function is_ssl() { 
  885. if ( isset( $_SERVER['HTTPS'] ) ) { 
  886. if ( 'on' == strtolower( $_SERVER['HTTPS'] ) ) { 
  887. return true; 
  888.  
  889. if ( '1' == $_SERVER['HTTPS'] ) { 
  890. return true; 
  891. } elseif ( isset($_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) { 
  892. return true; 
  893. return false; 
  894.  
  895. /** 
  896. * Converts a shorthand byte value to an integer byte value. 
  897. * 
  898. * @since 2.3.0 
  899. * @since 4.6.0 Moved from media.php to load.php. 
  900. * 
  901. * @link https://secure.php.net/manual/en/function.ini-get.php 
  902. * @link https://secure.php.net/manual/en/faq.using.php#faq.using.shorthandbytes 
  903. * 
  904. * @param string $value A (PHP ini) byte value, either shorthand or ordinary. 
  905. * @return int An integer byte value. 
  906. */ 
  907. function wp_convert_hr_to_bytes( $value ) { 
  908. $value = strtolower( trim( $value ) ); 
  909. $bytes = (int) $value; 
  910.  
  911. if ( false !== strpos( $value, 'g' ) ) { 
  912. $bytes *= GB_IN_BYTES; 
  913. } elseif ( false !== strpos( $value, 'm' ) ) { 
  914. $bytes *= MB_IN_BYTES; 
  915. } elseif ( false !== strpos( $value, 'k' ) ) { 
  916. $bytes *= KB_IN_BYTES; 
  917.  
  918. // Deal with large (float) values which run into the maximum integer size. 
  919. return min( $bytes, PHP_INT_MAX ); 
  920.  
  921. /** 
  922. * Determines whether a PHP ini value is changeable at runtime. 
  923. * 
  924. * @since 4.6.0 
  925. * 
  926. * @link https://secure.php.net/manual/en/function.ini-get-all.php 
  927. * 
  928. * @param string $setting The name of the ini setting to check. 
  929. * @return bool True if the value is changeable at runtime. False otherwise. 
  930. */ 
  931. function wp_is_ini_value_changeable( $setting ) { 
  932. static $ini_all; 
  933.  
  934. if ( ! isset( $ini_all ) ) { 
  935. $ini_all = false; 
  936. // Sometimes `ini_get_all()` is disabled via the `disable_functions` option for "security purposes". 
  937. if ( function_exists( 'ini_get_all' ) ) { 
  938. $ini_all = ini_get_all(); 
  939.  
  940. // 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. 
  941. if ( isset( $ini_all[ $setting ]['access'] ) && ( INI_ALL === ( $ini_all[ $setting ]['access'] & 7 ) || INI_USER === ( $ini_all[ $setting ]['access'] & 7 ) ) ) { 
  942. return true; 
  943.  
  944. // If we were unable to retrieve the details, fail gracefully to assume it's changeable. 
  945. if ( ! is_array( $ini_all ) ) { 
  946. return true; 
  947.  
  948. return false; 
  949.  
  950. /** 
  951. * Determines whether the current request is a WordPress Ajax request. 
  952. * 
  953. * @since 4.7.0 
  954. * 
  955. * @return bool True if it's a WordPress Ajax request, false otherwise. 
  956. */ 
  957. function wp_doing_ajax() { 
  958. /** 
  959. * Filters whether the current request is a WordPress Ajax request. 
  960. * 
  961. * @since 4.7.0 
  962. * 
  963. * @param bool $wp_doing_ajax Whether the current request is a WordPress Ajax request. 
  964. */ 
  965. return apply_filters( 'wp_doing_ajax', defined( 'DOING_AJAX' ) && DOING_AJAX ); 
  966.  
  967. /** 
  968. * Check whether variable is a WordPress Error. 
  969. * 
  970. * Returns true if $thing is an object of the WP_Error class. 
  971. * 
  972. * @since 2.1.0 
  973. * 
  974. * @param mixed $thing Check if unknown variable is a WP_Error object. 
  975. * @return bool True, if WP_Error. False, if not WP_Error. 
  976. */ 
  977. function is_wp_error( $thing ) { 
  978. return ( $thing instanceof WP_Error ); 
.