|
1 <?php |
|
2 /** |
|
3 * WordPress core upgrade functionality. |
|
4 * |
|
5 * @package WordPress |
|
6 * @subpackage Administration |
|
7 * @since 2.7.0 |
|
8 */ |
|
9 |
|
10 /** |
|
11 * Stores files to be deleted. |
|
12 * |
|
13 * @since 2.7.0 |
|
14 * @global array $_old_files |
|
15 * @var array |
|
16 * @name $_old_files |
|
17 */ |
|
18 global $_old_files; |
|
19 |
|
20 $_old_files = array( |
|
21 'wp-admin/bookmarklet.php', |
|
22 'wp-admin/css/upload.css', |
|
23 'wp-admin/css/upload-rtl.css', |
|
24 'wp-admin/css/press-this-ie.css', |
|
25 'wp-admin/css/press-this-ie-rtl.css', |
|
26 'wp-admin/edit-form.php', |
|
27 'wp-admin/link-import.php', |
|
28 'wp-admin/images/box-bg-left.gif', |
|
29 'wp-admin/images/box-bg-right.gif', |
|
30 'wp-admin/images/box-bg.gif', |
|
31 'wp-admin/images/box-butt-left.gif', |
|
32 'wp-admin/images/box-butt-right.gif', |
|
33 'wp-admin/images/box-butt.gif', |
|
34 'wp-admin/images/box-head-left.gif', |
|
35 'wp-admin/images/box-head-right.gif', |
|
36 'wp-admin/images/box-head.gif', |
|
37 'wp-admin/images/heading-bg.gif', |
|
38 'wp-admin/images/login-bkg-bottom.gif', |
|
39 'wp-admin/images/login-bkg-tile.gif', |
|
40 'wp-admin/images/notice.gif', |
|
41 'wp-admin/images/toggle.gif', |
|
42 'wp-admin/images/comment-stalk-classic.gif', |
|
43 'wp-admin/images/comment-stalk-fresh.gif', |
|
44 'wp-admin/images/comment-stalk-rtl.gif', |
|
45 'wp-admin/images/comment-pill.gif', |
|
46 'wp-admin/images/del.png', |
|
47 'wp-admin/images/media-button-gallery.gif', |
|
48 'wp-admin/images/media-buttons.gif', |
|
49 'wp-admin/images/tail.gif', |
|
50 'wp-admin/images/gear.png', |
|
51 'wp-admin/images/tab.png', |
|
52 'wp-admin/images/postbox-bg.gif', |
|
53 'wp-admin/includes/upload.php', |
|
54 'wp-admin/js/dbx-admin-key.js', |
|
55 'wp-admin/js/link-cat.js', |
|
56 'wp-admin/js/forms.js', |
|
57 'wp-admin/js/upload.js', |
|
58 'wp-admin/profile-update.php', |
|
59 'wp-admin/templates.php', |
|
60 'wp-includes/images/audio.png', |
|
61 'wp-includes/images/css.png', |
|
62 'wp-includes/images/default.png', |
|
63 'wp-includes/images/doc.png', |
|
64 'wp-includes/images/exe.png', |
|
65 'wp-includes/images/html.png', |
|
66 'wp-includes/images/js.png', |
|
67 'wp-includes/images/pdf.png', |
|
68 'wp-includes/images/swf.png', |
|
69 'wp-includes/images/tar.png', |
|
70 'wp-includes/images/text.png', |
|
71 'wp-includes/images/video.png', |
|
72 'wp-includes/images/zip.png', |
|
73 'wp-includes/js/dbx.js', |
|
74 'wp-includes/js/fat.js', |
|
75 'wp-includes/js/list-manipulation.js', |
|
76 'wp-includes/js/jquery/jquery.dimensions.min.js', |
|
77 'wp-includes/js/tinymce/langs/en.js', |
|
78 'wp-includes/js/tinymce/plugins/autosave/editor_plugin_src.js', |
|
79 'wp-includes/js/tinymce/plugins/autosave/langs', |
|
80 'wp-includes/js/tinymce/plugins/directionality/images', |
|
81 'wp-includes/js/tinymce/plugins/directionality/langs', |
|
82 'wp-includes/js/tinymce/plugins/inlinepopups/css', |
|
83 'wp-includes/js/tinymce/plugins/inlinepopups/images', |
|
84 'wp-includes/js/tinymce/plugins/inlinepopups/jscripts', |
|
85 'wp-includes/js/tinymce/plugins/paste/images', |
|
86 'wp-includes/js/tinymce/plugins/paste/jscripts', |
|
87 'wp-includes/js/tinymce/plugins/paste/langs', |
|
88 'wp-includes/js/tinymce/plugins/spellchecker/classes/HttpClient.class.php', |
|
89 'wp-includes/js/tinymce/plugins/spellchecker/classes/TinyGoogleSpell.class.php', |
|
90 'wp-includes/js/tinymce/plugins/spellchecker/classes/TinyPspell.class.php', |
|
91 'wp-includes/js/tinymce/plugins/spellchecker/classes/TinyPspellShell.class.php', |
|
92 'wp-includes/js/tinymce/plugins/spellchecker/css/spellchecker.css', |
|
93 'wp-includes/js/tinymce/plugins/spellchecker/images', |
|
94 'wp-includes/js/tinymce/plugins/spellchecker/langs', |
|
95 'wp-includes/js/tinymce/plugins/spellchecker/tinyspell.php', |
|
96 'wp-includes/js/tinymce/plugins/wordpress/images', |
|
97 'wp-includes/js/tinymce/plugins/wordpress/langs', |
|
98 'wp-includes/js/tinymce/plugins/wordpress/popups.css', |
|
99 'wp-includes/js/tinymce/plugins/wordpress/wordpress.css', |
|
100 'wp-includes/js/tinymce/plugins/wphelp', |
|
101 'wp-includes/js/tinymce/themes/advanced/css', |
|
102 'wp-includes/js/tinymce/themes/advanced/images', |
|
103 'wp-includes/js/tinymce/themes/advanced/jscripts', |
|
104 'wp-includes/js/tinymce/themes/advanced/langs', |
|
105 'wp-includes/js/tinymce/tiny_mce_gzip.php', |
|
106 'wp-includes/js/wp-ajax.js', |
|
107 'wp-admin/admin-db.php', |
|
108 'wp-admin/cat.js', |
|
109 'wp-admin/categories.js', |
|
110 'wp-admin/custom-fields.js', |
|
111 'wp-admin/dbx-admin-key.js', |
|
112 'wp-admin/edit-comments.js', |
|
113 'wp-admin/install-rtl.css', |
|
114 'wp-admin/install.css', |
|
115 'wp-admin/upgrade-schema.php', |
|
116 'wp-admin/upload-functions.php', |
|
117 'wp-admin/upload-rtl.css', |
|
118 'wp-admin/upload.css', |
|
119 'wp-admin/upload.js', |
|
120 'wp-admin/users.js', |
|
121 'wp-admin/widgets-rtl.css', |
|
122 'wp-admin/widgets.css', |
|
123 'wp-admin/xfn.js', |
|
124 'wp-includes/js/tinymce/license.html', |
|
125 'wp-admin/cat-js.php', |
|
126 'wp-admin/edit-form-ajax-cat.php', |
|
127 'wp-admin/execute-pings.php', |
|
128 'wp-admin/import/b2.php', |
|
129 'wp-admin/import/btt.php', |
|
130 'wp-admin/import/jkw.php', |
|
131 'wp-admin/inline-uploading.php', |
|
132 'wp-admin/link-categories.php', |
|
133 'wp-admin/list-manipulation.js', |
|
134 'wp-admin/list-manipulation.php', |
|
135 'wp-includes/comment-functions.php', |
|
136 'wp-includes/feed-functions.php', |
|
137 'wp-includes/functions-compat.php', |
|
138 'wp-includes/functions-formatting.php', |
|
139 'wp-includes/functions-post.php', |
|
140 'wp-includes/js/dbx-key.js', |
|
141 'wp-includes/js/tinymce/plugins/autosave/langs/cs.js', |
|
142 'wp-includes/js/tinymce/plugins/autosave/langs/sv.js', |
|
143 'wp-includes/js/tinymce/themes/advanced/editor_template_src.js', |
|
144 'wp-includes/links.php', |
|
145 'wp-includes/pluggable-functions.php', |
|
146 'wp-includes/template-functions-author.php', |
|
147 'wp-includes/template-functions-category.php', |
|
148 'wp-includes/template-functions-general.php', |
|
149 'wp-includes/template-functions-links.php', |
|
150 'wp-includes/template-functions-post.php', |
|
151 'wp-includes/wp-l10n.php', |
|
152 'wp-admin/import-b2.php', |
|
153 'wp-admin/import-blogger.php', |
|
154 'wp-admin/import-greymatter.php', |
|
155 'wp-admin/import-livejournal.php', |
|
156 'wp-admin/import-mt.php', |
|
157 'wp-admin/import-rss.php', |
|
158 'wp-admin/import-textpattern.php', |
|
159 'wp-admin/quicktags.js', |
|
160 'wp-images/fade-butt.png', |
|
161 'wp-images/get-firefox.png', |
|
162 'wp-images/header-shadow.png', |
|
163 'wp-images/smilies', |
|
164 'wp-images/wp-small.png', |
|
165 'wp-images/wpminilogo.png', |
|
166 'wp.php' |
|
167 ); |
|
168 |
|
169 /** |
|
170 * Upgrade the core of WordPress. |
|
171 * |
|
172 * This will create a .maintenance file at the base of the WordPress directory |
|
173 * to ensure that people can not access the web site, when the files are being |
|
174 * copied to their locations. |
|
175 * |
|
176 * The files in the {@link $_old_files} list will be removed and the new files |
|
177 * copied from the zip file after the database is upgraded. |
|
178 * |
|
179 * The steps for the upgrader for after the new release is downloaded and |
|
180 * unzipped is: |
|
181 * 1. Test unzipped location for select files to ensure that unzipped worked. |
|
182 * 2. Create the .maintenance file in current WordPress base. |
|
183 * 3. Copy new WordPress directory over old WordPress files. |
|
184 * 4. Upgrade WordPress to new version. |
|
185 * 5. Delete new WordPress directory path. |
|
186 * 6. Delete .maintenance file. |
|
187 * 7. Remove old files. |
|
188 * 8. Delete 'update_core' option. |
|
189 * |
|
190 * There are several areas of failure. For instance if PHP times out before step |
|
191 * 6, then you will not be able to access any portion of your site. Also, since |
|
192 * the upgrade will not continue where it left off, you will not be able to |
|
193 * automatically remove old files and remove the 'update_core' option. This |
|
194 * isn't that bad. |
|
195 * |
|
196 * If the copy of the new WordPress over the old fails, then the worse is that |
|
197 * the new WordPress directory will remain. |
|
198 * |
|
199 * If it is assumed that every file will be copied over, including plugins and |
|
200 * themes, then if you edit the default theme, you should rename it, so that |
|
201 * your changes remain. |
|
202 * |
|
203 * @since 2.7.0 |
|
204 * |
|
205 * @param string $from New release unzipped path. |
|
206 * @param string $to Path to old WordPress installation. |
|
207 * @return WP_Error|null WP_Error on failure, null on success. |
|
208 */ |
|
209 function update_core($from, $to) { |
|
210 global $wp_filesystem, $_old_files; |
|
211 |
|
212 @set_time_limit( 300 ); |
|
213 |
|
214 // Sanity check the unzipped distribution |
|
215 apply_filters('update_feedback', __('Verifying the unpacked files')); |
|
216 if ( !$wp_filesystem->exists($from . '/wordpress/wp-settings.php') || !$wp_filesystem->exists($from . '/wordpress/wp-admin/admin.php') || |
|
217 !$wp_filesystem->exists($from . '/wordpress/wp-includes/functions.php') ) { |
|
218 $wp_filesystem->delete($from, true); |
|
219 return new WP_Error('insane_distro', __('The update could not be unpacked') ); |
|
220 } |
|
221 |
|
222 apply_filters('update_feedback', __('Installing the latest version')); |
|
223 |
|
224 // Create maintenance file to signal that we are upgrading |
|
225 $maintenance_string = '<?php $upgrading = ' . time() . '; ?>'; |
|
226 $maintenance_file = $to . '.maintenance'; |
|
227 $wp_filesystem->delete($maintenance_file); |
|
228 $wp_filesystem->put_contents($maintenance_file, $maintenance_string, FS_CHMOD_FILE); |
|
229 |
|
230 // Copy new versions of WP files into place. |
|
231 $result = copy_dir($from . '/wordpress', $to); |
|
232 if ( is_wp_error($result) ) { |
|
233 $wp_filesystem->delete($maintenance_file); |
|
234 $wp_filesystem->delete($from, true); |
|
235 return $result; |
|
236 } |
|
237 |
|
238 // Remove old files |
|
239 foreach ( $_old_files as $old_file ) { |
|
240 $old_file = $to . $old_file; |
|
241 if ( !$wp_filesystem->exists($old_file) ) |
|
242 continue; |
|
243 $wp_filesystem->delete($old_file, true); |
|
244 } |
|
245 |
|
246 // Upgrade DB with separate request |
|
247 apply_filters('update_feedback', __('Upgrading database')); |
|
248 $db_upgrade_url = admin_url('upgrade.php?step=upgrade_db'); |
|
249 wp_remote_post($db_upgrade_url, array('timeout' => 60)); |
|
250 |
|
251 // Remove working directory |
|
252 $wp_filesystem->delete($from, true); |
|
253 |
|
254 // Force refresh of update information |
|
255 if ( function_exists('delete_transient') ) |
|
256 delete_transient('update_core'); |
|
257 else |
|
258 delete_option('update_core'); |
|
259 |
|
260 // Remove maintenance file, we're done. |
|
261 $wp_filesystem->delete($maintenance_file); |
|
262 } |
|
263 |
|
264 ?> |