-
+ 313D01A0D12B7E73C3039C791758E0D14267D19C9AA8B397D668C7CFF6B27159045FBF6C212410DA52B453C38FC46731A5FD43F71080AB9EF4E42A80CB13462D
mp-wp/wp-admin/includes/update.php
(0 . 0)(1 . 492)
44746 <?php
44747 /**
44748 * WordPress Administration Update API
44749 *
44750 * @package WordPress
44751 * @subpackage Admin
44752 */
44753
44754 // The admin side of our 1.1 update system
44755
44756 /**
44757 * Selects the first update version from the update_core option
44758 *
44759 * @return object the response from the API
44760 */
44761 function get_preferred_from_update_core() {
44762 $updates = get_core_updates();
44763 if ( !is_array( $updates ) )
44764 return false;
44765 if ( empty( $updates ) )
44766 return (object)array('response' => 'latest');
44767 return $updates[0];
44768 }
44769
44770 /**
44771 * Get available core updates
44772 *
44773 * @param array $options Set $options['dismissed'] to true to show dismissed upgrades too,
44774 * set $options['available'] to false to skip not-dimissed updates.
44775 * @return array Array of the update objects
44776 */
44777 function get_core_updates( $options = array() ) {
44778 $options = array_merge( array('available' => true, 'dismissed' => false ), $options );
44779 $dismissed = get_option( 'dismissed_update_core' );
44780 if ( !is_array( $dismissed ) ) $dismissed = array();
44781 $from_api = get_option( 'update_core' );
44782 if ( empty($from_api) )
44783 return false;
44784 if ( !is_array( $from_api->updates ) ) return false;
44785 $updates = $from_api->updates;
44786 if ( !is_array( $updates ) ) return false;
44787 $result = array();
44788 foreach($updates as $update) {
44789 if ( array_key_exists( $update->current.'|'.$update->locale, $dismissed ) ) {
44790 if ( $options['dismissed'] ) {
44791 $update->dismissed = true;
44792 $result[]= $update;
44793 }
44794 } else {
44795 if ( $options['available'] ) {
44796 $update->dismissed = false;
44797 $result[]= $update;
44798 }
44799 }
44800 }
44801 return $result;
44802 }
44803
44804 function dismiss_core_update( $update ) {
44805 $dismissed = get_option( 'dismissed_update_core' );
44806 $dismissed[ $update->current.'|'.$update->locale ] = true;
44807 return update_option( 'dismissed_update_core', $dismissed );
44808 }
44809
44810 function undismiss_core_update( $version, $locale ) {
44811 $dismissed = get_option( 'dismissed_update_core' );
44812 $key = $version.'|'.$locale;
44813 if ( !isset( $dismissed[$key] ) ) return false;
44814 unset( $dismissed[$key] );
44815 return update_option( 'dismissed_update_core', $dismissed );
44816 }
44817
44818 function find_core_update( $version, $locale ) {
44819 $from_api = get_option( 'update_core' );
44820 if ( !is_array( $from_api->updates ) ) return false;
44821 $updates = $from_api->updates;
44822 foreach($updates as $update) {
44823 if ( $update->current == $version && $update->locale == $locale )
44824 return $update;
44825 }
44826 return false;
44827 }
44828
44829 function core_update_footer( $msg = '' ) {
44830 if ( !current_user_can('manage_options') )
44831 return sprintf( '| '.__( 'Version %s' ), $GLOBALS['wp_version'] );
44832
44833 $cur = get_preferred_from_update_core();
44834 if ( ! isset( $cur->current ) )
44835 $cur->current = '';
44836
44837 if ( ! isset( $cur->url ) )
44838 $cur->url = '';
44839
44840 if ( ! isset( $cur->response ) )
44841 $cur->response = '';
44842
44843 switch ( $cur->response ) {
44844 case 'development' :
44845 return sprintf( __( 'You are using a development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.' ), $GLOBALS['wp_version'], 'update-core.php');
44846 break;
44847
44848 case 'upgrade' :
44849 if ( current_user_can('manage_options') ) {
44850 return sprintf( '<strong>'.__( '<a href="%1$s">Get Version %2$s</a>' ).'</strong>', 'update-core.php', $cur->current);
44851 break;
44852 }
44853
44854 case 'latest' :
44855 default :
44856 return sprintf( __( 'Version %s' ), $GLOBALS['wp_version'] );
44857 break;
44858 }
44859 }
44860 add_filter( 'update_footer', 'core_update_footer' );
44861
44862 function update_nag() {
44863 global $pagenow;
44864
44865 if ( 'update-core.php' == $pagenow )
44866 return;
44867
44868 $cur = get_preferred_from_update_core();
44869
44870 if ( ! isset( $cur->response ) || $cur->response != 'upgrade' )
44871 return false;
44872
44873 if ( current_user_can('manage_options') )
44874 $msg = sprintf( __('WordPress %1$s is available! <a href="%2$s">Please update now</a>.'), $cur->current, 'update-core.php' );
44875 else
44876 $msg = sprintf( __('WordPress %1$s is available! Please notify the site administrator.'), $cur->current );
44877
44878 echo "<div id='update-nag'>$msg</div>";
44879 }
44880 add_action( 'admin_notices', 'update_nag', 3 );
44881
44882 // Called directly from dashboard
44883 function update_right_now_message() {
44884 $cur = get_preferred_from_update_core();
44885
44886 $msg = sprintf( __('You are using <span class="b">WordPress %s</span>.'), $GLOBALS['wp_version'] );
44887 if ( isset( $cur->response ) && $cur->response == 'upgrade' && current_user_can('manage_options') )
44888 $msg .= " <a href='update-core.php' class='button'>" . sprintf( __('Update to %s'), $cur->current ? $cur->current : __( 'Latest' ) ) . '</a>';
44889
44890 echo "<span id='wp-version-message'>$msg</span>";
44891 }
44892
44893 function wp_plugin_update_row( $file, $plugin_data ) {
44894 $current = get_option( 'update_plugins' );
44895 if ( !isset( $current->response[ $file ] ) )
44896 return false;
44897
44898 $r = $current->response[ $file ];
44899
44900 $details_url = admin_url('plugin-install.php?tab=plugin-information&plugin=' . $r->slug . '&TB_iframe=true&width=600&height=800');
44901
44902 echo '<tr><td colspan="5" class="plugin-update">';
44903 if ( ! current_user_can('update_plugins') )
44904 printf( __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a>.'), $plugin_data['Name'], $details_url, $r->new_version);
44905 else if ( empty($r->package) )
44906 printf( __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a> <em>automatic upgrade unavailable for this plugin</em>.'), $plugin_data['Name'], $details_url, $r->new_version);
44907 else
44908 printf( __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s Details</a> or <a href="%4$s">upgrade automatically</a>.'), $plugin_data['Name'], $details_url, $r->new_version, wp_nonce_url('update.php?action=upgrade-plugin&plugin=' . $file, 'upgrade-plugin_' . $file) );
44909
44910 echo '</td></tr>';
44911 }
44912 add_action( 'after_plugin_row', 'wp_plugin_update_row', 10, 2 );
44913
44914 function wp_update_plugin($plugin, $feedback = '') {
44915 global $wp_filesystem;
44916
44917 if ( !empty($feedback) )
44918 add_filter('update_feedback', $feedback);
44919
44920 // Is an update available?
44921 $current = get_option( 'update_plugins' );
44922 if ( !isset( $current->response[ $plugin ] ) )
44923 return new WP_Error('up_to_date', __('The plugin is at the latest version.'));
44924
44925 // Is a filesystem accessor setup?
44926 if ( ! $wp_filesystem || ! is_object($wp_filesystem) )
44927 WP_Filesystem();
44928
44929 if ( ! is_object($wp_filesystem) )
44930 return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
44931
44932 if ( $wp_filesystem->errors->get_error_code() )
44933 return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);
44934
44935 //Get the base plugin folder
44936 $plugins_dir = $wp_filesystem->wp_plugins_dir();
44937 if ( empty($plugins_dir) )
44938 return new WP_Error('fs_no_plugins_dir', __('Unable to locate WordPress Plugin directory.'));
44939
44940 //And the same for the Content directory.
44941 $content_dir = $wp_filesystem->wp_content_dir();
44942 if( empty($content_dir) )
44943 return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).'));
44944
44945 $plugins_dir = trailingslashit( $plugins_dir );
44946 $content_dir = trailingslashit( $content_dir );
44947
44948 // Get the URL to the zip file
44949 $r = $current->response[ $plugin ];
44950
44951 if ( empty($r->package) )
44952 return new WP_Error('no_package', __('Upgrade package not available.'));
44953
44954 // Download the package
44955 $package = $r->package;
44956 apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package));
44957 $download_file = download_url($package);
44958
44959 if ( is_wp_error($download_file) )
44960 return new WP_Error('download_failed', __('Download failed.'), $download_file->get_error_message());
44961
44962 $working_dir = $content_dir . 'upgrade/' . basename($plugin, '.php');
44963
44964 // Clean up working directory
44965 if ( $wp_filesystem->is_dir($working_dir) )
44966 $wp_filesystem->delete($working_dir, true);
44967
44968 apply_filters('update_feedback', __('Unpacking the update'));
44969 // Unzip package to working directory
44970 $result = unzip_file($download_file, $working_dir);
44971
44972 // Once extracted, delete the package
44973 unlink($download_file);
44974
44975 if ( is_wp_error($result) ) {
44976 $wp_filesystem->delete($working_dir, true);
44977 return $result;
44978 }
44979
44980 if ( is_plugin_active($plugin) ) {
44981 //Deactivate the plugin silently, Prevent deactivation hooks from running.
44982 apply_filters('update_feedback', __('Deactivating the plugin'));
44983 deactivate_plugins($plugin, true);
44984 }
44985
44986 // Remove the existing plugin.
44987 apply_filters('update_feedback', __('Removing the old version of the plugin'));
44988 $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) );
44989
44990 // If plugin is in its own directory, recursively delete the directory.
44991 if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory seperator AND that its not the root plugin folder
44992 $deleted = $wp_filesystem->delete($this_plugin_dir, true);
44993 else
44994 $deleted = $wp_filesystem->delete($plugins_dir . $plugin);
44995
44996 if ( ! $deleted ) {
44997 $wp_filesystem->delete($working_dir, true);
44998 return new WP_Error('delete_failed', __('Could not remove the old plugin'));
44999 }
45000
45001 apply_filters('update_feedback', __('Installing the latest version'));
45002 // Copy new version of plugin into place.
45003 $result = copy_dir($working_dir, $plugins_dir);
45004 if ( is_wp_error($result) ) {
45005 $wp_filesystem->delete($working_dir, true);
45006 return $result;
45007 }
45008
45009 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
45010 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
45011
45012 // Remove working directory
45013 $wp_filesystem->delete($working_dir, true);
45014
45015 // Force refresh of plugin update information
45016 delete_option('update_plugins');
45017
45018 if( empty($filelist) )
45019 return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup.
45020
45021 $folder = $filelist[0];
45022 $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash
45023 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
45024
45025 return $folder . '/' . $pluginfiles[0];
45026 }
45027
45028 function wp_update_theme($theme, $feedback = '') {
45029 global $wp_filesystem;
45030
45031 if ( !empty($feedback) )
45032 add_filter('update_feedback', $feedback);
45033
45034 // Is an update available?
45035 $current = get_option( 'update_themes' );
45036 if ( !isset( $current->response[ $theme ] ) )
45037 return new WP_Error('up_to_date', __('The theme is at the latest version.'));
45038
45039 $r = $current->response[ $theme ];
45040
45041 $themes = get_themes();
45042 foreach ( (array) $themes as $this_theme ) {
45043 if ( $this_theme['Stylesheet'] == $theme ) {
45044 $theme_directory = preg_replace('!^/themes/!i', '', $this_theme['Stylesheet Dir']);
45045 break;
45046 }
45047 }
45048 unset($themes);
45049
45050 if ( empty($theme_directory) )
45051 return new WP_Error('theme_non_existant', __('Theme does not exist.'));
45052
45053 // Is a filesystem accessor setup?
45054 if ( ! $wp_filesystem || ! is_object($wp_filesystem) )
45055 WP_Filesystem();
45056
45057 if ( ! is_object($wp_filesystem) )
45058 return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
45059
45060 if ( $wp_filesystem->errors->get_error_code() )
45061 return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);
45062
45063 //Get the base plugin folder
45064 $themes_dir = $wp_filesystem->wp_themes_dir();
45065 if ( empty($themes_dir) )
45066 return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress Theme directory.'));
45067
45068 //And the same for the Content directory.
45069 $content_dir = $wp_filesystem->wp_content_dir();
45070 if( empty($content_dir) )
45071 return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).'));
45072
45073 $themes_dir = trailingslashit( $themes_dir );
45074 $content_dir = trailingslashit( $content_dir );
45075
45076 if ( empty($r->package) )
45077 return new WP_Error('no_package', __('Upgrade package not available.'));
45078
45079 // Download the package
45080 apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $r['package']));
45081 $download_file = download_url($r['package']);
45082
45083 if ( is_wp_error($download_file) )
45084 return new WP_Error('download_failed', __('Download failed.'), $download_file->get_error_message());
45085
45086 $working_dir = $content_dir . 'upgrade/' . basename($theme_directory);
45087
45088 // Clean up working directory
45089 if ( $wp_filesystem->is_dir($working_dir) )
45090 $wp_filesystem->delete($working_dir, true);
45091
45092 apply_filters('update_feedback', __('Unpacking the update'));
45093 // Unzip package to working directory
45094 $result = unzip_file($download_file, $working_dir);
45095
45096 // Once extracted, delete the package
45097 unlink($download_file);
45098
45099 if ( is_wp_error($result) ) {
45100 $wp_filesystem->delete($working_dir, true);
45101 return $result;
45102 }
45103
45104 //TODO: Is theme currently active? If so, set default theme
45105 /*
45106 if ( is_plugin_active($plugin) ) {
45107 //Deactivate the plugin silently, Prevent deactivation hooks from running.
45108 apply_filters('update_feedback', __('Deactivating the plugin'));
45109 deactivate_plugins($plugin, true);
45110 }*/
45111
45112 // Remove the existing plugin.
45113 apply_filters('update_feedback', __('Removing the old version of the theme'));
45114 $deleted = $wp_filesystem->delete($themes_dir . $theme_directory, true);
45115
45116 if ( ! $deleted ) {
45117 $wp_filesystem->delete($working_dir, true);
45118 return new WP_Error('delete_failed', __('Could not remove the old plugin'));
45119 }
45120
45121 apply_filters('update_feedback', __('Installing the latest version'));
45122 // Copy new version of plugin into place.
45123 $result = copy_dir($working_dir, $themes_dir);
45124 if ( is_wp_error($result) ) {
45125 $wp_filesystem->delete($working_dir, true);
45126 return $result;
45127 }
45128
45129 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
45130 //$filelist = array_keys( $wp_filesystem->dirlist($working_dir) );
45131
45132 // Remove working directory
45133 $wp_filesystem->delete($working_dir, true);
45134
45135 // Force refresh of plugin update information
45136 delete_option('update_themes');
45137
45138 /*if( empty($filelist) )
45139 return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup.
45140
45141 $folder = $filelist[0];
45142 $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash
45143 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
45144
45145 return $folder . '/' . $pluginfiles[0];*/
45146 }
45147
45148
45149 function wp_update_core($current, $feedback = '') {
45150 global $wp_filesystem;
45151
45152 @set_time_limit( 300 );
45153
45154 if ( !empty($feedback) )
45155 add_filter('update_feedback', $feedback);
45156
45157 // Is an update available?
45158 if ( !isset( $current->response ) || $current->response == 'latest' )
45159 return new WP_Error('up_to_date', __('WordPress is at the latest version.'));
45160
45161 // Is a filesystem accessor setup?
45162 if ( ! $wp_filesystem || ! is_object($wp_filesystem) )
45163 WP_Filesystem();
45164
45165 if ( ! is_object($wp_filesystem) )
45166 return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
45167
45168 if ( $wp_filesystem->errors->get_error_code() )
45169 return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);
45170
45171 // Get the base WP folder
45172 $wp_dir = $wp_filesystem->abspath();
45173 if ( empty($wp_dir) )
45174 return new WP_Error('fs_no_wp_dir', __('Unable to locate WordPress directory.'));
45175
45176 // And the same for the Content directory.
45177 $content_dir = $wp_filesystem->wp_content_dir();
45178 if( empty($content_dir) )
45179 return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).'));
45180
45181 $wp_dir = trailingslashit( $wp_dir );
45182 $content_dir = trailingslashit( $content_dir );
45183
45184 // Get the URL to the zip file
45185 $package = $current->package;
45186
45187 // Download the package
45188 apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package));
45189 $download_file = download_url($package);
45190
45191 if ( is_wp_error($download_file) )
45192 return new WP_Error('download_failed', __('Download failed.'), $download_file->get_error_message());
45193
45194 $working_dir = $content_dir . 'upgrade/core';
45195 // Clean up working directory
45196 if ( $wp_filesystem->is_dir($working_dir) ) {
45197 $wp_filesystem->delete($working_dir, true);
45198 }
45199
45200 apply_filters('update_feedback', __('Unpacking the core update'));
45201 // Unzip package to working directory
45202 $result = unzip_file($download_file, $working_dir);
45203 // Once extracted, delete the package
45204 unlink($download_file);
45205
45206 if ( is_wp_error($result) ) {
45207 $wp_filesystem->delete($working_dir, true);
45208 return $result;
45209 }
45210
45211 // Copy update-core.php from the new version into place.
45212 if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {
45213 $wp_filesystem->delete($working_dir, true);
45214 return new WP_Error('copy_failed', __('Could not copy files'));
45215 }
45216 $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
45217
45218 require(ABSPATH . 'wp-admin/includes/update-core.php');
45219
45220 return update_core($working_dir, $wp_dir);
45221 }
45222
45223 function maintenance_nag() {
45224 global $upgrading;
45225 if ( ! isset( $upgrading ) )
45226 return false;
45227
45228 if ( current_user_can('manage_options') )
45229 $msg = sprintf( __('An automated WordPress update has failed to complete - <a href="%s">please attempt the update again now</a>.'), 'update-core.php' );
45230 else
45231 $msg = __('An automated WordPress update has failed to complete! Please notify the site administrator.');
45232
45233 echo "<div id='update-nag'>$msg</div>";
45234 }
45235 add_action( 'admin_notices', 'maintenance_nag' );
45236
45237 ?>