raw
mp-wp_genesis           1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * Update Plugin/Theme administration panel.
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @subpackage Administration
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /** WordPress Administration Bootstrap */
mp-wp_genesis 10 require_once('admin.php');
mp-wp_genesis 11
mp-wp_genesis 12 if ( ! current_user_can('update_plugins') )
mp-wp_genesis 13 wp_die(__('You do not have sufficient permissions to update plugins for this blog.'));
mp-wp_genesis 14
mp-wp_genesis 15 /**
mp-wp_genesis 16 * Plugin upgrade display.
mp-wp_genesis 17 *
mp-wp_genesis 18 * @since 2.5
mp-wp_genesis 19 *
mp-wp_genesis 20 * @param string $plugin Plugin
mp-wp_genesis 21 */
mp-wp_genesis 22 function do_plugin_upgrade($plugin) {
mp-wp_genesis 23 global $wp_filesystem;
mp-wp_genesis 24
mp-wp_genesis 25 $url = wp_nonce_url("update.php?action=upgrade-plugin&plugin=$plugin", "upgrade-plugin_$plugin");
mp-wp_genesis 26 if ( false === ($credentials = request_filesystem_credentials($url)) )
mp-wp_genesis 27 return;
mp-wp_genesis 28
mp-wp_genesis 29 if ( ! WP_Filesystem($credentials) ) {
mp-wp_genesis 30 $error = true;
mp-wp_genesis 31 if ( is_object($wp_filesystem) && $wp_filesystem->errors->get_error_code() )
mp-wp_genesis 32 $error = $wp_filesystem->errors;
mp-wp_genesis 33 request_filesystem_credentials($url, '', $error); //Failed to connect, Error and request again
mp-wp_genesis 34 return;
mp-wp_genesis 35 }
mp-wp_genesis 36
mp-wp_genesis 37 echo '<div class="wrap">';
mp-wp_genesis 38 echo '<h2>' . __('Upgrade Plugin') . '</h2>';
mp-wp_genesis 39 if ( $wp_filesystem->errors->get_error_code() ) {
mp-wp_genesis 40 foreach ( $wp_filesystem->errors->get_error_messages() as $message )
mp-wp_genesis 41 show_message($message);
mp-wp_genesis 42 echo '</div>';
mp-wp_genesis 43 return;
mp-wp_genesis 44 }
mp-wp_genesis 45
mp-wp_genesis 46 $was_activated = is_plugin_active($plugin); //Check now, It'll be deactivated by the next line if it is
mp-wp_genesis 47
mp-wp_genesis 48 $result = wp_update_plugin($plugin, 'show_message');
mp-wp_genesis 49
mp-wp_genesis 50 if ( is_wp_error($result) ) {
mp-wp_genesis 51 show_message($result);
mp-wp_genesis 52 show_message( __('Plugin upgrade Failed') );
mp-wp_genesis 53 } else {
mp-wp_genesis 54 $plugin_file = $result;
mp-wp_genesis 55 show_message( __('Plugin upgraded successfully') );
mp-wp_genesis 56 if( $result && $was_activated ){
mp-wp_genesis 57 show_message(__('Attempting reactivation of the plugin'));
mp-wp_genesis 58 echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) .'"></iframe>';
mp-wp_genesis 59 }
mp-wp_genesis 60 $update_actions = array(
mp-wp_genesis 61 'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&amp;plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . attribute_escape(__('Activate this plugin')) . '" target="_parent">' . __('Activate Plugin') . '</a>',
mp-wp_genesis 62 'plugins_page' => '<a href="' . admin_url('plugins.php') . '" title="' . attribute_escape(__('Goto plugins page')) . '" target="_parent">' . __('Return to Plugins page') . '</a>'
mp-wp_genesis 63 );
mp-wp_genesis 64 if ( $was_activated )
mp-wp_genesis 65 unset( $update_actions['activate_plugin'] );
mp-wp_genesis 66
mp-wp_genesis 67 $update_actions = apply_filters('update_plugin_complete_actions', $update_actions, $plugin_file);
mp-wp_genesis 68 if ( ! empty($update_actions) )
mp-wp_genesis 69 show_message('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$update_actions));
mp-wp_genesis 70 }
mp-wp_genesis 71 echo '</div>';
mp-wp_genesis 72 }
mp-wp_genesis 73
mp-wp_genesis 74 /**
mp-wp_genesis 75 * Theme upgrade display.
mp-wp_genesis 76 *
mp-wp_genesis 77 * @since 2.5
mp-wp_genesis 78 *
mp-wp_genesis 79 * @param string $plugin Plugin
mp-wp_genesis 80 */
mp-wp_genesis 81 function do_theme_upgrade($theme) {
mp-wp_genesis 82 global $wp_filesystem;
mp-wp_genesis 83
mp-wp_genesis 84 $url = wp_nonce_url('update.php?action=upgrade-theme&theme=' . urlencode($theme), 'upgrade-plugin_' . urlencode($theme));
mp-wp_genesis 85 if ( false === ($credentials = request_filesystem_credentials($url)) )
mp-wp_genesis 86 return;
mp-wp_genesis 87
mp-wp_genesis 88 if ( ! WP_Filesystem($credentials) ) {
mp-wp_genesis 89 $error = true;
mp-wp_genesis 90 if ( is_object($wp_filesystem) && $wp_filesystem->errors->get_error_code() )
mp-wp_genesis 91 $error = $wp_filesystem->errors;
mp-wp_genesis 92 request_filesystem_credentials($url, '', $error); //Failed to connect, Error and request again
mp-wp_genesis 93 return;
mp-wp_genesis 94 }
mp-wp_genesis 95
mp-wp_genesis 96 echo '<div class="wrap">';
mp-wp_genesis 97 echo '<h2>' . __('Upgrade Theme') . '</h2>';
mp-wp_genesis 98 if ( $wp_filesystem->errors->get_error_code() ) {
mp-wp_genesis 99 foreach ( $wp_filesystem->errors->get_error_messages() as $message )
mp-wp_genesis 100 show_message($message);
mp-wp_genesis 101 echo '</div>';
mp-wp_genesis 102 return;
mp-wp_genesis 103 }
mp-wp_genesis 104
mp-wp_genesis 105 //TODO: Is theme currently active?
mp-wp_genesis 106 $was_current = false; //is_plugin_active($plugin); //Check now, It'll be deactivated by the next line if it is
mp-wp_genesis 107
mp-wp_genesis 108 $result = wp_update_theme($theme, 'show_message');
mp-wp_genesis 109
mp-wp_genesis 110 if ( is_wp_error($result) ) {
mp-wp_genesis 111 show_message($result);
mp-wp_genesis 112 show_message( __('Installation Failed') );
mp-wp_genesis 113 } else {
mp-wp_genesis 114 //Result is the new plugin file relative to WP_PLUGIN_DIR
mp-wp_genesis 115 show_message( __('Theme upgraded successfully') );
mp-wp_genesis 116 if( $result && $was_current ){
mp-wp_genesis 117 show_message(__('Setting theme as Current'));
mp-wp_genesis 118 //TODO: Actually set it as active again.
mp-wp_genesis 119 //echo '<iframe style="border:0" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&plugin=' . $result, 'activate-plugin_' . $result) .'"></iframe>';
mp-wp_genesis 120 }
mp-wp_genesis 121 }
mp-wp_genesis 122 echo '</div>';
mp-wp_genesis 123 }
mp-wp_genesis 124
mp-wp_genesis 125 if ( isset($_GET['action']) ) {
mp-wp_genesis 126 $plugin = isset($_GET['plugin']) ? trim($_GET['plugin']) : '';
mp-wp_genesis 127 $theme = isset($_REQUEST['theme']) ? urldecode($_REQUEST['theme']) : '';
mp-wp_genesis 128 $action = isset($_GET['action']) ? $_GET['action'] : '';
mp-wp_genesis 129
mp-wp_genesis 130 if ( 'upgrade-plugin' == $action ) {
mp-wp_genesis 131 check_admin_referer('upgrade-plugin_' . $plugin);
mp-wp_genesis 132 $title = __('Upgrade Plugin');
mp-wp_genesis 133 $parent_file = 'plugins.php';
mp-wp_genesis 134 require_once('admin-header.php');
mp-wp_genesis 135 do_plugin_upgrade($plugin);
mp-wp_genesis 136 include('admin-footer.php');
mp-wp_genesis 137 } elseif ('activate-plugin' == $action ) {
mp-wp_genesis 138 check_admin_referer('activate-plugin_' . $plugin);
mp-wp_genesis 139 if( ! isset($_GET['failure']) && ! isset($_GET['success']) ) {
mp-wp_genesis 140 wp_redirect( 'update.php?action=activate-plugin&failure=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] );
mp-wp_genesis 141 activate_plugin($plugin);
mp-wp_genesis 142 wp_redirect( 'update.php?action=activate-plugin&success=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] );
mp-wp_genesis 143 die();
mp-wp_genesis 144 }
mp-wp_genesis 145 iframe_header( __('Plugin Reactivation'), true );
mp-wp_genesis 146 if( isset($_GET['success']) )
mp-wp_genesis 147 echo '<p>' . __('Plugin reactivated successfully.') . '</p>';
mp-wp_genesis 148
mp-wp_genesis 149 if( isset($_GET['failure']) ){
mp-wp_genesis 150 echo '<p>' . __('Plugin failed to reactivate due to a fatal error.') . '</p>';
mp-wp_genesis 151 error_reporting( E_ALL ^ E_NOTICE );
mp-wp_genesis 152 @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
mp-wp_genesis 153 include(WP_PLUGIN_DIR . '/' . $plugin);
mp-wp_genesis 154 }
mp-wp_genesis 155 iframe_footer();
mp-wp_genesis 156 } elseif ( 'upgrade-theme' == $action ) {
mp-wp_genesis 157 check_admin_referer('upgrade-theme_' . $theme);
mp-wp_genesis 158 $title = __('Upgrade Theme');
mp-wp_genesis 159 $parent_file = 'themes.php';
mp-wp_genesis 160 require_once('admin-header.php');
mp-wp_genesis 161 do_theme_upgrade($theme);
mp-wp_genesis 162 include('admin-footer.php');
mp-wp_genesis 163 }
mp-wp_genesis 164 }
mp-wp_genesis 165
mp-wp_genesis 166 ?>