PageRenderTime 57ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-includes/load.php

https://gitlab.com/juanito.abelo/nlmobile
PHP | 1029 lines | 444 code | 119 blank | 466 comment | 132 complexity | 1310a25a97aa23befc7c8f6c76c7383e 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. /**
  163. * Filters whether to enable maintenance mode.
  164. *
  165. * This filter runs before it can be used by plugins. It is designed for
  166. * non-web runtimes. If this filter returns true, maintenance mode will be
  167. * active and the request will end. If false, the request will be allowed to
  168. * continue processing even if maintenance mode should be active.
  169. *
  170. * @since 4.6.0
  171. *
  172. * @param bool $enable_checks Whether to enable maintenance mode. Default true.
  173. * @param int $upgrading The timestamp set in the .maintenance file.
  174. */
  175. if ( ! apply_filters( 'enable_maintenance_mode', true, $upgrading ) ) {
  176. return;
  177. }
  178. if ( file_exists( WP_CONTENT_DIR . '/maintenance.php' ) ) {
  179. require_once( WP_CONTENT_DIR . '/maintenance.php' );
  180. die();
  181. }
  182. wp_load_translations_early();
  183. $protocol = wp_get_server_protocol();
  184. header( "$protocol 503 Service Unavailable", true, 503 );
  185. header( 'Content-Type: text/html; charset=utf-8' );
  186. header( 'Retry-After: 600' );
  187. ?>
  188. <!DOCTYPE html>
  189. <html xmlns="http://www.w3.org/1999/xhtml"<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>>
  190. <head>
  191. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  192. <title><?php _e( 'Maintenance' ); ?></title>
  193. </head>
  194. <body>
  195. <h1><?php _e( 'Briefly unavailable for scheduled maintenance. Check back in a minute.' ); ?></h1>
  196. </body>
  197. </html>
  198. <?php
  199. die();
  200. }
  201. /**
  202. * Start the WordPress micro-timer.
  203. *
  204. * @since 0.71
  205. * @access private
  206. *
  207. * @global float $timestart Unix timestamp set at the beginning of the page load.
  208. * @see timer_stop()
  209. *
  210. * @return bool Always returns true.
  211. */
  212. function timer_start() {
  213. global $timestart;
  214. $timestart = microtime( true );
  215. return true;
  216. }
  217. /**
  218. * Retrieve or display the time from the page start to when function is called.
  219. *
  220. * @since 0.71
  221. *
  222. * @global float $timestart Seconds from when timer_start() is called.
  223. * @global float $timeend Seconds from when function is called.
  224. *
  225. * @param int|bool $display Whether to echo or return the results. Accepts 0|false for return,
  226. * 1|true for echo. Default 0|false.
  227. * @param int $precision The number of digits from the right of the decimal to display.
  228. * Default 3.
  229. * @return string The "second.microsecond" finished time calculation. The number is formatted
  230. * for human consumption, both localized and rounded.
  231. */
  232. function timer_stop( $display = 0, $precision = 3 ) {
  233. global $timestart, $timeend;
  234. $timeend = microtime( true );
  235. $timetotal = $timeend - $timestart;
  236. $r = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision );
  237. if ( $display )
  238. echo $r;
  239. return $r;
  240. }
  241. /**
  242. * Set PHP error reporting based on WordPress debug settings.
  243. *
  244. * Uses three constants: `WP_DEBUG`, `WP_DEBUG_DISPLAY`, and `WP_DEBUG_LOG`.
  245. * All three can be defined in wp-config.php. By default, `WP_DEBUG` and
  246. * `WP_DEBUG_LOG` are set to false, and `WP_DEBUG_DISPLAY` is set to true.
  247. *
  248. * When `WP_DEBUG` is true, all PHP notices are reported. WordPress will also
  249. * display internal notices: when a deprecated WordPress function, function
  250. * argument, or file is used. Deprecated code may be removed from a later
  251. * version.
  252. *
  253. * It is strongly recommended that plugin and theme developers use `WP_DEBUG`
  254. * in their development environments.
  255. *
  256. * `WP_DEBUG_DISPLAY` and `WP_DEBUG_LOG` perform no function unless `WP_DEBUG`
  257. * is true.
  258. *
  259. * When `WP_DEBUG_DISPLAY` is true, WordPress will force errors to be displayed.
  260. * `WP_DEBUG_DISPLAY` defaults to true. Defining it as null prevents WordPress
  261. * from changing the global configuration setting. Defining `WP_DEBUG_DISPLAY`
  262. * as false will force errors to be hidden.
  263. *
  264. * When `WP_DEBUG_LOG` is true, errors will be logged to debug.log in the content
  265. * directory.
  266. *
  267. * Errors are never displayed for XML-RPC, REST, and Ajax requests.
  268. *
  269. * @since 3.0.0
  270. * @access private
  271. */
  272. function wp_debug_mode() {
  273. /**
  274. * Filters whether to allow the debug mode check to occur.
  275. *
  276. * This filter runs before it can be used by plugins. It is designed for
  277. * non-web run-times. Returning false causes the `WP_DEBUG` and related
  278. * constants to not be checked and the default php values for errors
  279. * will be used unless you take care to update them yourself.
  280. *
  281. * @since 4.6.0
  282. *
  283. * @param bool $enable_debug_mode Whether to enable debug mode checks to occur. Default true.
  284. */
  285. if ( ! apply_filters( 'enable_wp_debug_mode_checks', true ) ){
  286. return;
  287. }
  288. if ( WP_DEBUG ) {
  289. error_reporting( E_ALL );
  290. if ( WP_DEBUG_DISPLAY )
  291. ini_set( 'display_errors', 1 );
  292. elseif ( null !== WP_DEBUG_DISPLAY )
  293. ini_set( 'display_errors', 0 );
  294. if ( WP_DEBUG_LOG ) {
  295. ini_set( 'log_errors', 1 );
  296. ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' );
  297. }
  298. } else {
  299. 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 );
  300. }
  301. if ( defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
  302. @ini_set( 'display_errors', 0 );
  303. }
  304. }
  305. /**
  306. * Set the location of the language directory.
  307. *
  308. * To set directory manually, define the `WP_LANG_DIR` constant
  309. * in wp-config.php.
  310. *
  311. * If the language directory exists within `WP_CONTENT_DIR`, it
  312. * is used. Otherwise the language directory is assumed to live
  313. * in `WPINC`.
  314. *
  315. * @since 3.0.0
  316. * @access private
  317. */
  318. function wp_set_lang_dir() {
  319. if ( !defined( 'WP_LANG_DIR' ) ) {
  320. if ( file_exists( WP_CONTENT_DIR . '/languages' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) || !@is_dir(ABSPATH . WPINC . '/languages') ) {
  321. /**
  322. * Server path of the language directory.
  323. *
  324. * No leading slash, no trailing slash, full path, not relative to ABSPATH
  325. *
  326. * @since 2.1.0
  327. */
  328. define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' );
  329. if ( !defined( 'LANGDIR' ) ) {
  330. // Old static relative path maintained for limited backward compatibility - won't work in some cases.
  331. define( 'LANGDIR', 'wp-content/languages' );
  332. }
  333. } else {
  334. /**
  335. * Server path of the language directory.
  336. *
  337. * No leading slash, no trailing slash, full path, not relative to `ABSPATH`.
  338. *
  339. * @since 2.1.0
  340. */
  341. define( 'WP_LANG_DIR', ABSPATH . WPINC . '/languages' );
  342. if ( !defined( 'LANGDIR' ) ) {
  343. // Old relative path maintained for backward compatibility.
  344. define( 'LANGDIR', WPINC . '/languages' );
  345. }
  346. }
  347. }
  348. }
  349. /**
  350. * Load the database class file and instantiate the `$wpdb` global.
  351. *
  352. * @since 2.5.0
  353. *
  354. * @global wpdb $wpdb The WordPress database class.
  355. */
  356. function require_wp_db() {
  357. global $wpdb;
  358. require_once( ABSPATH . WPINC . '/wp-db.php' );
  359. if ( file_exists( WP_CONTENT_DIR . '/db.php' ) )
  360. require_once( WP_CONTENT_DIR . '/db.php' );
  361. if ( isset( $wpdb ) )
  362. return;
  363. $wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
  364. }
  365. /**
  366. * Set the database table prefix and the format specifiers for database
  367. * table columns.
  368. *
  369. * Columns not listed here default to `%s`.
  370. *
  371. * @since 3.0.0
  372. * @access private
  373. *
  374. * @global wpdb $wpdb The WordPress database class.
  375. * @global string $table_prefix The database table prefix.
  376. */
  377. function wp_set_wpdb_vars() {
  378. global $wpdb, $table_prefix;
  379. if ( !empty( $wpdb->error ) )
  380. dead_db();
  381. $wpdb->field_types = array( 'post_author' => '%d', 'post_parent' => '%d', 'menu_order' => '%d', 'term_id' => '%d', 'term_group' => '%d', 'term_taxonomy_id' => '%d',
  382. 'parent' => '%d', 'count' => '%d','object_id' => '%d', 'term_order' => '%d', 'ID' => '%d', 'comment_ID' => '%d', 'comment_post_ID' => '%d', 'comment_parent' => '%d',
  383. 'user_id' => '%d', 'link_id' => '%d', 'link_owner' => '%d', 'link_rating' => '%d', 'option_id' => '%d', 'blog_id' => '%d', 'meta_id' => '%d', 'post_id' => '%d',
  384. 'user_status' => '%d', 'umeta_id' => '%d', 'comment_karma' => '%d', 'comment_count' => '%d',
  385. // multisite:
  386. 'active' => '%d', 'cat_id' => '%d', 'deleted' => '%d', 'lang_id' => '%d', 'mature' => '%d', 'public' => '%d', 'site_id' => '%d', 'spam' => '%d',
  387. );
  388. $prefix = $wpdb->set_prefix( $table_prefix );
  389. if ( is_wp_error( $prefix ) ) {
  390. wp_load_translations_early();
  391. wp_die(
  392. /* translators: 1: $table_prefix 2: wp-config.php */
  393. sprintf( __( '<strong>ERROR</strong>: %1$s in %2$s can only contain numbers, letters, and underscores.' ),
  394. '<code>$table_prefix</code>',
  395. '<code>wp-config.php</code>'
  396. )
  397. );
  398. }
  399. }
  400. /**
  401. * Toggle `$_wp_using_ext_object_cache` on and off without directly
  402. * touching global.
  403. *
  404. * @since 3.7.0
  405. *
  406. * @global bool $_wp_using_ext_object_cache
  407. *
  408. * @param bool $using Whether external object cache is being used.
  409. * @return bool The current 'using' setting.
  410. */
  411. function wp_using_ext_object_cache( $using = null ) {
  412. global $_wp_using_ext_object_cache;
  413. $current_using = $_wp_using_ext_object_cache;
  414. if ( null !== $using )
  415. $_wp_using_ext_object_cache = $using;
  416. return $current_using;
  417. }
  418. /**
  419. * Start the WordPress object cache.
  420. *
  421. * If an object-cache.php file exists in the wp-content directory,
  422. * it uses that drop-in as an external object cache.
  423. *
  424. * @since 3.0.0
  425. * @access private
  426. *
  427. * @global int $blog_id Blog ID.
  428. */
  429. function wp_start_object_cache() {
  430. global $blog_id;
  431. $first_init = false;
  432. if ( ! function_exists( 'wp_cache_init' ) ) {
  433. if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
  434. require_once ( WP_CONTENT_DIR . '/object-cache.php' );
  435. if ( function_exists( 'wp_cache_init' ) )
  436. wp_using_ext_object_cache( true );
  437. }
  438. $first_init = true;
  439. } elseif ( ! wp_using_ext_object_cache() && file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
  440. /*
  441. * Sometimes advanced-cache.php can load object-cache.php before
  442. * it is loaded here. This breaks the function_exists check above
  443. * and can result in `$_wp_using_ext_object_cache` being set
  444. * incorrectly. Double check if an external cache exists.
  445. */
  446. wp_using_ext_object_cache( true );
  447. }
  448. if ( ! wp_using_ext_object_cache() )
  449. require_once ( ABSPATH . WPINC . '/cache.php' );
  450. /*
  451. * If cache supports reset, reset instead of init if already
  452. * initialized. Reset signals to the cache that global IDs
  453. * have changed and it may need to update keys and cleanup caches.
  454. */
  455. if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) )
  456. wp_cache_switch_to_blog( $blog_id );
  457. elseif ( function_exists( 'wp_cache_init' ) )
  458. wp_cache_init();
  459. if ( function_exists( 'wp_cache_add_global_groups' ) ) {
  460. 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' ) );
  461. wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) );
  462. }
  463. }
  464. /**
  465. * Redirect to the installer if WordPress is not installed.
  466. *
  467. * Dies with an error message when Multisite is enabled.
  468. *
  469. * @since 3.0.0
  470. * @access private
  471. */
  472. function wp_not_installed() {
  473. if ( is_multisite() ) {
  474. if ( ! is_blog_installed() && ! wp_installing() ) {
  475. nocache_headers();
  476. wp_die( __( 'The site you have requested is not installed properly. Please contact the system administrator.' ) );
  477. }
  478. } elseif ( ! is_blog_installed() && ! wp_installing() ) {
  479. nocache_headers();
  480. require( ABSPATH . WPINC . '/kses.php' );
  481. require( ABSPATH . WPINC . '/pluggable.php' );
  482. require( ABSPATH . WPINC . '/formatting.php' );
  483. $link = wp_guess_url() . '/wp-admin/install.php';
  484. wp_redirect( $link );
  485. die();
  486. }
  487. }
  488. /**
  489. * Retrieve an array of must-use plugin files.
  490. *
  491. * The default directory is wp-content/mu-plugins. To change the default
  492. * directory manually, define `WPMU_PLUGIN_DIR` and `WPMU_PLUGIN_URL`
  493. * in wp-config.php.
  494. *
  495. * @since 3.0.0
  496. * @access private
  497. *
  498. * @return array Files to include.
  499. */
  500. function wp_get_mu_plugins() {
  501. $mu_plugins = array();
  502. if ( !is_dir( WPMU_PLUGIN_DIR ) )
  503. return $mu_plugins;
  504. if ( ! $dh = opendir( WPMU_PLUGIN_DIR ) )
  505. return $mu_plugins;
  506. while ( ( $plugin = readdir( $dh ) ) !== false ) {
  507. if ( substr( $plugin, -4 ) == '.php' )
  508. $mu_plugins[] = WPMU_PLUGIN_DIR . '/' . $plugin;
  509. }
  510. closedir( $dh );
  511. sort( $mu_plugins );
  512. return $mu_plugins;
  513. }
  514. /**
  515. * Retrieve an array of active and valid plugin files.
  516. *
  517. * While upgrading or installing WordPress, no plugins are returned.
  518. *
  519. * The default directory is wp-content/plugins. To change the default
  520. * directory manually, define `WP_PLUGIN_DIR` and `WP_PLUGIN_URL`
  521. * in wp-config.php.
  522. *
  523. * @since 3.0.0
  524. * @access private
  525. *
  526. * @return array Files.
  527. */
  528. function wp_get_active_and_valid_plugins() {
  529. $plugins = array();
  530. $active_plugins = (array) get_option( 'active_plugins', array() );
  531. // Check for hacks file if the option is enabled
  532. if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) {
  533. _deprecated_file( 'my-hacks.php', '1.5.0' );
  534. array_unshift( $plugins, ABSPATH . 'my-hacks.php' );
  535. }
  536. if ( empty( $active_plugins ) || wp_installing() )
  537. return $plugins;
  538. $network_plugins = is_multisite() ? wp_get_active_network_plugins() : false;
  539. foreach ( $active_plugins as $plugin ) {
  540. if ( ! validate_file( $plugin ) // $plugin must validate as file
  541. && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php'
  542. && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist
  543. // not already included as a network plugin
  544. && ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins ) )
  545. )
  546. $plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
  547. }
  548. return $plugins;
  549. }
  550. /**
  551. * Set internal encoding.
  552. *
  553. * In most cases the default internal encoding is latin1, which is
  554. * of no use, since we want to use the `mb_` functions for `utf-8` strings.
  555. *
  556. * @since 3.0.0
  557. * @access private
  558. */
  559. function wp_set_internal_encoding() {
  560. if ( function_exists( 'mb_internal_encoding' ) ) {
  561. $charset = get_option( 'blog_charset' );
  562. if ( ! $charset || ! @mb_internal_encoding( $charset ) )
  563. mb_internal_encoding( 'UTF-8' );
  564. }
  565. }
  566. /**
  567. * Add magic quotes to `$_GET`, `$_POST`, `$_COOKIE`, and `$_SERVER`.
  568. *
  569. * Also forces `$_REQUEST` to be `$_GET + $_POST`. If `$_SERVER`,
  570. * `$_COOKIE`, or `$_ENV` are needed, use those superglobals directly.
  571. *
  572. * @since 3.0.0
  573. * @access private
  574. */
  575. function wp_magic_quotes() {
  576. // If already slashed, strip.
  577. if ( get_magic_quotes_gpc() ) {
  578. $_GET = stripslashes_deep( $_GET );
  579. $_POST = stripslashes_deep( $_POST );
  580. $_COOKIE = stripslashes_deep( $_COOKIE );
  581. }
  582. // Escape with wpdb.
  583. $_GET = add_magic_quotes( $_GET );
  584. $_POST = add_magic_quotes( $_POST );
  585. $_COOKIE = add_magic_quotes( $_COOKIE );
  586. $_SERVER = add_magic_quotes( $_SERVER );
  587. // Force REQUEST to be GET + POST.
  588. $_REQUEST = array_merge( $_GET, $_POST );
  589. }
  590. /**
  591. * Runs just before PHP shuts down execution.
  592. *
  593. * @since 1.2.0
  594. * @access private
  595. */
  596. function shutdown_action_hook() {
  597. /**
  598. * Fires just before PHP shuts down execution.
  599. *
  600. * @since 1.2.0
  601. */
  602. do_action( 'shutdown' );
  603. wp_cache_close();
  604. }
  605. /**
  606. * Copy an object.
  607. *
  608. * @since 2.7.0
  609. * @deprecated 3.2.0
  610. *
  611. * @param object $object The object to clone.
  612. * @return object The cloned object.
  613. */
  614. function wp_clone( $object ) {
  615. // Use parens for clone to accommodate PHP 4. See #17880
  616. return clone( $object );
  617. }
  618. /**
  619. * Whether the current request is for an administrative interface page.
  620. *
  621. * Does not check if the user is an administrator; current_user_can()
  622. * for checking roles and capabilities.
  623. *
  624. * @since 1.5.1
  625. *
  626. * @global WP_Screen $current_screen
  627. *
  628. * @return bool True if inside WordPress administration interface, false otherwise.
  629. */
  630. function is_admin() {
  631. if ( isset( $GLOBALS['current_screen'] ) )
  632. return $GLOBALS['current_screen']->in_admin();
  633. elseif ( defined( 'WP_ADMIN' ) )
  634. return WP_ADMIN;
  635. return false;
  636. }
  637. /**
  638. * Whether the current request is for a site's admininstrative interface.
  639. *
  640. * e.g. `/wp-admin/`
  641. *
  642. * Does not check if the user is an administrator; current_user_can()
  643. * for checking roles and capabilities.
  644. *
  645. * @since 3.1.0
  646. *
  647. * @global WP_Screen $current_screen
  648. *
  649. * @return bool True if inside WordPress blog administration pages.
  650. */
  651. function is_blog_admin() {
  652. if ( isset( $GLOBALS['current_screen'] ) )
  653. return $GLOBALS['current_screen']->in_admin( 'site' );
  654. elseif ( defined( 'WP_BLOG_ADMIN' ) )
  655. return WP_BLOG_ADMIN;
  656. return false;
  657. }
  658. /**
  659. * Whether the current request is for the network administrative interface.
  660. *
  661. * e.g. `/wp-admin/network/`
  662. *
  663. * Does not check if the user is an administrator; current_user_can()
  664. * for checking roles and capabilities.
  665. *
  666. * @since 3.1.0
  667. *
  668. * @global WP_Screen $current_screen
  669. *
  670. * @return bool True if inside WordPress network administration pages.
  671. */
  672. function is_network_admin() {
  673. if ( isset( $GLOBALS['current_screen'] ) )
  674. return $GLOBALS['current_screen']->in_admin( 'network' );
  675. elseif ( defined( 'WP_NETWORK_ADMIN' ) )
  676. return WP_NETWORK_ADMIN;
  677. return false;
  678. }
  679. /**
  680. * Whether the current request is for a user admin screen.
  681. *
  682. * e.g. `/wp-admin/user/`
  683. *
  684. * Does not inform on whether the user is an admin! Use capability
  685. * checks to tell if the user should be accessing a section or not
  686. * current_user_can().
  687. *
  688. * @since 3.1.0
  689. *
  690. * @global WP_Screen $current_screen
  691. *
  692. * @return bool True if inside WordPress user administration pages.
  693. */
  694. function is_user_admin() {
  695. if ( isset( $GLOBALS['current_screen'] ) )
  696. return $GLOBALS['current_screen']->in_admin( 'user' );
  697. elseif ( defined( 'WP_USER_ADMIN' ) )
  698. return WP_USER_ADMIN;
  699. return false;
  700. }
  701. /**
  702. * If Multisite is enabled.
  703. *
  704. * @since 3.0.0
  705. *
  706. * @return bool True if Multisite is enabled, false otherwise.
  707. */
  708. function is_multisite() {
  709. if ( defined( 'MULTISITE' ) )
  710. return MULTISITE;
  711. if ( defined( 'SUBDOMAIN_INSTALL' ) || defined( 'VHOST' ) || defined( 'SUNRISE' ) )
  712. return true;
  713. return false;
  714. }
  715. /**
  716. * Retrieve the current site ID.
  717. *
  718. * @since 3.1.0
  719. *
  720. * @global int $blog_id
  721. *
  722. * @return int Site ID.
  723. */
  724. function get_current_blog_id() {
  725. global $blog_id;
  726. return absint($blog_id);
  727. }
  728. /**
  729. * Retrieves the current network ID.
  730. *
  731. * @since 4.6.0
  732. *
  733. * @global WP_Network $current_site The current network.
  734. *
  735. * @return int The ID of the current network.
  736. */
  737. function get_current_network_id() {
  738. if ( ! is_multisite() ) {
  739. return 1;
  740. }
  741. $current_site = get_current_site();
  742. if ( ! isset( $current_site->id ) ) {
  743. return get_main_network_id();
  744. }
  745. return absint( $current_site->id );
  746. }
  747. /**
  748. * Attempt an early load of translations.
  749. *
  750. * Used for errors encountered during the initial loading process, before
  751. * the locale has been properly detected and loaded.
  752. *
  753. * Designed for unusual load sequences (like setup-config.php) or for when
  754. * the script will then terminate with an error, otherwise there is a risk
  755. * that a file can be double-included.
  756. *
  757. * @since 3.4.0
  758. * @access private
  759. *
  760. * @global string $text_direction
  761. * @global WP_Locale $wp_locale The WordPress date and time locale object.
  762. *
  763. * @staticvar bool $loaded
  764. */
  765. function wp_load_translations_early() {
  766. global $text_direction, $wp_locale;
  767. static $loaded = false;
  768. if ( $loaded )
  769. return;
  770. $loaded = true;
  771. if ( function_exists( 'did_action' ) && did_action( 'init' ) )
  772. return;
  773. // We need $wp_local_package
  774. require ABSPATH . WPINC . '/version.php';
  775. // Translation and localization
  776. require_once ABSPATH . WPINC . '/pomo/mo.php';
  777. require_once ABSPATH . WPINC . '/l10n.php';
  778. require_once ABSPATH . WPINC . '/locale.php';
  779. // General libraries
  780. require_once ABSPATH . WPINC . '/plugin.php';
  781. $locales = $locations = array();
  782. while ( true ) {
  783. if ( defined( 'WPLANG' ) ) {
  784. if ( '' == WPLANG )
  785. break;
  786. $locales[] = WPLANG;
  787. }
  788. if ( isset( $wp_local_package ) )
  789. $locales[] = $wp_local_package;
  790. if ( ! $locales )
  791. break;
  792. if ( defined( 'WP_LANG_DIR' ) && @is_dir( WP_LANG_DIR ) )
  793. $locations[] = WP_LANG_DIR;
  794. if ( defined( 'WP_CONTENT_DIR' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) )
  795. $locations[] = WP_CONTENT_DIR . '/languages';
  796. if ( @is_dir( ABSPATH . 'wp-content/languages' ) )
  797. $locations[] = ABSPATH . 'wp-content/languages';
  798. if ( @is_dir( ABSPATH . WPINC . '/languages' ) )
  799. $locations[] = ABSPATH . WPINC . '/languages';
  800. if ( ! $locations )
  801. break;
  802. $locations = array_unique( $locations );
  803. foreach ( $locales as $locale ) {
  804. foreach ( $locations as $location ) {
  805. if ( file_exists( $location . '/' . $locale . '.mo' ) ) {
  806. load_textdomain( 'default', $location . '/' . $locale . '.mo' );
  807. if ( defined( 'WP_SETUP_CONFIG' ) && file_exists( $location . '/admin-' . $locale . '.mo' ) )
  808. load_textdomain( 'default', $location . '/admin-' . $locale . '.mo' );
  809. break 2;
  810. }
  811. }
  812. }
  813. break;
  814. }
  815. $wp_locale = new WP_Locale();
  816. }
  817. /**
  818. * Check or set whether WordPress is in "installation" mode.
  819. *
  820. * If the `WP_INSTALLING` constant is defined during the bootstrap, `wp_installing()` will default to `true`.
  821. *
  822. * @since 4.4.0
  823. *
  824. * @staticvar bool $installing
  825. *
  826. * @param bool $is_installing Optional. True to set WP into Installing mode, false to turn Installing mode off.
  827. * Omit this parameter if you only want to fetch the current status.
  828. * @return bool True if WP is installing, otherwise false. When a `$is_installing` is passed, the function will
  829. * report whether WP was in installing mode prior to the change to `$is_installing`.
  830. */
  831. function wp_installing( $is_installing = null ) {
  832. static $installing = null;
  833. // Support for the `WP_INSTALLING` constant, defined before WP is loaded.
  834. if ( is_null( $installing ) ) {
  835. $installing = defined( 'WP_INSTALLING' ) && WP_INSTALLING;
  836. }
  837. if ( ! is_null( $is_installing ) ) {
  838. $old_installing = $installing;
  839. $installing = $is_installing;
  840. return (bool) $old_installing;
  841. }
  842. return (bool) $installing;
  843. }
  844. /**
  845. * Determines if SSL is used.
  846. *
  847. * @since 2.6.0
  848. * @since 4.6.0 Moved from functions.php to load.php.
  849. *
  850. * @return bool True if SSL, otherwise false.
  851. */
  852. function is_ssl() {
  853. if ( isset( $_SERVER['HTTPS'] ) ) {
  854. if ( 'on' == strtolower( $_SERVER['HTTPS'] ) ) {
  855. return true;
  856. }
  857. if ( '1' == $_SERVER['HTTPS'] ) {
  858. return true;
  859. }
  860. } elseif ( isset($_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
  861. return true;
  862. }
  863. return false;
  864. }
  865. /**
  866. * Converts a shorthand byte value to an integer byte value.
  867. *
  868. * @since 2.3.0
  869. * @since 4.6.0 Moved from media.php to load.php.
  870. *
  871. * @link http://php.net/manual/en/function.ini-get.php
  872. * @link http://php.net/manual/en/faq.using.php#faq.using.shorthandbytes
  873. *
  874. * @param string $value A (PHP ini) byte value, either shorthand or ordinary.
  875. * @return int An integer byte value.
  876. */
  877. function wp_convert_hr_to_bytes( $value ) {
  878. $value = strtolower( trim( $value ) );
  879. $bytes = (int) $value;
  880. if ( false !== strpos( $value, 'g' ) ) {
  881. $bytes *= GB_IN_BYTES;
  882. } elseif ( false !== strpos( $value, 'm' ) ) {
  883. $bytes *= MB_IN_BYTES;
  884. } elseif ( false !== strpos( $value, 'k' ) ) {
  885. $bytes *= KB_IN_BYTES;
  886. }
  887. // Deal with large (float) values which run into the maximum integer size.
  888. return min( $bytes, PHP_INT_MAX );
  889. }
  890. /**
  891. * Determines whether a PHP ini value is changeable at runtime.
  892. *
  893. * @since 4.6.0
  894. *
  895. * @link http://php.net/manual/en/function.ini-get-all.php
  896. *
  897. * @param string $setting The name of the ini setting to check.
  898. * @return bool True if the value is changeable at runtime. False otherwise.
  899. */
  900. function wp_is_ini_value_changeable( $setting ) {
  901. static $ini_all;
  902. if ( ! isset( $ini_all ) ) {
  903. $ini_all = ini_get_all();
  904. }
  905. // 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.
  906. if ( isset( $ini_all[ $setting ]['access'] ) && ( INI_ALL === ( $ini_all[ $setting ]['access'] & 7 ) || INI_USER === ( $ini_all[ $setting ]['access'] & 7 ) ) ) {
  907. return true;
  908. }
  909. return false;
  910. }