Projects : mp-wp : mp-wp_genesis
1 | <?php |
2 | /** |
3 | * Update Core administration panel. |
4 | * |
5 | * @package WordPress |
6 | * @subpackage Administration |
7 | */ |
8 | |
9 | /** WordPress Administration Bootstrap */ |
10 | require_once('admin.php'); |
11 | |
12 | if ( ! current_user_can('update_plugins') ) |
13 | wp_die(__('You do not have sufficient permissions to update plugins for this blog.')); |
14 | |
15 | function list_core_update( $update ) { |
16 | $version_string = 'en_US' == $update->locale ? |
17 | $update->current : sprintf("%s–<strong>%s</strong>", $update->current, $update->locale); |
18 | $current = false; |
19 | if ( !isset($update->response) || 'latest' == $update->response ) |
20 | $current = true; |
21 | $submit = __('Upgrade Automatically'); |
22 | $form_action = 'update-core.php?action=do-core-upgrade'; |
23 | if ( 'development' == $update->response ) { |
24 | $message = __('You are using a development version of WordPress. You can upgrade to the latest nightly build automatically or download the nightly build and install it manually:'); |
25 | $download = __('Download nightly build'); |
26 | } else { |
27 | if ( $current ) { |
28 | $message = sprintf(__('You have the latest version of WordPress. You do not need to upgrade. However, if you want to re-install version %s, you can do so automatically or download the package and re-install manually:'), $version_string); |
29 | $submit = __('Re-install Automatically'); |
30 | $form_action = 'update-core.php?action=do-core-reinstall'; |
31 | } else { |
32 | $message = sprintf(__('You can upgrade to version %s automatically or download the package and install it manually:'), $version_string); |
33 | } |
34 | $download = sprintf(__('Download %s'), $version_string); |
35 | } |
36 | |
37 | echo '<p>'; |
38 | echo $message; |
39 | echo '</p>'; |
40 | echo '<form method="post" action="' . $form_action . '" name="upgrade" class="upgrade">'; |
41 | wp_nonce_field('upgrade-core'); |
42 | echo '<p>'; |
43 | echo '<input id="upgrade" class="button" type="submit" value="' . $submit . '" name="upgrade" /> '; |
44 | echo '<input name="version" value="'.$update->current.'" type="hidden"/>'; |
45 | echo '<input name="locale" value="'.$update->locale.'" type="hidden"/>'; |
46 | echo '<a href="' . $update->package . '" class="button">' . $download . '</a> '; |
47 | if ( 'en_US' != $update->locale ) |
48 | if ( !isset( $update->dismissed ) || !$update->dismissed ) |
49 | echo '<input id="dismiss" class="button" type="submit" value="' . attribute_escape(__('Hide this update')) . '" name="dismiss" />'; |
50 | else |
51 | echo '<input id="undismiss" class="button" type="submit" value="' . attribute_escape(__('Bring back this update')) . '" name="undismiss" />'; |
52 | echo '</p>'; |
53 | echo '</form>'; |
54 | |
55 | } |
56 | |
57 | function dismissed_updates() { |
58 | $dismissed = get_core_updates( array( 'dismissed' => true, 'available' => false ) ); |
59 | if ( $dismissed ) { |
60 | |
61 | $show_text = js_escape(__('Show hidden updates')); |
62 | $hide_text = js_escape(__('Hide hidden updates')); |
63 | ?> |
64 | <script type="text/javascript"> |
65 | |
66 | jQuery(function($) { |
67 | $('dismissed-updates').show(); |
68 | $('#show-dismissed').toggle(function(){$(this).text('<?php echo $hide_text; ?>');}, function() {$(this).text('<?php echo $show_text; ?>')}); |
69 | $('#show-dismissed').click(function() { $('#dismissed-updates').toggle('slow');}); |
70 | }); |
71 | </script> |
72 | <?php |
73 | echo '<p class="hide-if-no-js"><a id="show-dismissed" href="#">'.__('Show hidden updates').'</a></p>'; |
74 | echo '<ul id="dismissed-updates" class="core-updates dismissed">'; |
75 | foreach( (array) $dismissed as $update) { |
76 | echo '<li>'; |
77 | list_core_update( $update ); |
78 | echo '</li>'; |
79 | } |
80 | echo '</ul>'; |
81 | } |
82 | } |
83 | |
84 | /** |
85 | * Display upgrade WordPress for downloading latest or upgrading automatically form. |
86 | * |
87 | * @since 2.7 |
88 | * |
89 | * @return null |
90 | */ |
91 | function core_upgrade_preamble() { |
92 | $updates = get_core_updates(); |
93 | ?> |
94 | <div class="wrap"> |
95 | <?php screen_icon(); ?> |
96 | <h2><?php _e('Upgrade WordPress'); ?></h2> |
97 | <?php |
98 | if ( !isset($updates[0]->response) || 'latest' == $updates[0]->response ) { |
99 | echo '<h3>'; |
100 | _e('You have the latest version of WordPress. You do not need to upgrade'); |
101 | echo '</h3>'; |
102 | } else { |
103 | echo '<div class="updated fade"><p>'; |
104 | _e('<strong>Important:</strong> before upgrading, please <a href="http://codex.wordpress.org/WordPress_Backups">backup your database and files</a>.'); |
105 | echo '</p></div>'; |
106 | |
107 | echo '<h3 class="response">'; |
108 | _e( 'There is a new version of WordPress available for upgrade' ); |
109 | echo '</h3>'; |
110 | } |
111 | |
112 | echo '<ul class="core-updates">'; |
113 | $alternate = true; |
114 | foreach( (array) $updates as $update ) { |
115 | $class = $alternate? ' class="alternate"' : ''; |
116 | $alternate = !$alternate; |
117 | echo "<li $class>"; |
118 | list_core_update( $update ); |
119 | echo '</li>'; |
120 | } |
121 | echo '</ul>'; |
122 | dismissed_updates(); |
123 | echo '</div>'; |
124 | } |
125 | |
126 | |
127 | /** |
128 | * Upgrade WordPress core display. |
129 | * |
130 | * @since 2.7 |
131 | * |
132 | * @return null |
133 | */ |
134 | function do_core_upgrade( $reinstall = false ) { |
135 | global $wp_filesystem; |
136 | |
137 | $url = wp_nonce_url('update-core.php?action=do-core-upgrade', 'upgrade-core'); |
138 | if ( false === ($credentials = request_filesystem_credentials($url)) ) |
139 | return; |
140 | |
141 | $version = isset( $_POST['version'] )? $_POST['version'] : false; |
142 | $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US'; |
143 | $update = find_core_update( $version, $locale ); |
144 | if ( !$update ) |
145 | return; |
146 | |
147 | |
148 | if ( ! WP_Filesystem($credentials) ) { |
149 | request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again |
150 | return; |
151 | } |
152 | ?> |
153 | <div class="wrap"> |
154 | <?php screen_icon(); ?> |
155 | <h2><?php _e('Upgrade WordPress'); ?></h2> |
156 | <?php |
157 | if ( $wp_filesystem->errors->get_error_code() ) { |
158 | foreach ( $wp_filesystem->errors->get_error_messages() as $message ) |
159 | show_message($message); |
160 | echo '</div>'; |
161 | return; |
162 | } |
163 | |
164 | if ( $reinstall ) |
165 | $update->response = 'reinstall'; |
166 | |
167 | $result = wp_update_core($update, 'show_message'); |
168 | |
169 | if ( is_wp_error($result) ) { |
170 | show_message($result); |
171 | if ('up_to_date' != $result->get_error_code() ) |
172 | show_message( __('Installation Failed') ); |
173 | } else { |
174 | show_message( __('WordPress upgraded successfully') ); |
175 | } |
176 | echo '</div>'; |
177 | } |
178 | |
179 | function do_dismiss_core_update() { |
180 | $version = isset( $_POST['version'] )? $_POST['version'] : false; |
181 | $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US'; |
182 | $update = find_core_update( $version, $locale ); |
183 | if ( !$update ) |
184 | return; |
185 | dismiss_core_update( $update ); |
186 | wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') ); |
187 | } |
188 | |
189 | function do_undismiss_core_update() { |
190 | $version = isset( $_POST['version'] )? $_POST['version'] : false; |
191 | $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US'; |
192 | $update = find_core_update( $version, $locale ); |
193 | if ( !$update ) |
194 | return; |
195 | undismiss_core_update( $version, $locale ); |
196 | wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') ); |
197 | } |
198 | |
199 | $action = isset($_GET['action']) ? $_GET['action'] : 'upgrade-core'; |
200 | |
201 | if ( 'upgrade-core' == $action ) { |
202 | $title = __('Upgrade WordPress'); |
203 | $parent_file = 'tools.php'; |
204 | require_once('admin-header.php'); |
205 | core_upgrade_preamble(); |
206 | include('admin-footer.php'); |
207 | } elseif ( 'do-core-upgrade' == $action || 'do-core-reinstall' == $action ) { |
208 | check_admin_referer('upgrade-core'); |
209 | $title = __('Upgrade WordPress'); |
210 | $parent_file = 'tools.php'; |
211 | // do the (un)dismiss actions before headers, |
212 | // so that they can redirect |
213 | if ( isset( $_POST['dismiss'] ) ) |
214 | do_dismiss_core_update(); |
215 | elseif ( isset( $_POST['undismiss'] ) ) |
216 | do_undismiss_core_update(); |
217 | require_once('admin-header.php'); |
218 | if ( 'do-core-reinstall' == $action ) |
219 | $reinstall = true; |
220 | else |
221 | $reinstall = false; |
222 | if ( isset( $_POST['upgrade'] ) ) |
223 | do_core_upgrade($reinstall); |
224 | include('admin-footer.php'); |
225 | |
226 | }?> |