3 require_once('admin.php');
5 if ( !current_user_can('edit_plugins') )
6 wp_die('<p>'.__('You do not have sufficient permissions to update plugins for this blog.').'</p>');
8 function request_filesystem_credentials($form_post, $type = '', $error = false) {
9 $req_cred = apply_filters('request_filesystem_credentials', '', $form_post, $type, $error);
10 if ( '' !== $req_cred )
14 $type = get_filesystem_method();
16 if ( 'direct' == $type )
19 if( ! $credentials = get_option('ftp_credentials') )
20 $credentials = array();
21 // If defined, set it to that, Else, If POST'd, set it to that, If not, Set it to whatever it previously was(saved details in option)
22 $credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : (!empty($_POST['hostname']) ? $_POST['hostname'] : $credentials['hostname']);
23 $credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($_POST['username']) ? $_POST['username'] : $credentials['username']);
24 $credentials['password'] = defined('FTP_PASS') ? FTP_PASS : (!empty($_POST['password']) ? $_POST['password'] : $credentials['password']);
25 $credentials['ssl'] = defined('FTP_SSL') ? FTP_SSL : (!empty($_POST['ssl']) ? $_POST['ssl'] : $credentials['ssl']);
27 if ( ! $error && !empty($credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname']) ) {
28 $stored_credentials = $credentials;
29 unset($stored_credentials['password']);
30 update_option('ftp_credentials', $stored_credentials);
37 if ( !empty($credentials) )
38 extract($credentials, EXTR_OVERWRITE);
40 echo '<div id="message" class="error"><p>' . __('<strong>Error:</strong> There was an error connecting to the server, Please verify the settings are correct.') . '</p></div>';
42 <form action="<?php echo $form_post ?>" method="post">
44 <h2><?php _e('FTP Connection Information') ?></h2>
45 <p><?php _e('To perform the requested update, FTP connection information is required.') ?></p>
46 <table class="form-table">
48 <th scope="row"><?php _e('Hostname:') ?></th>
49 <td><input name="hostname" type="text" id="hostname" value="<?php echo attribute_escape($hostname) ?>"<?php if( defined('FTP_HOST') ) echo ' disabled="disabled"' ?> size="40" /></td>
52 <th scope="row"><?php _e('Username:') ?></th>
53 <td><input name="username" type="text" id="username" value="<?php echo attribute_escape($username) ?>"<?php if( defined('FTP_USER') ) echo ' disabled="disabled"' ?> size="40" /></td>
56 <th scope="row"><?php _e('Password:') ?></th>
57 <td><input name="password" type="password" id="password" value=""<?php if( defined('FTP_PASS') ) echo ' disabled="disabled"' ?> size="40" /><?php if( defined('FTP_PASS') && !empty($password) ) echo '<em>'.__('(Password not shown)').'</em>'; ?></td>
60 <th scope="row"><?php _e('Use SSL:') ?></th>
62 <select name="ssl" id="ssl"<?php if( defined('FTP_SSL') ) echo ' disabled="disabled"' ?>>
64 foreach ( array(0 => __('No'), 1 => __('Yes')) as $key => $value ) :
65 $selected = ($ssl == $value) ? 'selected="selected"' : '';
66 echo "\n\t<option value='$key' $selected>" . $value . '</option>';
74 <input type="submit" name="submit" value="<?php _e('Proceed'); ?>" />
82 function show_message($message) {
83 if( is_wp_error($message) ){
84 if( $message->get_error_data() )
85 $message = $message->get_error_message() . ': ' . $message->get_error_data();
87 $message = $message->get_error_message();
89 echo "<p>$message</p>\n";
92 function do_plugin_upgrade($plugin) {
93 global $wp_filesystem;
95 $url = wp_nonce_url("update.php?action=upgrade-plugin&plugin=$plugin", "upgrade-plugin_$plugin");
96 if ( false === ($credentials = request_filesystem_credentials($url)) )
99 if ( ! WP_Filesystem($credentials) ) {
100 request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again
104 echo '<div class="wrap">';
105 echo '<h2>' . __('Upgrade Plugin') . '</h2>';
106 if ( $wp_filesystem->errors->get_error_code() ) {
107 foreach ( $wp_filesystem->errors->get_error_messages() as $message )
108 show_message($message);
113 $was_activated = is_plugin_active($plugin); //Check now, It'll be deactivated by the next line if it is,
115 $result = wp_update_plugin($plugin, 'show_message');
117 if ( is_wp_error($result) ) {
118 show_message($result);
120 //Result is the new plugin file relative to PLUGINDIR
121 show_message(__('Plugin upgraded successfully'));
122 if( $result && $was_activated ){
123 show_message(__('Attempting reactivation of the plugin'));
124 echo '<iframe style="border:0" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&plugin=' . $result, 'activate-plugin_' . $result) .'"></iframe>';
130 if ( isset($_GET['action']) ) {
131 $plugin = isset($_GET['plugin']) ? trim($_GET['plugin']) : '';
133 if ( 'upgrade-plugin' == $_GET['action'] ) {
134 check_admin_referer('upgrade-plugin_' . $plugin);
135 $title = __('Upgrade Plugin');
136 $parent_file = 'plugins.php';
137 require_once('admin-header.php');
138 do_plugin_upgrade($plugin);
139 include('admin-footer.php');
140 } elseif ('activate-plugin' == $_GET['action'] ) {
141 check_admin_referer('activate-plugin_' . $plugin);
142 if( ! isset($_GET['failure']) && ! isset($_GET['success']) ) {
143 wp_redirect( 'update.php?action=activate-plugin&failure=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] );
144 activate_plugin($plugin);
145 wp_redirect( 'update.php?action=activate-plugin&success=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] );
148 ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
149 <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
151 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
152 <title><?php bloginfo('name') ?> › <?php _e('Plugin Reactivation'); ?> — <?php _e('WordPress'); ?></title>
154 wp_admin_css( 'css/global' );
155 wp_admin_css( 'css/colors' );
160 if( isset($_GET['success']) )
161 echo '<p>' . __('Plugin reactivated successfully.') . '</p>';
163 if( isset($_GET['failure']) ){
164 echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>';
165 error_reporting( E_ALL ^ E_NOTICE );
166 @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
167 include(ABSPATH . PLUGINDIR . '/' . $plugin);
169 echo "</body></html>";