PageRenderTime 53ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/php/wp-settings-cli.php

https://gitlab.com/clakeb/wp-cli
PHP | 366 lines | 189 code | 65 blank | 112 comment | 27 complexity | fcc53a8e276bf8c515266048522987b1 MD5 | raw file
  1. <?php
  2. /**
  3. * A modified version of wp-settings.php, tailored for CLI use.
  4. */
  5. use \WP_CLI\Utils;
  6. /**
  7. * Stores the location of the WordPress directory of functions, classes, and core content.
  8. *
  9. * @since 1.0.0
  10. */
  11. define( 'WPINC', 'wp-includes' );
  12. // Include files required for initialization.
  13. require( ABSPATH . WPINC . '/load.php' );
  14. require( ABSPATH . WPINC . '/default-constants.php' );
  15. require( ABSPATH . WPINC . '/version.php' );
  16. // Set initial default constants including WP_MEMORY_LIMIT, WP_MAX_MEMORY_LIMIT, WP_DEBUG, WP_CONTENT_DIR and WP_CACHE.
  17. wp_initial_constants();
  18. // Check for the required PHP version and for the MySQL extension or a database drop-in.
  19. wp_check_php_mysql_versions();
  20. // Disable magic quotes at runtime. Magic quotes are added using wpdb later in wp-settings.php.
  21. @ini_set( 'magic_quotes_runtime', 0 );
  22. @ini_set( 'magic_quotes_sybase', 0 );
  23. // WordPress calculates offsets from UTC.
  24. date_default_timezone_set( 'UTC' );
  25. // Turn register_globals off.
  26. wp_unregister_GLOBALS();
  27. // Standardize $_SERVER variables across setups.
  28. wp_fix_server_vars();
  29. // Start loading timer.
  30. timer_start();
  31. // Load WP-CLI utilities
  32. require WP_CLI_ROOT . '/php/utils-wp.php';
  33. // Check if we're in WP_DEBUG mode.
  34. Utils\wp_debug_mode();
  35. // Define WP_LANG_DIR if not set.
  36. wp_set_lang_dir();
  37. // Load early WordPress files.
  38. require( ABSPATH . WPINC . '/compat.php' );
  39. require( ABSPATH . WPINC . '/functions.php' );
  40. require( ABSPATH . WPINC . '/class-wp.php' );
  41. require( ABSPATH . WPINC . '/class-wp-error.php' );
  42. require( ABSPATH . WPINC . '/plugin.php' );
  43. require( ABSPATH . WPINC . '/pomo/mo.php' );
  44. // WP_CLI: Early hooks
  45. Utils\replace_wp_die_handler();
  46. add_filter( 'wp_redirect', 'WP_CLI\\Utils\\wp_redirect_handler' );
  47. if ( defined( 'WP_INSTALLING' ) && is_multisite() ) {
  48. $values = array(
  49. 'ms_files_rewriting' => null,
  50. 'active_sitewide_plugins' => array(),
  51. '_site_transient_update_core' => null,
  52. '_site_transient_update_themes' => null,
  53. '_site_transient_update_plugins' => null,
  54. 'WPLANG' => '',
  55. );
  56. foreach ( $values as $key => $value ) {
  57. add_filter( "pre_site_option_$key", function () use ( $values, $key ) {
  58. return $values[ $key ];
  59. } );
  60. }
  61. unset( $values, $key, $value );
  62. }
  63. // Include the wpdb class and, if present, a db.php database drop-in.
  64. require_wp_db();
  65. // WP-CLI: Handle db error ourselves, instead of waiting for dead_db()
  66. global $wpdb;
  67. if ( !empty( $wpdb->error ) )
  68. wp_die( $wpdb->error );
  69. // Set the database table prefix and the format specifiers for database table columns.
  70. // @codingStandardsIgnoreStart
  71. $GLOBALS['table_prefix'] = $table_prefix;
  72. // @codingStandardsIgnoreEnd
  73. wp_set_wpdb_vars();
  74. // Start the WordPress object cache, or an external object cache if the drop-in is present.
  75. wp_start_object_cache();
  76. // WP-CLI: the APC cache is not available on the command-line, so bail, to prevent cache poisoning
  77. if ( $GLOBALS['_wp_using_ext_object_cache'] && class_exists( 'APC_Object_Cache' ) ) {
  78. WP_CLI::error( 'WP-CLI is not compatible with the APC object cache.' );
  79. }
  80. // Attach the default filters.
  81. require( ABSPATH . WPINC . '/default-filters.php' );
  82. // Initialize multisite if enabled.
  83. if ( is_multisite() ) {
  84. require( ABSPATH . WPINC . '/ms-blogs.php' );
  85. require( ABSPATH . WPINC . '/ms-settings.php' );
  86. } elseif ( ! defined( 'MULTISITE' ) ) {
  87. define( 'MULTISITE', false );
  88. }
  89. register_shutdown_function( 'shutdown_action_hook' );
  90. // Stop most of WordPress from being loaded if we just want the basics.
  91. if ( SHORTINIT )
  92. return false;
  93. // Load the L10n library.
  94. require_once( ABSPATH . WPINC . '/l10n.php' );
  95. // Run the installer if WordPress is not installed.
  96. Utils\wp_not_installed();
  97. // Load most of WordPress.
  98. require( ABSPATH . WPINC . '/class-wp-walker.php' );
  99. require( ABSPATH . WPINC . '/class-wp-ajax-response.php' );
  100. require( ABSPATH . WPINC . '/formatting.php' );
  101. require( ABSPATH . WPINC . '/capabilities.php' );
  102. require( ABSPATH . WPINC . '/query.php' );
  103. Utils\maybe_require( '3.7-alpha-25139', ABSPATH . WPINC . '/date.php' );
  104. require( ABSPATH . WPINC . '/theme.php' );
  105. require( ABSPATH . WPINC . '/class-wp-theme.php' );
  106. require( ABSPATH . WPINC . '/template.php' );
  107. require( ABSPATH . WPINC . '/user.php' );
  108. require( ABSPATH . WPINC . '/meta.php' );
  109. require( ABSPATH . WPINC . '/general-template.php' );
  110. require( ABSPATH . WPINC . '/link-template.php' );
  111. require( ABSPATH . WPINC . '/author-template.php' );
  112. require( ABSPATH . WPINC . '/post.php' );
  113. require( ABSPATH . WPINC . '/post-template.php' );
  114. Utils\maybe_require( '3.6-alpha-23451', ABSPATH . WPINC . '/revision.php' );
  115. Utils\maybe_require( '3.6-alpha-23451', ABSPATH . WPINC . '/post-formats.php' );
  116. require( ABSPATH . WPINC . '/post-thumbnail-template.php' );
  117. require( ABSPATH . WPINC . '/category.php' );
  118. require( ABSPATH . WPINC . '/category-template.php' );
  119. require( ABSPATH . WPINC . '/comment.php' );
  120. require( ABSPATH . WPINC . '/comment-template.php' );
  121. require( ABSPATH . WPINC . '/rewrite.php' );
  122. require( ABSPATH . WPINC . '/feed.php' );
  123. require( ABSPATH . WPINC . '/bookmark.php' );
  124. require( ABSPATH . WPINC . '/bookmark-template.php' );
  125. require( ABSPATH . WPINC . '/kses.php' );
  126. require( ABSPATH . WPINC . '/cron.php' );
  127. require( ABSPATH . WPINC . '/deprecated.php' );
  128. require( ABSPATH . WPINC . '/script-loader.php' );
  129. require( ABSPATH . WPINC . '/taxonomy.php' );
  130. require( ABSPATH . WPINC . '/update.php' );
  131. require( ABSPATH . WPINC . '/canonical.php' );
  132. require( ABSPATH . WPINC . '/shortcodes.php' );
  133. Utils\maybe_require( '3.5-alpha-22024', ABSPATH . WPINC . '/class-wp-embed.php' );
  134. require( ABSPATH . WPINC . '/media.php' );
  135. require( ABSPATH . WPINC . '/http.php' );
  136. require( ABSPATH . WPINC . '/class-http.php' );
  137. require( ABSPATH . WPINC . '/widgets.php' );
  138. require( ABSPATH . WPINC . '/nav-menu.php' );
  139. require( ABSPATH . WPINC . '/nav-menu-template.php' );
  140. require( ABSPATH . WPINC . '/admin-bar.php' );
  141. // Load multisite-specific files.
  142. if ( is_multisite() ) {
  143. require( ABSPATH . WPINC . '/ms-functions.php' );
  144. require( ABSPATH . WPINC . '/ms-default-filters.php' );
  145. require( ABSPATH . WPINC . '/ms-deprecated.php' );
  146. }
  147. // Define constants that rely on the API to obtain the default value.
  148. // Define must-use plugin directory constants, which may be overridden in the sunrise.php drop-in.
  149. wp_plugin_directory_constants();
  150. $symlinked_plugins_supported = function_exists( 'wp_register_plugin_realpath' );
  151. if ( $symlinked_plugins_supported ) {
  152. $GLOBALS['wp_plugin_paths'] = array();
  153. }
  154. // Load must-use plugins.
  155. foreach ( wp_get_mu_plugins() as $mu_plugin ) {
  156. include_once( $mu_plugin );
  157. }
  158. unset( $mu_plugin );
  159. // Load network activated plugins.
  160. if ( is_multisite() ) {
  161. foreach( wp_get_active_network_plugins() as $network_plugin ) {
  162. if ( !Utils\is_plugin_skipped( $network_plugin ) ) {
  163. if ( $symlinked_plugins_supported )
  164. wp_register_plugin_realpath( $network_plugin );
  165. include_once( $network_plugin );
  166. }
  167. }
  168. unset( $network_plugin );
  169. }
  170. do_action( 'muplugins_loaded' );
  171. if ( is_multisite() )
  172. ms_cookie_constants( );
  173. // Define constants after multisite is loaded. Cookie-related constants may be overridden in ms_network_cookies().
  174. wp_cookie_constants( );
  175. // Define and enforce our SSL constants
  176. wp_ssl_constants( );
  177. // Create common globals.
  178. // require( ABSPATH . WPINC . '/vars.php' );
  179. // Make taxonomies and posts available to plugins and themes.
  180. // @plugin authors: warning: these get registered again on the init hook.
  181. create_initial_taxonomies();
  182. create_initial_post_types();
  183. // Register the default theme directory root
  184. register_theme_directory( get_theme_root() );
  185. // Load active plugins.
  186. foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
  187. if ( !Utils\is_plugin_skipped( $plugin ) ) {
  188. if ( $symlinked_plugins_supported )
  189. wp_register_plugin_realpath( $plugin );
  190. include_once( $plugin );
  191. }
  192. }
  193. unset( $plugin, $symlinked_plugins_supported );
  194. // Load pluggable functions.
  195. require( ABSPATH . WPINC . '/pluggable.php' );
  196. require( ABSPATH . WPINC . '/pluggable-deprecated.php' );
  197. // Set internal encoding.
  198. wp_set_internal_encoding();
  199. // Run wp_cache_postload() if object cache is enabled and the function exists.
  200. if ( WP_CACHE && function_exists( 'wp_cache_postload' ) )
  201. wp_cache_postload();
  202. do_action( 'plugins_loaded' );
  203. // Define constants which affect functionality if not already defined.
  204. wp_functionality_constants( );
  205. // Add magic quotes and set up $_REQUEST ( $_GET + $_POST )
  206. wp_magic_quotes();
  207. do_action( 'sanitize_comment_cookies' );
  208. /**
  209. * WordPress Query object
  210. * @global object $wp_the_query
  211. * @since 2.0.0
  212. */
  213. $wp_the_query = new WP_Query();
  214. /**
  215. * Holds the reference to @see $wp_the_query
  216. * Use this global for WordPress queries
  217. * @global object $wp_query
  218. * @since 1.5.0
  219. */
  220. $wp_query = $wp_the_query;
  221. /**
  222. * Holds the WordPress Rewrite object for creating pretty URLs
  223. * @global object $wp_rewrite
  224. * @since 1.5.0
  225. */
  226. $GLOBALS['wp_rewrite'] = new WP_Rewrite();
  227. /**
  228. * WordPress Object
  229. * @global object $wp
  230. * @since 2.0.0
  231. */
  232. $wp = new WP();
  233. /**
  234. * WordPress Widget Factory Object
  235. * @global object $wp_widget_factory
  236. * @since 2.8.0
  237. */
  238. $GLOBALS['wp_widget_factory'] = new WP_Widget_Factory();
  239. /**
  240. * WordPress User Roles
  241. * @global object $wp_roles
  242. * @since 2.0.0
  243. */
  244. $GLOBALS['wp_roles'] = new WP_Roles();
  245. do_action( 'setup_theme' );
  246. // Define the template related constants.
  247. wp_templating_constants( );
  248. // Load the default text localization domain.
  249. load_default_textdomain();
  250. $locale = get_locale();
  251. $locale_file = WP_LANG_DIR . "/$locale.php";
  252. if ( ( 0 === validate_file( $locale ) ) && is_readable( $locale_file ) )
  253. require( $locale_file );
  254. unset( $locale_file );
  255. // Pull in locale data after loading text domain.
  256. require_once( ABSPATH . WPINC . '/locale.php' );
  257. /**
  258. * WordPress Locale object for loading locale domain date and various strings.
  259. * @global object $wp_locale
  260. * @since 2.1.0
  261. */
  262. $GLOBALS['wp_locale'] = new WP_Locale();
  263. // Load the functions for the active theme, for both parent and child theme if applicable.
  264. global $pagenow;
  265. if ( ! defined( 'WP_INSTALLING' ) || 'wp-activate.php' === $pagenow ) {
  266. if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists( STYLESHEETPATH . '/functions.php' ) )
  267. include( STYLESHEETPATH . '/functions.php' );
  268. if ( file_exists( TEMPLATEPATH . '/functions.php' ) )
  269. include( TEMPLATEPATH . '/functions.php' );
  270. }
  271. do_action( 'after_setup_theme' );
  272. // Set up current user.
  273. $wp->init();
  274. /**
  275. * Most of WP is loaded at this stage, and the user is authenticated. WP continues
  276. * to load on the init hook that follows (e.g. widgets), and many plugins instantiate
  277. * themselves on it for all sorts of reasons (e.g. they need a user, a taxonomy, etc.).
  278. *
  279. * If you wish to plug an action once WP is loaded, use the wp_loaded hook below.
  280. */
  281. do_action( 'init' );
  282. // Check site status
  283. # if ( is_multisite() ) { // WP-CLI
  284. if ( is_multisite() && !defined('WP_INSTALLING') ) {
  285. if ( true !== ( $file = ms_site_check() ) ) {
  286. require( $file );
  287. die();
  288. }
  289. unset($file);
  290. }
  291. /**
  292. * This hook is fired once WP, all plugins, and the theme are fully loaded and instantiated.
  293. *
  294. * AJAX requests should use wp-admin/admin-ajax.php. admin-ajax.php can handle requests for
  295. * users not logged in.
  296. *
  297. * @link http://codex.wordpress.org/AJAX_in_Plugins
  298. *
  299. * @since 3.0.0
  300. */
  301. do_action('wp_loaded');