Skip to content
Newer
Older
100644 270 lines (218 sloc) 9.24 KB
0bc8613 b2config.php replaced with wp-config.sample.php
mikelittle authored
1 <?php
2919fe2 That last thing didn't work at all.
matt authored
2 // Turn register globals off
eb4e2a2 Prefix unregister_GLOBALS to avoid name collisions. Props westi. fixe…
ryan authored
3 function wp_unregister_GLOBALS() {
dce5220 Typos and more secure unsetting. Hat tip: Stefen Esser
matt authored
4 if ( !ini_get('register_globals') )
5 return;
6
7 if ( isset($_REQUEST['GLOBALS']) )
79d9f41 Use die() not wp_die(). Props AlanJCastonguay. fixes #3357
ryan authored
8 die('GLOBALS overwrite attempt detected');
dce5220 Typos and more secure unsetting. Hat tip: Stefen Esser
matt authored
9
10 // Variables that shouldn't be unset
11 $noUnset = array('GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix');
dd202ce Death to trailing tabs. Props Mark J. fixes #2405
ryan authored
12
dce5220 Typos and more secure unsetting. Hat tip: Stefen Esser
matt authored
13 $input = array_merge($_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array());
14 foreach ( $input as $k => $v )
9323d39 Zend hash del key or index fix. PRops MarkJaquith.
ryan authored
15 if ( !in_array($k, $noUnset) && isset($GLOBALS[$k]) ) {
16 $GLOBALS[$k] = NULL;
dce5220 Typos and more secure unsetting. Hat tip: Stefen Esser
matt authored
17 unset($GLOBALS[$k]);
9323d39 Zend hash del key or index fix. PRops MarkJaquith.
ryan authored
18 }
2919fe2 That last thing didn't work at all.
matt authored
19 }
877e6a7 Turn register globals off. Hat tip: Christian Schmidt
matt authored
20
eb4e2a2 Prefix unregister_GLOBALS to avoid name collisions. Props westi. fixe…
ryan authored
21 wp_unregister_GLOBALS();
dce5220 Typos and more secure unsetting. Hat tip: Stefen Esser
matt authored
22
23 unset( $wp_filter, $cache_userdata, $cache_lastcommentmodified, $cache_lastpostdate, $cache_settings, $category_cache, $cache_categories );
376ec4d Tweak
matt authored
24
85723b8 Object caching, round one.
ryan authored
25 if ( ! isset($blog_id) )
26 $blog_id = 1;
27
a18a23e Work around IIS' lack of REQUEST_URI
saxmatt authored
28 // Fix for IIS, which doesn't set REQUEST_URI
40a7d9d Fixes #1488
matt authored
29 if ( empty( $_SERVER['REQUEST_URI'] ) ) {
30 $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME']; // Does this work under CGI?
dd202ce Death to trailing tabs. Props Mark J. fixes #2405
ryan authored
31
720316d Do not touch REQUEST_URI if it is already set by the server.
rboren authored
32 // Append the query string if it exists and isn't null
33 if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) {
34 $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
35 }
12b4069 Fix REQUEST_URI construction for IIS. Bug 389. Patch from Dennis Will…
rboren authored
36 }
a18a23e Work around IIS' lack of REQUEST_URI
saxmatt authored
37
c50e7da Fixes #1591 (again)
matt authored
38 // Fix for PHP as CGI hosts that set SCRIPT_FILENAME to something ending in php.cgi for all requests
c1ed565 Check if SCRIPT_FILENAME is set to avoid warnings. fixes #2227
ryan authored
39 if ( isset($_SERVER['SCRIPT_FILENAME']) && ( strpos($_SERVER['SCRIPT_FILENAME'], 'php.cgi') == strlen($_SERVER['SCRIPT_FILENAME']) - 7 ) )
c50e7da Fixes #1591 (again)
matt authored
40 $_SERVER['SCRIPT_FILENAME'] = $_SERVER['PATH_TRANSLATED'];
41
885ee8f This should fix permalinks, but may break the PHP as CGI funkiness again
matt authored
42 // Fix for Dreamhost and other PHP as CGI hosts
43 if ( strstr( $_SERVER['SCRIPT_NAME'], 'php.cgi' ) )
c50e7da Fixes #1591 (again)
matt authored
44 unset($_SERVER['PATH_INFO']);
45
38f4fca Move PHP_SELF setup to wp-settings.php. #2153
ryan authored
46 // Fix empty PHP_SELF
47 $PHP_SELF = $_SERVER['PHP_SELF'];
48 if ( empty($PHP_SELF) )
49 $_SERVER['PHP_SELF'] = $PHP_SELF = preg_replace("/(\?.*)?$/",'',$_SERVER["REQUEST_URI"]);
885ee8f This should fix permalinks, but may break the PHP as CGI funkiness again
matt authored
50
da4a0d9 Fix for empty plugin strings, class include moved for timing.
saxmatt authored
51 if ( !(phpversion() >= '4.1') )
fa1ec4e Don't wp_die() before functions.php is loaded.
ryan authored
52 die( 'Your server is running PHP version ' . phpversion() . ' but WordPress requires at least 4.1' );
da4a0d9 Fix for empty plugin strings, class include moved for timing.
saxmatt authored
53
172bfb8 Don't enforce presence of mysql system if custom DB class is being us…
ryan authored
54 if ( !extension_loaded('mysql') && !file_exists(ABSPATH . 'wp-content/db.php') )
fa1ec4e Don't wp_die() before functions.php is loaded.
ryan authored
55 die( 'Your PHP installation appears to be missing the MySQL which is required for WordPress.' );
0d040b3 Sanity check mysql.
saxmatt authored
56
551e52f Code cleanup and some fixes from the WP Japan folks.
saxmatt authored
57 function timer_start() {
58 global $timestart;
59 $mtime = explode(' ', microtime() );
60 $mtime = $mtime[1] + $mtime[0];
61 $timestart = $mtime;
62 return true;
63 }
0f7bb42 timer_stop() wanted to be near timer_start().
ryan authored
64
65 function timer_stop($display = 0, $precision = 3) { //if called like timer_stop(1), will echo $timetotal
66 global $timestart, $timeend;
67 $mtime = microtime();
68 $mtime = explode(' ',$mtime);
69 $mtime = $mtime[1] + $mtime[0];
70 $timeend = $mtime;
71 $timetotal = $timeend-$timestart;
a9d23d4 allow timer_stop() to use number_format() when returning. Props mdawa…
markjaquith authored
72 $r = number_format($timetotal, $precision);
0f7bb42 timer_stop() wanted to be near timer_start().
ryan authored
73 if ( $display )
a9d23d4 allow timer_stop() to use number_format() when returning. Props mdawa…
markjaquith authored
74 echo $r;
75 return $r;
0f7bb42 timer_stop() wanted to be near timer_start().
ryan authored
76 }
551e52f Code cleanup and some fixes from the WP Japan folks.
saxmatt authored
77 timer_start();
da4a0d9 Fix for empty plugin strings, class include moved for timing.
saxmatt authored
78
9b09572 Turn down error reporting.
saxmatt authored
79 // Change to E_ALL for development/debugging
80 error_reporting(E_ALL ^ E_NOTICE);
81
70a449d Allow for plugins to kick in before everything if define in wp-config
saxmatt authored
82 // For an advanced caching plugin to use, static because you would only want one
83 if ( defined('WP_CACHE') )
84 require (ABSPATH . 'wp-content/advanced-cache.php');
85
edc7d7c Installation cleanup.
saxmatt authored
86 define('WPINC', 'wp-includes');
54d7ccb make /languages/ directory default to /wp-content/languages/ with fal…
markjaquith authored
87
88 if ( !defined('LANGDIR') ) {
89 if ( file_exists(ABSPATH . 'wp-content/languages') && @is_dir(ABSPATH . 'wp-content/languages') )
90 define('LANGDIR', 'wp-content/languages'); // no leading slash, no trailing slash
91 else
92 define('LANGDIR', WPINC . '/languages'); // no leading slash, no trailing slash
93 }
94
7a03234 Turn hard-coded paths to defines. Pull gettext includes int wp-settin…
ryan authored
95 if ( !defined('PLUGINDIR') )
96 define('PLUGINDIR', 'wp-content/plugins'); // no leading slash, no trailing slash
c84524f db.php instead of wp-db.php for pluggable DB load. #2721
ryan authored
97 if ( file_exists(ABSPATH . 'wp-content/db.php') )
98 require (ABSPATH . 'wp-content/db.php');
c01753a Allow pluggable wp-db. #2721
ryan authored
99 else
100 require_once (ABSPATH . WPINC . '/wp-db.php');
edc7d7c Installation cleanup.
saxmatt authored
101
71a2674 Use $wpdb->prefix when defining table names
markjaquith authored
102 // $table_prefix is deprecated as of 2.1
103 $wpdb->prefix = $table_prefix;
104
cde68f9 Exit gracefully with a warning if the table_prefix uses disallowed ch…
markjaquith authored
105 if ( preg_match('|[^a-z0-9_]|i', $wpdb->prefix) && !file_exists(ABSPATH . 'wp-content/db.php') )
f717f85 Don't gettext before l10n bits are loaded. Props nbachiyski. fixes #3590
ryan authored
106 die("<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores.");
cde68f9 Exit gracefully with a warning if the table_prefix uses disallowed ch…
markjaquith authored
107
25ae03e Giant commit, sorry mailing list people. Move all table names to new …
saxmatt authored
108 // Table names
71a2674 Use $wpdb->prefix when defining table names
markjaquith authored
109 $wpdb->posts = $wpdb->prefix . 'posts';
110 $wpdb->users = $wpdb->prefix . 'users';
111 $wpdb->categories = $wpdb->prefix . 'categories';
112 $wpdb->post2cat = $wpdb->prefix . 'post2cat';
113 $wpdb->comments = $wpdb->prefix . 'comments';
114 $wpdb->link2cat = $wpdb->prefix . 'link2cat';
115 $wpdb->links = $wpdb->prefix . 'links';
116 $wpdb->options = $wpdb->prefix . 'options';
117 $wpdb->postmeta = $wpdb->prefix . 'postmeta';
118 $wpdb->usermeta = $wpdb->prefix . 'usermeta';
233afca Drafts clean up.
matt authored
119
2765f58 Allow for custom user table. If rewriting user functions need to incl…
saxmatt authored
120 if ( defined('CUSTOM_USER_TABLE') )
121 $wpdb->users = CUSTOM_USER_TABLE;
de9cc8b More user updates
matt authored
122 if ( defined('CUSTOM_USER_META_TABLE') )
123 $wpdb->usermeta = CUSTOM_USER_META_TABLE;
85723b8 Object caching, round one.
ryan authored
124
b1aee5c Another step toward removing old table vars, this is why we should be…
matt authored
125 // To be removed in 2.2
126 $tableposts = $tableusers = $tablecategories = $tablepost2cat = $tablecomments = $tablelink2cat = $tablelinks = $tablelinkcategories = $tableoptions = $tablepostmeta = '';
8fff608 Sometimes we need to keep things around.
saxmatt authored
127
85723b8 Object caching, round one.
ryan authored
128 if ( file_exists(ABSPATH . 'wp-content/object-cache.php') )
129 require (ABSPATH . 'wp-content/object-cache.php');
130 else
131 require (ABSPATH . WPINC . '/cache.php');
132
133 wp_cache_init();
134
9dc65ab Cleaning up some includes.
saxmatt authored
135 require (ABSPATH . WPINC . '/functions.php');
6d7717e Move plugin API to plugin.php. #2525
ryan authored
136 require (ABSPATH . WPINC . '/plugin.php');
81e7d92 Some filter action and cleanup
saxmatt authored
137 require (ABSPATH . WPINC . '/default-filters.php');
acc5602 Always load gettext.
ryan authored
138 include_once(ABSPATH . WPINC . '/streams.php');
139 include_once(ABSPATH . WPINC . '/gettext.php');
62927ab Remove wp- prefix from wp-l10n.php
ryan authored
140 require_once (ABSPATH . WPINC . '/l10n.php');
1bd4057 Bug fixes
saxmatt authored
141
8a751c5 Pluggable install functions. fixes #2616
ryan authored
142 if ( !is_blog_installed() && (!strstr($_SERVER['PHP_SELF'], 'install.php') && !defined('WP_INSTALLING')) ) {
ca2815f If we're already in wp-admin don't recursive link
saxmatt authored
143 if ( strstr($_SERVER['PHP_SELF'], 'wp-admin') )
144 $link = 'install.php';
145 else
146 $link = 'wp-admin/install.php';
f717f85 Don't gettext before l10n bits are loaded. Props nbachiyski. fixes #3590
ryan authored
147 wp_die(sprintf("It doesn't look like you've installed WP yet. Try running <a href='%s'>install.php</a>.", $link));
ca2815f If we're already in wp-admin don't recursive link
saxmatt authored
148 }
1bd4057 Bug fixes
saxmatt authored
149
c93efa8 Include file renames. #2525
ryan authored
150 require (ABSPATH . WPINC . '/formatting.php');
a6ade4a Role/capability system. Round one. Props: Owen Winkler
ryan authored
151 require (ABSPATH . WPINC . '/capabilities.php');
da4a0d9 Fix for empty plugin strings, class include moved for timing.
saxmatt authored
152 require (ABSPATH . WPINC . '/classes.php');
9303053 Move WP_Query and its wrapper functions to query.php. #2525
ryan authored
153 require (ABSPATH . WPINC . '/query.php');
40b2e61 Move theme functions to theme.php. #2525
ryan authored
154 require (ABSPATH . WPINC . '/theme.php');
c56e62f Move user functions to user.php. Relocate more post functions to post…
ryan authored
155 require (ABSPATH . WPINC . '/user.php');
c93efa8 Include file renames. #2525
ryan authored
156 require (ABSPATH . WPINC . '/general-template.php');
157 require (ABSPATH . WPINC . '/link-template.php');
c56e62f Move user functions to user.php. Relocate more post functions to post…
ryan authored
158 require (ABSPATH . WPINC . '/author-template.php');
3c8ed76 Reworg post/page/attachment functions. #2525
ryan authored
159 require (ABSPATH . WPINC . '/post.php');
160 require (ABSPATH . WPINC . '/post-template.php');
0f5dc0f Reorg category functions. #2525
ryan authored
161 require (ABSPATH . WPINC . '/category.php');
162 require (ABSPATH . WPINC . '/category-template.php');
6027cfa Reorg comment functions. #2525
ryan authored
163 require (ABSPATH . WPINC . '/comment.php');
164 require (ABSPATH . WPINC . '/comment-template.php');
6970a75 Rewrite API additions and improvements from David House. #2433
ryan authored
165 require (ABSPATH . WPINC . '/rewrite.php');
c93efa8 Include file renames. #2525
ryan authored
166 require (ABSPATH . WPINC . '/feed.php');
19ea5fb Reorg bookmark functions. #2525
ryan authored
167 require (ABSPATH . WPINC . '/bookmark.php');
168 require (ABSPATH . WPINC . '/bookmark-template.php');
9dc65ab Cleaning up some includes.
saxmatt authored
169 require (ABSPATH . WPINC . '/kses.php');
fb1e531 Cron improvements from masquerade. #2425
ryan authored
170 require (ABSPATH . WPINC . '/cron.php');
2520d8e Include cleanups
saxmatt authored
171 require (ABSPATH . WPINC . '/version.php');
ca92bb4 Move deprecated functions to deprecated.php. #2520
ryan authored
172 require (ABSPATH . WPINC . '/deprecated.php');
4d49e98 Script loader from mdawaffe. #2701
ryan authored
173 require (ABSPATH . WPINC . '/script-loader.php');
da4a0d9 Fix for empty plugin strings, class include moved for timing.
saxmatt authored
174
16aa6ae New import system. Very rough draft.
ryan authored
175 if (!strstr($_SERVER['PHP_SELF'], 'install.php')) :
a2342f1 Define COOKIEHASH and new get_profile function. TODO: re-org function…
saxmatt authored
176 // Used to guarantee unique hash cookies
911d3a1 Remove comment. fixes #3210
ryan authored
177 $cookiehash = md5(get_option('siteurl'));
a2342f1 Define COOKIEHASH and new get_profile function. TODO: re-org function…
saxmatt authored
178 define('COOKIEHASH', $cookiehash);
179 endif;
5c97b54 Smilie fix from Jaykul, changed fool's siteurl fix to use faster preg…
saxmatt authored
180
41afea2 Let advanced users override cookies.
matt authored
181 if ( !defined('USER_COOKIE') )
182 define('USER_COOKIE', 'wordpressuser_'. COOKIEHASH);
183 if ( !defined('PASS_COOKIE') )
184 define('PASS_COOKIE', 'wordpresspass_'. COOKIEHASH);
185 if ( !defined('COOKIEPATH') )
849a0d2 Use get_option instead of get_settings. Just 'cause.
ryan authored
186 define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home') . '/' ) );
41afea2 Let advanced users override cookies.
matt authored
187 if ( !defined('SITECOOKIEPATH') )
849a0d2 Use get_option instead of get_settings. Just 'cause.
ryan authored
188 define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('siteurl') . '/' ) );
41afea2 Let advanced users override cookies.
matt authored
189 if ( !defined('COOKIE_DOMAIN') )
190 define('COOKIE_DOMAIN', false);
191
9dc65ab Cleaning up some includes.
saxmatt authored
192 require (ABSPATH . WPINC . '/vars.php');
edc7d7c Installation cleanup.
saxmatt authored
193
c26991b Move hack file include.
saxmatt authored
194 // Check for hacks file if the option is enabled
849a0d2 Use get_option instead of get_settings. Just 'cause.
ryan authored
195 if (get_option('hack_file')) {
c26991b Move hack file include.
saxmatt authored
196 if (file_exists(ABSPATH . '/my-hacks.php'))
197 require(ABSPATH . '/my-hacks.php');
198 }
199
849a0d2 Use get_option instead of get_settings. Just 'cause.
ryan authored
200 if ( get_option('active_plugins') ) {
201 $current_plugins = get_option('active_plugins');
11f5bb3 Add a precautionary is_array() check around the plugin loading loop. h…
ryan authored
202 if ( is_array($current_plugins) ) {
203 foreach ($current_plugins as $plugin) {
204 if ('' != $plugin && file_exists(ABSPATH . 'wp-content/plugins/' . $plugin))
205 include_once(ABSPATH . 'wp-content/plugins/' . $plugin);
206 }
e733249 Functional plugin implementation.
saxmatt authored
207 }
208 }
1127059 shutdown action hook.
saxmatt authored
209
c93efa8 Include file renames. #2525
ryan authored
210 require (ABSPATH . WPINC . '/pluggable.php');
08b02d9 Move plugin replacebale functions to pluggable-functions.php. http://…
ryan authored
211
70a449d Allow for plugins to kick in before everything if define in wp-config
saxmatt authored
212 if ( defined('WP_CACHE') && function_exists('wp_cache_postload') )
213 wp_cache_postload();
214
215 do_action('plugins_loaded');
216
91efba1 Use wpdb->escape instead of addslashes to prepare DB bound data.
ryan authored
217 // If already slashed, strip.
218 if ( get_magic_quotes_gpc() ) {
6cbb6fe Stripslashes doesn't work on arrays. Add stripslashes_deep(). Props: …
ryan authored
219 $_GET = stripslashes_deep($_GET );
220 $_POST = stripslashes_deep($_POST );
221 $_COOKIE = stripslashes_deep($_COOKIE);
65bbec7 Comments refactoring and cleanup
saxmatt authored
222 }
223
91efba1 Use wpdb->escape instead of addslashes to prepare DB bound data.
ryan authored
224 // Escape with wpdb.
225 $_GET = add_magic_quotes($_GET );
226 $_POST = add_magic_quotes($_POST );
227 $_COOKIE = add_magic_quotes($_COOKIE);
228 $_SERVER = add_magic_quotes($_SERVER);
229
1034767 wp_get_current_commenter()
ryan authored
230 do_action('sanitize_comment_cookies');
231
22bee1c Preserve the original query object as wp_the_query so that it's not s…
ryan authored
232 $wp_the_query =& new WP_Query();
233 $wp_query =& $wp_the_query;
234 $wp_rewrite =& new WP_Rewrite();
235 $wp =& new WP();
1baf503 Break blog header up into functional chunks. Stick it all in a WP cla…
ryan authored
236
978fc18 Tweak theme validation.
ryan authored
237 validate_current_theme();
98aa7f5 Rearrange load order. Init classes before loading the text domain and…
ryan authored
238 define('TEMPLATEPATH', get_template_directory());
b55b6aa Allow stylesheet only themes to provide functions.php. Props skeltoac…
ryan authored
239 define('STYLESHEETPATH', get_stylesheet_directory());
98aa7f5 Rearrange load order. Init classes before loading the text domain and…
ryan authored
240
241 // Load the default text localization domain.
242 load_default_textdomain();
243
3e26469 Load locale specific php code in global context. fixes #3488
ryan authored
244 $locale = get_locale();
245 $locale_file = ABSPATH . LANGDIR . "/$locale.php";
246 if ( is_readable($locale_file) )
247 require_once($locale_file);
248
98aa7f5 Rearrange load order. Init classes before loading the text domain and…
ryan authored
249 // Pull in locale data after loading text domain.
250 require_once(ABSPATH . WPINC . '/locale.php');
251
92421de Ref more singletons.
ryan authored
252 $wp_locale =& new WP_Locale();
3d2347a WP_Locale. Props Sewar. fixes #2568
ryan authored
253
c369310 Better support for theme plugins. add_theme_page() and active theme f…
ryan authored
254 // Load functions for active theme.
b55b6aa Allow stylesheet only themes to provide functions.php. Props skeltoac…
ryan authored
255 if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists(STYLESHEETPATH . '/functions.php') )
256 include(STYLESHEETPATH . '/functions.php');
257 if ( file_exists(TEMPLATEPATH . '/functions.php') )
258 include(TEMPLATEPATH . '/functions.php');
c369310 Better support for theme plugins. add_theme_page() and active theme f…
ryan authored
259
98aa7f5 Rearrange load order. Init classes before loading the text domain and…
ryan authored
260 function shutdown_action_hook() {
261 do_action('shutdown');
84da5fc Save cache after the shutdown hook runs. fixes #2232
ryan authored
262 wp_cache_close();
98aa7f5 Rearrange load order. Init classes before loading the text domain and…
ryan authored
263 }
264 register_shutdown_function('shutdown_action_hook');
265
1baf503 Break blog header up into functional chunks. Stick it all in a WP cla…
ryan authored
266 // Everything is loaded and initialized.
9838608 Allow multiple args to be passed to apply_filters and do_action. Move…
rboren authored
267 do_action('init');
06a0fc3 Formatting
matt authored
268
4d49e98 Script loader from mdawaffe. #2701
ryan authored
269 ?>
Something went wrong with that request. Please try again.