PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-includes/load.php

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