Ticket #7875: 7875.2.diff
File 7875.2.diff, 88.5 KB (added by , 15 years ago) |
---|
-
wp-admin/includes/class-wp-filesystem-ftpext.php
14 14 * @subpackage Filesystem 15 15 * @uses WP_Filesystem_Base Extends class 16 16 */ 17 class WP_Filesystem_FTPext extends WP_Filesystem_Base {17 class _WP_Filesystem_FTPext extends WP_Filesystem_Base { 18 18 var $link; 19 19 var $timeout = 5; 20 var $errors = array();20 var $errors = null; 21 21 var $options = array(); 22 22 23 23 var $permission = null; … … 65 65 } 66 66 67 67 function connect() { 68 if ( $this->options['ssl'] && function_exists('ftp_ssl_connect') )68 if ( isset($this->options['ssl']) && $this->options['ssl'] && function_exists('ftp_ssl_connect') ) 69 69 $this->link = @ftp_ssl_connect($this->options['hostname'], $this->options['port'],$this->timeout); 70 70 else 71 71 $this->link = @ftp_connect($this->options['hostname'], $this->options['port'],$this->timeout); … … 187 187 return ftp_rename($this->link, $source, $destination); 188 188 } 189 189 190 function delete($file,$recursive=false) { 190 function delete($file, $recursive = false ) { 191 if ( empty($file) ) 192 return false; 191 193 if ( $this->is_file($file) ) 192 194 return @ftp_delete($this->link, $file); 193 195 if ( !$recursive ) 194 196 return @ftp_rmdir($this->link, $file); 195 $filelist = $this->dirlist($file); 196 foreach ((array) $filelist as $filename => $fileinfo) { 197 $this->delete($file . '/' . $filename, $recursive); 198 } 197 198 $filelist = $this->dirlist( trailingslashit($file) ); 199 if ( !empty($filelist) ) 200 foreach ( $filelist as $delete_file ) 201 $this->delete( trailingslashit($file) . $delete_file['name'], $recursive); 199 202 return @ftp_rmdir($this->link, $file); 200 203 } 201 204 202 205 function exists($file) { 203 $list = ftp_rawlist($this->link, $file, false); 204 if( ! $list ) 205 return false; 206 return count($list) == 1 ? true : false; 206 $list = @ftp_rawlist($this->link, $file, false); 207 return !empty($list); //empty list = no file, so invert. 207 208 } 208 209 function is_file($file) { 209 return $this-> is_dir($file) ? false : true;210 return $this->exists($file) && !$this->is_dir($file); 210 211 } 211 212 function is_dir($path) { 212 213 $cwd = $this->cwd(); 213 $result = @ftp_chdir($this->link, $path);214 $result = @ftp_chdir($this->link, trailingslashit($path) ); 214 215 if( $result && $path == $this->cwd() || $this->cwd() != $cwd ) { 215 216 @ftp_chdir($this->link, $cwd); 216 217 return true; … … 218 219 return false; 219 220 } 220 221 function is_readable($file) { 221 //Get dir list, Check if the file is writable by the current user??222 //Get dir list, Check if the file is readable by the current user?? 222 223 return true; 223 224 } 224 225 function is_writable($file) { … … 238 239 return false; 239 240 } 240 241 function mkdir($path, $chmod = false, $chown = false, $chgrp = false) { 241 if( ! @ftp_mkdir($this->link, $path) )242 if( !ftp_mkdir($this->link, $path) ) 242 243 return false; 243 244 if( $chmod ) 244 245 $this->chmod($path, $chmod); … … 249 250 return true; 250 251 } 251 252 function rmdir($path, $recursive = false) { 252 if( ! $recursive ) 253 return @ftp_rmdir($this->link, $path); 254 255 //TODO: Recursive Directory delete, Have to delete files from the folder first. 256 //$dir = $this->dirlist($path); 257 //foreach($dir as $file) 258 253 return $this->delete($path, $recursive); 259 254 } 260 255 261 256 function parselisting($line) { 262 $is_windows = ($this->OS_remote == FTP_OS_Windows); 257 static $is_windows; 258 if ( is_null($is_windows) ) 259 $is_windows = strpos( strtolower(ftp_systype($this->link)), 'win') !== false; 260 263 261 if ($is_windows && preg_match("/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/", $line, $lucifer)) { 264 262 $b = array(); 265 263 if ($lucifer[3]<70) { $lucifer[3] +=2000; } else { $lucifer[3]+=1900; } // 4digit year fix -
wp-admin/includes/class-wp-filesystem-ftpsockets.php
17 17 class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { 18 18 var $ftp = false; 19 19 var $timeout = 5; 20 var $errors ;20 var $errors = null; 21 21 var $options = array(); 22 22 23 23 var $permission = null; … … 210 210 } 211 211 212 212 function delete($file, $recursive = false ) { 213 if ( empty($file) ) 214 return false; 213 215 if ( $this->is_file($file) ) 214 216 return $this->ftp->delete($file); 215 217 if ( !$recursive ) -
wp-admin/includes/file.php
598 598 599 599 $wp_filesystem = new $method($args); 600 600 601 if ( $wp_filesystem->errors->get_error_code() )601 if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) 602 602 return false; 603 603 604 604 if ( !$wp_filesystem->connect() ) -
wp-admin/includes/plugin-install.php
208 208 ?> 209 209 <h4><?php _e('Install a plugin in .zip format') ?></h4> 210 210 <p class="install-help"><?php _e('If you have a plugin in a .zip format, You may install it by uploading it here.') ?></p> 211 <form method="post" enctype="multipart/form-data" action="<?php echo admin_url(' plugin-install.php?tab=do_upload') ?>">211 <form method="post" enctype="multipart/form-data" action="<?php echo admin_url('update.php?action=upload-plugin') ?>"> 212 212 <?php wp_nonce_field( 'plugin-upload') ?> 213 213 <input type="file" name="pluginzip" /> 214 214 <input type="submit" class="button" value="<?php _e('Install Now') ?>" /> … … 461 461 default: 462 462 case 'install': 463 463 if ( current_user_can('install_plugins') ) : 464 ?><a href="<?php echo wp_nonce_url(admin_url(' plugin-install.php?tab=install&plugin=' . $api->slug), 'install-plugin_' . $api->slug) ?>" target="_parent"><?php _e('Install Now') ?></a><?php464 ?><a href="<?php echo wp_nonce_url(admin_url('update.php?action=install-plugin&plugin=' . $api->slug), 'install-plugin_' . $api->slug) ?>" target="_parent"><?php _e('Install Now') ?></a><?php 465 465 endif; 466 466 break; 467 467 case 'update_available': … … 544 544 iframe_footer(); 545 545 exit; 546 546 } 547 548 549 add_action('install_plugins_do_upload', 'upload_plugin');550 function upload_plugin() {551 552 if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )553 wp_die($uploads['error']);554 555 if ( !empty($_FILES) )556 $filename = $_FILES['pluginzip']['name'];557 else if ( isset($_GET['package']) )558 $filename = $_GET['package'];559 560 check_admin_referer('plugin-upload');561 562 echo '<div class="wrap">';563 echo '<h2>', sprintf( __('Installing Plugin from file: %s'), basename($filename) ), '</h2>';564 565 //Handle a newly uploaded file, Else assume it was566 if ( !empty($_FILES) ) {567 $filename = wp_unique_filename( $uploads['basedir'], $filename );568 $local_file = $uploads['basedir'] . '/' . $filename;569 570 // Move the file to the uploads dir571 if ( false === @ move_uploaded_file( $_FILES['pluginzip']['tmp_name'], $local_file) )572 wp_die( sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path']));573 } else {574 $local_file = $uploads['basedir'] . '/' . $filename;575 }576 577 do_plugin_install_local_package($local_file, $filename);578 echo '</div>';579 }580 581 add_action('install_plugins_install', 'install_plugin');582 583 /**584 * Display plugin link and execute install.585 *586 * @since 2.7.0587 */588 function install_plugin() {589 590 $plugin = isset($_REQUEST['plugin']) ? stripslashes( $_REQUEST['plugin'] ) : '';591 592 check_admin_referer('install-plugin_' . $plugin);593 $api = plugins_api('plugin_information', array('slug' => $plugin, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.594 595 if ( is_wp_error($api) )596 wp_die($api);597 598 echo '<div class="wrap">';599 echo '<h2>', sprintf( __('Installing Plugin: %s'), $api->name . ' ' . $api->version ), '</h2>';600 601 do_plugin_install($api->download_link, $api);602 echo '</div>';603 604 }605 606 /**607 * Retrieve plugin and install.608 *609 * @since 2.7.0610 *611 * @param string $download_url Download URL.612 * @param object $plugin_information Optional. Plugin information613 */614 function do_plugin_install($download_url, $plugin_information = null) {615 global $wp_filesystem;616 617 if ( empty($download_url) ) {618 show_message( __('No plugin Specified') );619 return;620 }621 622 $plugin = isset($_REQUEST['plugin']) ? stripslashes( $_REQUEST['plugin'] ) : '';623 624 $url = 'plugin-install.php?tab=install';625 $url = add_query_arg(array('plugin' => $plugin, 'plugin_name' => stripslashes( $_REQUEST['plugin_name'] ), 'download_url' => stripslashes( $_REQUEST['download_url'] ) ), $url);626 627 $url = wp_nonce_url($url, 'install-plugin_' . $plugin);628 if ( false === ($credentials = request_filesystem_credentials($url)) )629 return;630 631 if ( ! WP_Filesystem($credentials) ) {632 request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again633 return;634 }635 636 if ( $wp_filesystem->errors->get_error_code() ) {637 foreach ( $wp_filesystem->errors->get_error_messages() as $message )638 show_message($message);639 return;640 }641 642 $result = wp_install_plugin( $download_url, 'show_message' );643 644 if ( is_wp_error($result) ) {645 show_message($result);646 show_message( __('Installation Failed') );647 } else {648 show_message( sprintf(__('Successfully installed the plugin <strong>%s %s</strong>.'), $plugin_information->name, $plugin_information->version) );649 $plugin_file = $result;650 651 $install_actions = apply_filters('install_plugin_complete_actions', array(652 'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . attribute_escape(__('Activate this plugin')) . '" target="_parent">' . __('Activate Plugin') . '</a>',653 'plugins_page' => '<a href="' . admin_url('plugins.php') . '" title="' . attribute_escape(__('Goto plugins page')) . '" target="_parent">' . __('Return to Plugins page') . '</a>'654 ), $plugin_information, $plugin_file);655 if ( ! empty($install_actions) )656 show_message('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$install_actions));657 }658 }659 660 /**661 * Install a plugin from a local file.662 *663 * @since 2.7.0664 *665 * @param string $package Local Plugin zip666 * @param string $filename Optional. Original filename667 * @param object $plugin_information Optional. Plugin information668 */669 function do_plugin_install_local_package($package, $filename = '') {670 global $wp_filesystem;671 672 if ( empty($package) ) {673 show_message( __('No plugin Specified') );674 return;675 }676 677 if ( empty($filename) )678 $filename = basename($package);679 680 $url = 'plugin-install.php?tab=upload';681 $url = add_query_arg(array('package' => $filename), $url);682 683 $url = wp_nonce_url($url, 'plugin-upload');684 if ( false === ($credentials = request_filesystem_credentials($url)) )685 return;686 687 if ( ! WP_Filesystem($credentials) ) {688 request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again689 return;690 }691 692 if ( $wp_filesystem->errors->get_error_code() ) {693 foreach ( $wp_filesystem->errors->get_error_messages() as $message )694 show_message($message);695 return;696 }697 698 $result = wp_install_plugin_local_package( $package, 'show_message' );699 700 if ( is_wp_error($result) ) {701 show_message($result);702 show_message( __('Installation Failed') );703 } else {704 show_message( __('Successfully installed the plugin.') );705 $plugin_file = $result;706 707 $install_actions = apply_filters('install_plugin_complete_actions', array(708 'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>',709 'plugins_page' => '<a href="' . admin_url('plugins.php') . '" title="' . __('Goto plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'710 ), array(), $plugin_file);711 if ( ! empty($install_actions) )712 show_message('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$install_actions));713 }714 }715 716 /**717 * Install plugin.718 *719 * @since 2.7.0720 *721 * @param string $package722 * @param string $feedback Optional.723 * @return mixed.724 */725 function wp_install_plugin($package, $feedback = '') {726 global $wp_filesystem;727 728 if ( !empty($feedback) )729 add_filter('install_feedback', $feedback);730 731 // Is a filesystem accessor setup?732 if ( ! $wp_filesystem || ! is_object($wp_filesystem) )733 WP_Filesystem();734 735 if ( ! is_object($wp_filesystem) )736 return new WP_Error('fs_unavailable', __('Could not access filesystem.'));737 738 if ( $wp_filesystem->errors->get_error_code() )739 return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);740 741 //Get the base plugin folder742 $plugins_dir = $wp_filesystem->wp_plugins_dir();743 if ( empty($plugins_dir) )744 return new WP_Error('fs_no_plugins_dir', __('Unable to locate WordPress Plugin directory.'));745 746 //And the same for the Content directory.747 $content_dir = $wp_filesystem->wp_content_dir();748 if( empty($content_dir) )749 return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).'));750 751 $plugins_dir = trailingslashit( $plugins_dir );752 $content_dir = trailingslashit( $content_dir );753 754 if ( empty($package) )755 return new WP_Error('no_package', __('Install package not available.'));756 757 // Download the package758 apply_filters('install_feedback', sprintf(__('Downloading plugin package from %s'), $package));759 $download_file = download_url($package);760 761 if ( is_wp_error($download_file) )762 return new WP_Error('download_failed', __('Download failed.'), $download_file->get_error_message());763 764 $working_dir = $content_dir . 'upgrade/' . basename($package, '.zip');765 766 // Clean up working directory767 if ( $wp_filesystem->is_dir($working_dir) )768 $wp_filesystem->delete($working_dir, true);769 770 apply_filters('install_feedback', __('Unpacking the plugin package'));771 // Unzip package to working directory772 $result = unzip_file($download_file, $working_dir);773 774 // Once extracted, delete the package775 @unlink($download_file);776 777 if ( is_wp_error($result) ) {778 $wp_filesystem->delete($working_dir, true);779 return $result;780 }781 782 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin783 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );784 785 if( $wp_filesystem->exists( $plugins_dir . $filelist[0] ) ) {786 $wp_filesystem->delete($working_dir, true);787 return new WP_Error('install_folder_exists', __('Folder already exists.'), $filelist[0] );788 }789 790 apply_filters('install_feedback', __('Installing the plugin'));791 // Copy new version of plugin into place.792 $result = copy_dir($working_dir, $plugins_dir);793 if ( is_wp_error($result) ) {794 $wp_filesystem->delete($working_dir, true);795 return $result;796 }797 798 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin799 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );800 801 // Remove working directory802 $wp_filesystem->delete($working_dir, true);803 804 if( empty($filelist) )805 return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup.806 807 $folder = $filelist[0];808 $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash809 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list810 811 //Return the plugin files name.812 return $folder . '/' . $pluginfiles[0];813 }814 815 /**816 * Install plugin from local package817 *818 * @since 2.7.0819 *820 * @param string $package821 * @param string $feedback Optional.822 * @return mixed.823 */824 function wp_install_plugin_local_package($package, $feedback = '') {825 global $wp_filesystem;826 827 if ( !empty($feedback) )828 add_filter('install_feedback', $feedback);829 830 // Is a filesystem accessor setup?831 if ( ! $wp_filesystem || ! is_object($wp_filesystem) )832 WP_Filesystem();833 834 if ( ! is_object($wp_filesystem) )835 return new WP_Error('fs_unavailable', __('Could not access filesystem.'));836 837 if ( $wp_filesystem->errors->get_error_code() )838 return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);839 840 //Get the base plugin folder841 $plugins_dir = $wp_filesystem->wp_plugins_dir();842 if ( empty($plugins_dir) )843 return new WP_Error('fs_no_plugins_dir', __('Unable to locate WordPress Plugin directory.'));844 845 //And the same for the Content directory.846 $content_dir = $wp_filesystem->wp_content_dir();847 if( empty($content_dir) )848 return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).'));849 850 $plugins_dir = trailingslashit( $plugins_dir );851 $content_dir = trailingslashit( $content_dir );852 853 if ( empty($package) )854 return new WP_Error('no_package', __('Install package not available.'));855 856 $working_dir = $content_dir . 'upgrade/' . basename($package, '.zip');857 858 // Clean up working directory859 if ( $wp_filesystem->is_dir($working_dir) )860 $wp_filesystem->delete($working_dir, true);861 862 apply_filters('install_feedback', __('Unpacking the plugin package'));863 // Unzip package to working directory864 $result = unzip_file($package, $working_dir);865 866 // Once extracted, delete the package867 unlink($package);868 869 if ( is_wp_error($result) ) {870 $wp_filesystem->delete($working_dir, true);871 return $result;872 }873 874 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin875 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );876 877 if( $wp_filesystem->exists( $plugins_dir . $filelist[0] ) ) {878 $wp_filesystem->delete($working_dir, true);879 return new WP_Error('install_folder_exists', __('Folder already exists.'), $filelist[0] );880 }881 882 apply_filters('install_feedback', __('Installing the plugin'));883 // Copy new version of plugin into place.884 $result = copy_dir($working_dir, $plugins_dir);885 if ( is_wp_error($result) ) {886 $wp_filesystem->delete($working_dir, true);887 return $result;888 }889 890 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin891 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );892 893 // Remove working directory894 $wp_filesystem->delete($working_dir, true);895 896 if( empty($filelist) )897 return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup.898 899 $folder = $filelist[0];900 $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash901 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list902 903 //Return the plugin files name.904 return $folder . '/' . $pluginfiles[0];905 }906 907 ?> -
wp-admin/includes/plugin.php
216 216 217 217 // Files in wp-content/plugins directory 218 218 $plugins_dir = @ opendir( $plugin_root); 219 $plugin_files = array(); 219 220 if ( $plugins_dir ) { 220 221 while (($file = readdir( $plugins_dir ) ) !== false ) { 221 222 if ( substr($file, 0, 1) == '.' ) … … 239 240 @closedir( $plugins_dir ); 240 241 @closedir( $plugins_subdir ); 241 242 242 if ( !$plugins_dir || !$plugin_files)243 if ( !$plugins_dir || empty($plugin_files) ) 243 244 return $wp_plugins; 244 245 245 246 foreach ( $plugin_files as $plugin_file ) { … … 432 433 return; 433 434 } 434 435 435 if ( $wp_filesystem->errors->get_error_code() ) {436 return $wp_filesystem->errors;437 }438 439 436 if ( ! is_object($wp_filesystem) ) 440 437 return new WP_Error('fs_unavailable', __('Could not access filesystem.')); 441 438 442 if ( $wp_filesystem->errors->get_error_code() )439 if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) 443 440 return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors); 444 441 445 442 //Get the base plugin folder -
wp-admin/includes/theme-install.php
277 277 ?> 278 278 <h4><?php _e('Install a theme in .zip format') ?></h4> 279 279 <p class="install-help"><?php _e('If you have a theme in a .zip format, you may install it by uploading it here.') ?></p> 280 <form method="post" enctype="multipart/form-data" action="<?php echo admin_url(' theme-install.php?tab=do_upload') ?>">280 <form method="post" enctype="multipart/form-data" action="<?php echo admin_url('update.php?action=upload-theme') ?>"> 281 281 <?php wp_nonce_field( 'theme-upload') ?> 282 282 <input type="file" name="themezip" /> 283 <input type="submit" class="button" value="<?php _e('Install Now') ?>" /> 283 <input type="submit" 284 class="button" value="<?php _e('Install Now') ?>" /> 284 285 </form> 285 <?php286 <?php 286 287 } 287 288 288 289 function display_theme($theme, $actions = null, $show_details = true) { … … 411 412 ?> 412 413 <tr> 413 414 <?php 415 414 416 foreach ( $cols as $col => $theme_index ) { 415 417 $class = array('available-theme'); 416 418 if ( $row == 1 ) $class[] = 'top'; … … 511 513 default: 512 514 case 'install': 513 515 if ( current_user_can('install_themes') ) : 514 $buttons .= '<a class="button-primary" id="install" href="' . wp_nonce_url(admin_url(' theme-install.php?tab=install&theme=' . $api->slug), 'install-theme_' . $api->slug) . '" target="_parent">' . __('Install Now') . '</a>';516 $buttons .= '<a class="button-primary" id="install" href="' . wp_nonce_url(admin_url('update.php?action=install-theme&theme=' . $api->slug), 'install-theme_' . $api->slug) . '" target="_parent">' . __('Install Now') . '</a>'; 515 517 endif; 516 518 break; 517 519 case 'update_available': … … 542 544 iframe_footer(); 543 545 exit; 544 546 } 545 546 add_action('install_themes_do_upload', 'upload_theme');547 function upload_theme() {548 549 if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )550 wp_die($uploads['error']);551 552 if ( !empty($_FILES) )553 $filename = $_FILES['themezip']['name'];554 else if ( isset($_GET['package']) )555 $filename = $_GET['package'];556 557 check_admin_referer('theme-upload');558 559 echo '<div class="wrap">';560 echo '<h2>', sprintf( __('Installing theme from file: %s'), basename($filename) ), '</h2>';561 562 //Handle a newly uploaded file, Else assume it was563 if ( !empty($_FILES) ) {564 $filename = wp_unique_filename( $uploads['basedir'], $filename );565 $local_file = $uploads['basedir'] . '/' . $filename;566 567 // Move the file to the uploads dir568 if ( false === @ move_uploaded_file( $_FILES['themezip']['tmp_name'], $local_file) )569 wp_die( sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path']));570 } else {571 $local_file = $uploads['basedir'] . '/' . $filename;572 }573 574 do_theme_install_local_package($local_file, $filename);575 echo '</div>';576 }577 578 add_action('install_themes_install', 'install_theme');579 580 /**581 * Display theme link and execute install.582 *583 * @since 2.8.0584 */585 function install_theme() {586 587 $theme = isset($_REQUEST['theme']) ? stripslashes( $_REQUEST['theme'] ) : '';588 589 check_admin_referer('install-theme_' . $theme);590 $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false) ) ); //Save on a bit of bandwidth.591 592 if ( is_wp_error($api) )593 wp_die($api);594 595 echo '<div class="wrap">';596 echo '<h2>', sprintf( __('Installing theme: %s'), $api->name . ' ' . $api->version ), '</h2>';597 598 do_theme_install($api->download_link, $api);599 echo '</div>';600 601 }602 603 /**604 * Retrieve theme and install.605 *606 * @since 2.8.0607 *608 * @param string $download_url Download URL.609 * @param object $theme_information Optional. Theme information610 */611 function do_theme_install($download_url, $theme_information = null) {612 global $wp_filesystem;613 614 if ( empty($download_url) ) {615 show_message( __('No theme specified') );616 return;617 }618 619 $theme = isset($_REQUEST['theme']) ? stripslashes( $_REQUEST['theme'] ) : '';620 $theme_name = isset($_REQUEST['theme_name']) ? stripslashes( $_REQUEST['theme_name'] ) : '';621 622 $url = 'theme-install.php?tab=install';623 $url = add_query_arg(array('theme' => $theme, 'theme_name' => $theme_name, 'download_url' => $download_url ), $url);624 625 $url = wp_nonce_url($url, 'install-theme_' . $theme);626 if ( false === ($credentials = request_filesystem_credentials($url)) )627 return;628 629 if ( ! WP_Filesystem($credentials) ) {630 request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again631 return;632 }633 634 if ( $wp_filesystem->errors->get_error_code() ) {635 foreach ( $wp_filesystem->errors->get_error_messages() as $message )636 show_message($message);637 return;638 }639 640 $result = wp_install_theme( $download_url, 'show_message' );641 642 if ( is_wp_error($result) ) {643 show_message($result);644 show_message( __('Installation Failed') );645 } else {646 show_message( sprintf(__('Successfully installed the theme <strong>%s %s</strong>.'), $theme_information->name, $theme_information->version) );647 $theme_file = $result;648 649 $install_actions = apply_filters('install_theme_complete_actions', array(650 //'activate_theme' => '<a href="' . wp_nonce_url('themes.php?action=activate&theme=' . $theme_file, 'activate-theme_' . $theme_file) . '" title="' . attribute_escape(__('Activate this theme')) . '" target="_parent">' . __('Activate Theme') . '</a>',651 'themes_page' => '<a href="' . admin_url('themes.php') . '" title="' . attribute_escape(__('Return to Themes page')) . '" target="_parent">' . __('Return to Themes page') . '</a>'652 ), $theme_information, $theme_file);653 if ( ! empty($install_actions) )654 show_message('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$install_actions));655 }656 }657 658 /**659 * Install a theme from a local file.660 *661 * @since 2.8.0662 *663 * @param string $package Local Theme zip664 * @param string $filename Optional. Original filename665 * @param object $theme_information Optional. Theme information666 */667 function do_theme_install_local_package($package, $filename = '') {668 global $wp_filesystem;669 670 if ( empty($package) ) {671 show_message( __('No theme specified') );672 return;673 }674 675 if ( empty($filename) )676 $filename = basename($package);677 678 $url = 'theme-install.php?tab=upload';679 $url = add_query_arg(array('package' => $filename), $url);680 681 $url = wp_nonce_url($url, 'theme-upload');682 if ( false === ($credentials = request_filesystem_credentials($url)) )683 return;684 685 if ( ! WP_Filesystem($credentials) ) {686 request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again687 return;688 }689 690 if ( $wp_filesystem->errors->get_error_code() ) {691 foreach ( $wp_filesystem->errors->get_error_messages() as $message )692 show_message($message);693 return;694 }695 696 $result = wp_install_theme_local_package( $package, 'show_message' );697 698 if ( is_wp_error($result) ) {699 show_message($result);700 show_message( __('Installation Failed') );701 } else {702 show_message( __('Successfully installed the theme.') );703 $theme_file = $result;704 705 $install_actions = apply_filters('install_theme_complete_actions', array(706 //'activate_theme' => '<a href="' . wp_nonce_url('themes.php?action=activate&theme=' . $theme_file, 'activate-theme_' . $theme_file) . '" title="' . __('Activate this theme') . '" target="_parent">' . __('Activate Theme') . '</a>',707 'themes_page' => '<a href="' . admin_url('themes.php') . '" title="' . __('Goto themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>'708 ), array(), $theme_file);709 if ( ! empty($install_actions) )710 show_message('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$install_actions));711 }712 }713 714 /**715 * Install theme.716 *717 * @since 2.8.0718 *719 * @param string $package720 * @param string $feedback Optional.721 * @return mixed.722 */723 function wp_install_theme($package, $feedback = '') {724 global $wp_filesystem;725 726 if ( !empty($feedback) )727 add_filter('install_feedback', $feedback);728 729 // Is a filesystem accessor setup?730 if ( ! $wp_filesystem || ! is_object($wp_filesystem) )731 WP_Filesystem();732 733 if ( ! is_object($wp_filesystem) )734 return new WP_Error('fs_unavailable', __('Could not access filesystem.'));735 736 if ( $wp_filesystem->errors->get_error_code() )737 return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);738 739 // Get the base theme folder740 $themes_dir = $wp_filesystem->wp_themes_dir();741 if ( empty($themes_dir) )742 return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress themes directory.'));743 744 // And the same for the Content directory.745 $content_dir = $wp_filesystem->wp_content_dir();746 if ( empty($content_dir) )747 return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress content directory (wp-content).'));748 749 $themes_dir = trailingslashit( $themes_dir );750 $content_dir = trailingslashit( $content_dir );751 752 if ( empty($package) )753 return new WP_Error('no_package', __('Install package not available.'));754 755 // Download the package756 apply_filters('install_feedback', sprintf(__('Downloading theme package from %s'), $package));757 $download_file = download_url($package);758 759 if ( is_wp_error($download_file) )760 return new WP_Error('download_failed', __('Download failed.'), $download_file->get_error_message());761 762 $working_dir = $content_dir . 'upgrade/' . basename($package, '.zip');763 764 // Clean up working directory765 if ( $wp_filesystem->is_dir($working_dir) )766 $wp_filesystem->delete($working_dir, true);767 768 apply_filters('install_feedback', __('Unpacking the theme package'));769 // Unzip package to working directory770 $result = unzip_file($download_file, $working_dir);771 772 // Once extracted, delete the package773 @unlink($download_file);774 775 if ( is_wp_error($result) ) {776 $wp_filesystem->delete($working_dir, true);777 return $result;778 }779 780 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the theme781 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );782 783 if ( $wp_filesystem->exists( $themes_dir . $filelist[0] ) ) {784 $wp_filesystem->delete($working_dir, true);785 return new WP_Error('install_folder_exists', __('Folder already exists.'), $filelist[0] );786 }787 788 apply_filters('install_feedback', __('Installing the theme'));789 // Copy new version of theme into place.790 $result = copy_dir($working_dir, $themes_dir);791 if ( is_wp_error($result) ) {792 $wp_filesystem->delete($working_dir, true);793 return $result;794 }795 796 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the theme797 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );798 799 // Remove working directory800 $wp_filesystem->delete($working_dir, true);801 802 if ( empty($filelist) )803 return false; //We couldnt find any files in the working dir, therefor no theme installed? Failsafe backup.804 805 //TODO: TODO: TODO806 $stylesheet = $filelist[0];807 // $theme = get_themes('/' . $folder); //Ensure to pass with leading slash //TODO: TODO: TODO808 // $themefiles = array_keys($theme); //Assume the requested theme is the first in the list809 810 //Return the theme files name.811 return $stylesheet; //$folder . '/' . $themefiles[0];812 }813 814 /**815 * Install theme from local package816 *817 * @since 2.8.0818 *819 * @param string $package820 * @param string $feedback Optional.821 * @return mixed.822 */823 function wp_install_theme_local_package($package, $feedback = '') {824 global $wp_filesystem;825 826 if ( !empty($feedback) )827 add_filter('install_feedback', $feedback);828 829 // Is a filesystem accessor setup?830 if ( ! $wp_filesystem || ! is_object($wp_filesystem) )831 WP_Filesystem();832 833 if ( ! is_object($wp_filesystem) )834 return new WP_Error('fs_unavailable', __('Could not access filesystem.'));835 836 if ( $wp_filesystem->errors->get_error_code() )837 return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);838 839 //Get the base theme folder840 $themes_dir = $wp_filesystem->wp_themes_dir();841 if ( empty($themes_dir) )842 return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress themes directory.'));843 844 //And the same for the Content directory.845 $content_dir = $wp_filesystem->wp_content_dir();846 if ( empty($content_dir) )847 return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress content directory (wp-content).'));848 849 $themes_dir = trailingslashit( $themes_dir );850 $content_dir = trailingslashit( $content_dir );851 852 if ( empty($package) )853 return new WP_Error('no_package', __('Install package not available.'));854 855 $working_dir = $content_dir . 'upgrade/' . basename($package, '.zip');856 857 858 // Clean up working directory859 if ( $wp_filesystem->is_dir($working_dir) )860 $wp_filesystem->delete($working_dir, true);861 862 apply_filters('install_feedback', __('Unpacking the theme package'));863 // Unzip package to working directory864 $result = unzip_file($package, $working_dir);865 866 // Once extracted, delete the package867 unlink($package);868 869 if ( is_wp_error($result) ) {870 $wp_filesystem->delete($working_dir, true);871 return $result;872 }873 874 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the theme875 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );876 877 if ( $wp_filesystem->exists( $themes_dir . $filelist[0] ) ) {878 $wp_filesystem->delete($working_dir, true);879 return new WP_Error('install_folder_exists', __('Folder already exists.'), $filelist[0] );880 }881 882 apply_filters('install_feedback', __('Installing the theme'));883 // Copy new version of theme into place.884 $result = copy_dir($working_dir, $themes_dir);885 if ( is_wp_error($result) ) {886 $wp_filesystem->delete($working_dir, true);887 return $result;888 }889 890 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the theme891 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );892 893 // Remove working directory894 $wp_filesystem->delete($working_dir, true);895 896 if ( empty($filelist) )897 return false; //We couldnt find any files in the working dir, therefor no theme installed? Failsafe backup.898 899 //TODO TODO TODO900 $stylesheet = $filelist[0];901 // $theme = get_themes('/' . $folder); //Ensure to pass with leading slash902 // $themefiles = array_keys($theme); //Assume the requested theme is the first in the list903 904 //Return the theme files name.905 return $stylsheet; //$folder . '/' . $themefiles[0];906 } -
wp-admin/includes/theme.php
72 72 return; 73 73 } 74 74 75 if ( $wp_filesystem->errors->get_error_code() ) {76 return $wp_filesystem->errors;77 }78 75 79 76 if ( ! is_object($wp_filesystem) ) 80 77 return new WP_Error('fs_unavailable', __('Could not access filesystem.')); 81 78 82 if ( $wp_filesystem->errors->get_error_code() )79 if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) 83 80 return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors); 84 81 85 82 //Get the base plugin folder -
wp-admin/includes/update-core.php
229 229 $result = copy_dir($from . '/wordpress', $to); 230 230 if ( is_wp_error($result) ) { 231 231 $wp_filesystem->delete($maintenance_file); 232 //$wp_filesystem->delete($working_dir, true); //TODO: Uncomment? This DOES mean that the new files are available in the upgrade folder if it fails.232 $wp_filesystem->delete($working_dir, true); 233 233 return $result; 234 234 } 235 235 -
wp-admin/includes/update.php
167 167 add_action( 'after_plugin_row', 'wp_plugin_update_row', 10, 2 ); 168 168 169 169 function wp_update_plugin($plugin, $feedback = '') { 170 global $wp_filesystem;171 170 172 171 if ( !empty($feedback) ) 173 172 add_filter('update_feedback', $feedback); 174 173 175 // Is an update available? 176 $current = get_transient( 'update_plugins' ); 177 if ( !isset( $current->response[ $plugin ] ) ) 178 return new WP_Error('up_to_date', __('The plugin is at the latest version.')); 179 180 // Is a filesystem accessor setup? 181 if ( ! $wp_filesystem || ! is_object($wp_filesystem) ) 182 WP_Filesystem(); 183 184 if ( ! is_object($wp_filesystem) ) 185 return new WP_Error('fs_unavailable', __('Could not access filesystem.')); 186 187 if ( $wp_filesystem->errors->get_error_code() ) 188 return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors); 189 190 //Get the base plugin folder 191 $plugins_dir = $wp_filesystem->wp_plugins_dir(); 192 if ( empty($plugins_dir) ) 193 return new WP_Error('fs_no_plugins_dir', __('Unable to locate WordPress Plugin directory.')); 194 195 //And the same for the Content directory. 196 $content_dir = $wp_filesystem->wp_content_dir(); 197 if( empty($content_dir) ) 198 return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).')); 199 200 $plugins_dir = trailingslashit( $plugins_dir ); 201 $content_dir = trailingslashit( $content_dir ); 202 203 // Get the URL to the zip file 204 $r = $current->response[ $plugin ]; 205 206 if ( empty($r->package) ) 207 return new WP_Error('no_package', __('Upgrade package not available.')); 208 209 // Download the package 210 $package = $r->package; 211 apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package)); 212 $download_file = download_url($package); 213 214 if ( is_wp_error($download_file) ) 215 return new WP_Error('download_failed', __('Download failed.'), $download_file->get_error_message()); 216 217 $working_dir = $content_dir . 'upgrade/' . basename($plugin, '.php'); 218 219 // Clean up working directory 220 if ( $wp_filesystem->is_dir($working_dir) ) 221 $wp_filesystem->delete($working_dir, true); 222 223 apply_filters('update_feedback', __('Unpacking the update')); 224 // Unzip package to working directory 225 $result = unzip_file($download_file, $working_dir); 226 227 // Once extracted, delete the package 228 unlink($download_file); 229 230 if ( is_wp_error($result) ) { 231 $wp_filesystem->delete($working_dir, true); 232 return $result; 233 } 234 235 if ( is_plugin_active($plugin) ) { 236 //Deactivate the plugin silently, Prevent deactivation hooks from running. 237 apply_filters('update_feedback', __('Deactivating the plugin')); 238 deactivate_plugins($plugin, true); 239 } 240 241 // Remove the existing plugin. 242 apply_filters('update_feedback', __('Removing the old version of the plugin')); 243 $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) ); 244 245 // If plugin is in its own directory, recursively delete the directory. 246 if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory seperator AND that its not the root plugin folder 247 $deleted = $wp_filesystem->delete($this_plugin_dir, true); 248 else 249 $deleted = $wp_filesystem->delete($plugins_dir . $plugin); 250 251 if ( ! $deleted ) { 252 $wp_filesystem->delete($working_dir, true); 253 return new WP_Error('delete_failed', __('Could not remove the old plugin')); 254 } 255 256 apply_filters('update_feedback', __('Installing the latest version')); 257 // Copy new version of plugin into place. 258 $result = copy_dir($working_dir, $plugins_dir); 259 if ( is_wp_error($result) ) { 260 $wp_filesystem->delete($working_dir, true); 261 return $result; 262 } 263 264 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin 265 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) ); 266 267 // Remove working directory 268 $wp_filesystem->delete($working_dir, true); 269 270 // Force refresh of plugin update information 271 delete_transient('update_plugins'); 272 273 if( empty($filelist) ) 274 return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup. 275 276 $folder = $filelist[0]; 277 $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash 278 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list 279 280 return $folder . '/' . $pluginfiles[0]; 174 include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 175 $upgrader = new Plugin_Upgrader(); 176 return $upgrader->upgrade($plugin); 281 177 } 282 178 283 179 function wp_update_theme($theme, $feedback = '') { 284 global $wp_filesystem; 285 180 286 181 if ( !empty($feedback) ) 287 182 add_filter('update_feedback', $feedback); 288 183 289 // Is an update available? 290 $current = get_transient( 'update_themes' ); 291 if ( !isset( $current->response[ $theme ] ) ) 292 return new WP_Error('up_to_date', __('The theme is at the latest version.')); 293 294 $r = $current->response[ $theme ]; 295 296 $themes = get_themes(); 297 foreach ( (array) $themes as $this_theme ) { 298 if ( $this_theme['Stylesheet'] == $theme ) { 299 $theme_directory = preg_replace('!^/themes/!i', '', $this_theme['Stylesheet Dir']); 300 break; 301 } 302 } 303 unset($themes); 304 305 if ( empty($theme_directory) ) 306 return new WP_Error('theme_non_existant', __('Theme does not exist.')); 307 308 // Is a filesystem accessor setup? 309 if ( ! $wp_filesystem || ! is_object($wp_filesystem) ) 310 WP_Filesystem(); 311 312 if ( ! is_object($wp_filesystem) ) 313 return new WP_Error('fs_unavailable', __('Could not access filesystem.')); 314 315 if ( $wp_filesystem->errors->get_error_code() ) 316 return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors); 317 318 //Get the base plugin folder 319 $themes_dir = $wp_filesystem->wp_themes_dir(); 320 if ( empty($themes_dir) ) 321 return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress Theme directory.')); 322 323 //And the same for the Content directory. 324 $content_dir = $wp_filesystem->wp_content_dir(); 325 if( empty($content_dir) ) 326 return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).')); 327 328 $themes_dir = trailingslashit( $themes_dir ); 329 $content_dir = trailingslashit( $content_dir ); 330 331 if ( empty($r->package) ) 332 return new WP_Error('no_package', __('Upgrade package not available.')); 333 334 // Download the package 335 apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $r['package'])); 336 $download_file = download_url($r['package']); 337 338 if ( is_wp_error($download_file) ) 339 return new WP_Error('download_failed', __('Download failed.'), $download_file->get_error_message()); 340 341 $working_dir = $content_dir . 'upgrade/' . basename($theme_directory); 342 343 // Clean up working directory 344 if ( $wp_filesystem->is_dir($working_dir) ) 345 $wp_filesystem->delete($working_dir, true); 346 347 apply_filters('update_feedback', __('Unpacking the update')); 348 // Unzip package to working directory 349 $result = unzip_file($download_file, $working_dir); 350 351 // Once extracted, delete the package 352 unlink($download_file); 353 354 if ( is_wp_error($result) ) { 355 $wp_filesystem->delete($working_dir, true); 356 return $result; 357 } 358 359 //TODO: Is theme currently active? If so, set default theme 360 /* 361 if ( is_plugin_active($plugin) ) { 362 //Deactivate the plugin silently, Prevent deactivation hooks from running. 363 apply_filters('update_feedback', __('Deactivating the plugin')); 364 deactivate_plugins($plugin, true); 365 }*/ 366 367 // Remove the existing plugin. 368 apply_filters('update_feedback', __('Removing the old version of the theme')); 369 $deleted = $wp_filesystem->delete($themes_dir . $theme_directory, true); 370 371 if ( ! $deleted ) { 372 $wp_filesystem->delete($working_dir, true); 373 return new WP_Error('delete_failed', __('Could not remove the old plugin')); 374 } 375 376 apply_filters('update_feedback', __('Installing the latest version')); 377 // Copy new version of plugin into place. 378 $result = copy_dir($working_dir, $themes_dir); 379 if ( is_wp_error($result) ) { 380 $wp_filesystem->delete($working_dir, true); 381 return $result; 382 } 383 384 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin 385 //$filelist = array_keys( $wp_filesystem->dirlist($working_dir) ); 386 387 // Remove working directory 388 $wp_filesystem->delete($working_dir, true); 389 390 // Force refresh of plugin update information 391 delete_transient('update_themes'); 392 393 /*if( empty($filelist) ) 394 return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup. 395 396 $folder = $filelist[0]; 397 $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash 398 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list 399 400 return $folder . '/' . $pluginfiles[0];*/ 184 include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 185 $upgrader = new Theme_Upgrader(); 186 return $upgrader->upgrade($theme); 401 187 } 402 188 403 189 404 190 function wp_update_core($current, $feedback = '') { 405 global $wp_filesystem; 406 407 @set_time_limit( 300 ); 408 191 409 192 if ( !empty($feedback) ) 410 193 add_filter('update_feedback', $feedback); 411 194 412 // Is an update available?413 if ( !isset( $current->response ) || $current->response == 'latest' )414 return new WP_Error('up_to_date', __('WordPress is at the latest version.'));195 include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 196 $upgrader = new Core_Upgrader(); 197 return $upgrader->upgrade($current); 415 198 416 // Is a filesystem accessor setup?417 if ( ! $wp_filesystem || ! is_object($wp_filesystem) )418 WP_Filesystem();419 420 if ( ! is_object($wp_filesystem) )421 return new WP_Error('fs_unavailable', __('Could not access filesystem.'));422 423 if ( $wp_filesystem->errors->get_error_code() )424 return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);425 426 // Get the base WP folder427 $wp_dir = $wp_filesystem->abspath();428 if ( empty($wp_dir) )429 return new WP_Error('fs_no_wp_dir', __('Unable to locate WordPress directory.'));430 431 // And the same for the Content directory.432 $content_dir = $wp_filesystem->wp_content_dir();433 if( empty($content_dir) )434 return new WP_Error('fs_no_content_dir', __('Unable to locate WordPress Content directory (wp-content).'));435 436 $wp_dir = trailingslashit( $wp_dir );437 $content_dir = trailingslashit( $content_dir );438 439 // Get the URL to the zip file440 $package = $current->package;441 442 // Download the package443 apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package));444 $download_file = download_url($package);445 446 if ( is_wp_error($download_file) )447 return new WP_Error('download_failed', __('Download failed.'), $download_file->get_error_message());448 449 $working_dir = $content_dir . 'upgrade/core';450 // Clean up working directory451 if ( $wp_filesystem->is_dir($working_dir) ) {452 $wp_filesystem->delete($working_dir, true);453 }454 455 apply_filters('update_feedback', __('Unpacking the core update'));456 // Unzip package to working directory457 $result = unzip_file($download_file, $working_dir);458 // Once extracted, delete the package459 unlink($download_file);460 461 if ( is_wp_error($result) ) {462 $wp_filesystem->delete($working_dir, true);463 return $result;464 }465 466 // Copy update-core.php from the new version into place.467 if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {468 $wp_filesystem->delete($working_dir, true);469 return new WP_Error('copy_failed', __('Could not copy files'));470 }471 $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);472 473 require(ABSPATH . 'wp-admin/includes/update-core.php');474 475 return update_core($working_dir, $wp_dir);476 199 } 477 200 478 201 function maintenance_nag() { -
wp-admin/plugin-install.php
24 24 25 25 //These are the tabs which are shown on the page, 26 26 $tabs = array(); 27 $tabs['dashboard'] = __('Search'); //TODO: Better name?27 $tabs['dashboard'] = __('Search'); 28 28 if ( 'search' == $tab ) 29 29 $tabs['search'] = __('Search Results'); 30 30 $tabs['upload'] = __('Upload'); … … 33 33 $tabs['new'] = __('Newest'); 34 34 $tabs['updated'] = __('Recently Updated'); 35 35 36 $nonmenu_tabs = array(' install', 'plugin-information', 'do_upload'); //Valid actions to perform which do not have a Menu item.36 $nonmenu_tabs = array('plugin-information'); //Valid actions to perform which do not have a Menu item. 37 37 38 38 $tabs = apply_filters('install_plugins_tabs', $tabs ); 39 39 $nonmenu_tabs = apply_filters('install_plugins_nonmenu_tabs', $nonmenu_tabs); … … 62 62 foreach ( (array)$tabs as $action => $text ) { 63 63 $sep = ( end($tabs) != $text ) ? ' | ' : ''; 64 64 $class = ( $action == $tab ) ? ' class="current"' : ''; 65 $href = admin_url('plugin-install.php?tab=' . $action);65 $href = admin_url('plugin-install.php?tab=' . $action); 66 66 echo "\t\t<li><a href='$href'$class>$text</a>$sep</li>\n"; 67 67 } 68 68 ?> … … 71 71 <?php do_action('install_plugins_' . $tab, $paged); ?> 72 72 </div> 73 73 <?php 74 include('admin-footer.php'); 75 ?> 74 include('admin-footer.php'); 75 No newline at end of file -
wp-admin/theme-install.php
35 35 $tabs['new'] = __('Newest'); 36 36 $tabs['updated'] = __('Recently Updated'); 37 37 38 $nonmenu_tabs = array(' install', 'theme-information', 'do_upload'); //Valid actions to perform which do not have a Menu item.38 $nonmenu_tabs = array('theme-information'); //Valid actions to perform which do not have a Menu item. 39 39 40 40 $tabs = apply_filters('install_themes_tabs', $tabs ); 41 41 $nonmenu_tabs = apply_filters('install_themes_nonmenu_tabs', $nonmenu_tabs); -
wp-includes/update.php
112 112 113 113 $new_option = new stdClass; 114 114 $new_option->last_checked = time(); 115 $timeout = 'load-plugins.php' == current_filter() ? 360 : 43200; //Check for updated every 60 minutes if hitting the themes page, Else, check every 12 hours115 $timeout = 'load-plugins.php' == current_filter() ? 3600 : 43200; //Check for updated every 60 minutes if hitting the themes page, Else, check every 12 hours 116 116 $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked ); 117 117 118 118 $plugin_changed = false; … … 195 195 196 196 $new_option = new stdClass; 197 197 $new_option->last_checked = time( ); 198 $timeout = 'load-themes.php' == current_filter() ? 360 : 43200; //Check for updated every 60 minutes if hitting the themes page, Else, check every 12 hours198 $timeout = 'load-themes.php' == current_filter() ? 3600 : 43200; //Check for updated every 60 minutes if hitting the themes page, Else, check every 12 hours 199 199 $time_not_changed = isset( $current_theme->last_checked ) && $timeout > ( time( ) - $current_theme->last_checked ); 200 200 201 201 if( $time_not_changed ) -
wp-admin/includes/class-wp-upgrader.php
1 <?php 2 /** 3 * This file is an attempt at an abstracted version of the plugin/theme/core installer/upgrader which can be used interchangably for all uses needed within WordPress. 4 * It is designed to be as flexible as possible, but some logic may seem rather, crazy to say the least. 5 * Yes, this header is designed to be replaced before commiting, Hopefully i'll get some proper documentation in here. 6 * 7 * This File obviously needs some new PHPDoc, However: 8 * Tested: 9 * Theme/Plugin Upgrades/Installs 10 * FTP Extension, FTP Sockets, Direct. 11 * Untested: 12 * Core Update (Logic seemed correct to me) 13 * SSH2 Layer. 14 * 15 * TODO: Remove this commentblock and replace with some better docs. 16 */ 17 18 class WP_Upgrader { 19 var $strings = array(); 20 var $skin = null; 21 var $result = array(); 22 23 function WP_Upgrader(&$skin = null) { 24 return __construct($skin); 25 } 26 function __construct(&$skin = null) { 27 if ( null == $skin ) 28 $this->skin = new WP_Upgrader_Skin(); 29 $this->skin = $skin; 30 $this->skin->set_upgrader($this); 31 } 32 33 function generic_strings() { 34 $this->strings['bad_request'] = __('Invalid Data provided.'); 35 $this->strings['fs_unavailable'] = __('Could not access filesystem.'); 36 $this->strings['fs_error'] = __('Filesystem error'); 37 $this->strings['fs_no_root_dir'] = __('Unable to locate WordPress Root directory.'); 38 $this->strings['fs_no_content_dir'] = __('Unable to locate WordPress Content directory (wp-content).'); 39 $this->strings['fs_no_plugins_dir'] = __('Unable to locate WordPress Plugin directory.'); 40 $this->strings['fs_no_themes_dir'] = __('Unable to locate WordPress Theme directory.'); 41 $this->strings['fs_no_folder'] = __('Unable to locate needed folder (%s).'); 42 43 $this->strings['download_failed'] = __('Download failed.'); 44 $this->strings['installing_package'] = __('Installing the latest version.'); 45 $this->strings['folder_exists'] = __('Destination folder already exists.'); 46 $this->strings['mkdir_failed'] = __('Could not create directory.'); 47 $this->strings['bad_package'] = __('Incompatible Archive'); 48 49 $this->strings['maintenance_start'] = __('Enabling Maintenance mode.'); 50 $this->strings['maintenance_end'] = __('Disabling Maintenance mode.'); 51 } 52 53 function fs_connect( $directories = array() ) { 54 global $wp_filesystem; 55 56 if ( false === ($credentials = $this->skin->request_filesystem_credentials()) ) //request_filesystem_credentials($url)) ) 57 return false; 58 59 if ( ! WP_Filesystem($credentials) ) { 60 $error = true; 61 if ( is_object($wp_filesystem) && $wp_filesystem->errors->get_error_code() ) 62 $error = $wp_filesystem->errors; 63 $this->skin->request_filesystem_credentials($error); //Failed to connect, Error and request again 64 return false; 65 } 66 67 if ( ! is_object($wp_filesystem) ) 68 return new WP_Error('fs_unavailable', $this->strings['fs_unavailable'] ); 69 70 if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) 71 return new WP_Error('fs_error', $this->strings['fs_error'], $wp_filesystem->errors); 72 73 foreach ( (array)$directories as $dir ) { 74 if ( ABSPATH == $dir && ! $wp_filesystem->abspath() ) 75 return new WP_Error('fs_no_root_dir', $this->strings['fs_no_root_dir']); 76 77 elseif ( WP_CONTENT_DIR == $dir && ! $wp_filesystem->wp_content_dir() ) 78 return new WP_Error('fs_no_content_dir', $this->strings['fs_no_content_dir']); 79 80 elseif ( WP_PLUGIN_DIR == $dir && ! $wp_filesystem->wp_plugins_dir() ) 81 return new WP_Error('fs_no_plugins_dir', $this->strings['fs_no_plugins_dir']); 82 83 elseif ( WP_CONTENT_DIR . '/themes' == $dir && ! $wp_filesystem->find_folder(WP_CONTENT_DIR . '/themes') ) 84 return new WP_Error('fs_no_themes_dir', $this->strings['fs_no_themes_dir']); 85 86 elseif ( ! $wp_filesystem->find_folder($dir) ) 87 return new WP_Error('fs_no_folder', sprintf($strings['fs_no_folder'], $dir)); 88 } 89 return true; 90 } //end fs_connect(); 91 92 function download_package($package) { 93 94 if ( ! preg_match('!^(http|https|ftp)://!i', $package) && file_exists($package) ) //Local file or remote? 95 return $package; //must be a local file.. 96 97 if ( empty($package) ) 98 return new WP_Error('no_package', $this->strings['no_package']); 99 100 $this->skin->feedback('downloading_package', $package); 101 102 $download_file = download_url($package); 103 104 if ( is_wp_error($download_file) ) 105 return new WP_Error('download_failed', $this->strings['download_failed'], $download_file->get_error_message()); 106 107 return $download_file; 108 } 109 110 function unpack_package($package, $delete_package = true) { 111 global $wp_filesystem; 112 113 $this->skin->feedback('unpack_package'); 114 115 $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/'; 116 117 //Clean up contents of upgrade directory beforehand. 118 $upgrade_files = $wp_filesystem->dirlist($upgrade_folder); 119 if ( !empty($upgrade_files) ) { 120 foreach ( $upgrade_files as $file ) 121 $wp_filesystem->delete($upgrade_folder . $file['name'], true); 122 } 123 124 //We need a working directory 125 $working_dir = $upgrade_folder . basename($package, '.zip'); 126 127 // Clean up working directory 128 if ( $wp_filesystem->is_dir($working_dir) ) 129 $wp_filesystem->delete($working_dir, true); 130 131 // Unzip package to working directory 132 $result = unzip_file($package, $working_dir); //TODO optimizations, Copy when Move/Rename would suffice? 133 134 // Once extracted, delete the package if required. 135 if ( $delete_package ) 136 unlink($package); 137 138 if ( is_wp_error($result) ) { 139 $wp_filesystem->delete($working_dir, true); 140 return $result; 141 } 142 143 return $working_dir; 144 } 145 146 function install_package($args = array()) { 147 global $wp_filesystem; 148 $defaults = array( 'source' => '', 'destination' => '', //Please always pass these 149 'clear_destination' => false, 'clear_working' => false, 150 'hook_extra' => array()); 151 152 $args = wp_parse_args($args, $defaults); 153 extract($args); 154 155 @set_time_limit( 300 ); 156 157 if ( empty($source) || empty($destination) ) 158 return new WP_Error('bad_request', $this->strings['bad_request']); 159 160 $this->skin->feedback('installing_package'); 161 162 $res = apply_filters('upgrader_pre_install', true, $hook_extra); 163 if ( is_wp_error($res) ) 164 return $res; 165 166 //Retain the Original source and destinations 167 $remote_source = $source; 168 $local_destination = $destination; 169 170 $source_files = array_keys( $wp_filesystem->dirlist($remote_source) ); 171 $remote_destination = $wp_filesystem->find_folder($local_destination); 172 173 //Locate which directory to copy to the new folder, This is based on the actual folder holding the files. 174 if ( 1 == count($source_files) && $wp_filesystem->is_dir( trailingslashit($source) . $source_files[0] . '/') ) //Only one folder? Then we want its contents. 175 $source = trailingslashit($source) . trailingslashit($source_files[0]); 176 elseif ( count($source_files) == 0 ) 177 return new WP_Error('bad_package', $this->strings['bad_package']); //There are no files? 178 //else //Its only a single file, The upgrader will use the foldername of this file as the destination folder. foldername is based on zip filename. 179 180 //Hook ability to change the source file location.. 181 $source = apply_filters('upgrader_source_selection', $source, $remote_source, $this); 182 if ( is_wp_error($source) ) 183 return $source; 184 185 //Has the source location changed? If so, we need a new source_files list. 186 if ( $source !== $remote_source ) 187 $source_files = array_keys( $wp_filesystem->dirlist($source) ); 188 189 //Protection against deleting files in any important base directories. 190 if ( in_array( $destination, array(ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes') ) ) { 191 $remote_destination = trailingslashit($remote_destination) . trailingslashit(basename($source)); 192 $destination = trailingslashit($destination) . trailingslashit(basename($source)); 193 } 194 195 //If we're not clearing the destination folder, and something exists there allready, Bail. 196 if ( ! $clear_destination && $wp_filesystem->exists($remote_destination) ) { 197 $wp_filesystem->delete($remote_source, true); //Clear out the source files. 198 return new WP_Error('folder_exists', $this->strings['folder_exists'], $remote_destination ); 199 } else if ( $clear_destination ) { 200 //We're going to clear the destination if theres something there 201 $this->skin->feedback('remove_old'); 202 203 $removed = true; 204 if ( $wp_filesystem->exists($remote_destination) ) 205 $removed = $wp_filesystem->delete($remote_destination, true); 206 207 $removed = apply_filters('upgrader_clear_destination', $removed, $local_destination, $remote_destination, $hook_extra); 208 209 if ( is_wp_error($removed) ) 210 return $removed; 211 else if ( ! $removed ) 212 return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']); 213 } 214 215 //Create destination if needed 216 if ( !$wp_filesystem->exists($remote_destination) ) 217 if ( !$wp_filesystem->mkdir($remote_destination) ) 218 return new WP_Error('mkdir_failed', $this->strings['mkdir_failed'], $remote_destination); 219 220 // Copy new version of item into place. 221 $result = copy_dir($source, $remote_destination); 222 if ( is_wp_error($result) ) { 223 if ( $clear_working ) 224 $wp_filesystem->delete($remote_source, true); 225 return $result; 226 } 227 228 //Clear the Working folder? 229 if ( $clear_working ) 230 $wp_filesystem->delete($remote_source, true); 231 232 $destination_name = basename( str_replace($local_destination, '', $destination) ); 233 if ( '.' == $destination_name ) 234 $destination_name = ''; 235 236 $this->result = compact('local_source', 'source', 'source_name', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination', 'delete_source_dir'); 237 238 $res = apply_filters('upgrader_post_install', true, $hook_extra, $this->result); 239 if ( is_wp_error($res) ) { 240 $this->result = $res; 241 return $res; 242 } 243 244 //Bombard the calling function will all the info which we've just used. 245 return $this->result; 246 } 247 248 function run($options) { 249 250 $defaults = array( 'package' => '', //Please always pass this. 251 'destination' => '', //And this 252 'clear_destination' => false, 253 'clear_working' => true, 254 'hook_extra' => array() //Pass any extra $hook_extra args here, this will be passed to any hooked filters. 255 ); 256 257 $options = wp_parse_args($options, $defaults); 258 extract($options); 259 260 $this->skin->header(); 261 $this->skin->before(); 262 263 //Connect to the Filesystem first. 264 $res = $this->fs_connect( array(WP_CONTENT_DIR, $destination) ); 265 if ( ! $res ) //Mainly for non-connected filesystem. 266 return false; 267 268 if ( is_wp_error($res) ) { 269 $this->skin->error($res); 270 return $res; 271 } 272 273 //Download the package (Note, This just returns the filename of the file if the package is a local file) 274 $download = $this->download_package( $package ); 275 if ( is_wp_error($download) ) { 276 $this->skin->error($download); 277 return $download; 278 } 279 280 //Unzip's the file into a temporary directory 281 $working_dir = $this->unpack_package( $download ); 282 if ( is_wp_error($working_dir) ) { 283 $this->skin->error($working_dir); 284 return $working_dir; 285 } 286 287 //With the given options, this installs it to the destination directory. 288 $result = $this->install_package( array( 289 'source' => $working_dir, 290 'destination' => $destination, 291 'clear_destination' => $clear_destination, 292 'clear_working' => $clear_working, 293 'hook_extra' => $hook_extra 294 ) ); 295 $this->skin->set_result($result); 296 if ( is_wp_error($result) ) { 297 $this->skin->error($result); 298 $this->skin->feedback('process_failed'); 299 } else { 300 //Install Suceeded 301 $this->skin->feedback('process_success'); 302 } 303 $this->skin->after(); 304 $this->skin->footer(); 305 return $result; 306 } 307 308 function maintenance_mode($enable = false) { 309 global $wp_filesystem; 310 $file = $wp_filesystem->abspath() . '.maintenance'; 311 if ( $enable ) { 312 $this->skin->feedback('maintenance_start'); 313 // Create maintenance file to signal that we are upgrading 314 $maintenance_string = '<?php $upgrading = ' . time() . '; ?>'; 315 $wp_filesystem->delete($file); 316 $wp_filesystem->put_contents($file, $maintenance_string, FS_CHMOD_FILE); 317 } else if ( !$enable && $wp_filesystem->exists($file) ) { 318 $this->skin->feedback('maintenance_end'); 319 $wp_filesystem->delete($file); 320 } 321 } 322 323 } 324 325 class Plugin_Upgrader extends WP_Upgrader { 326 327 var $result; 328 329 function upgrade_strings() { 330 $this->generic_strings(); 331 $this->strings['up_to_date'] = __('The plugin is at the latest version.'); 332 $this->strings['no_package'] = __('Upgrade package not available.'); 333 $this->strings['downloading_package'] = __('Downloading update from %s.'); 334 $this->strings['unpack_package'] = __('Unpacking the update.'); 335 $this->strings['deactivate_plugin'] = __('Deactivating the plugin.'); 336 $this->strings['remove_old'] = __('Removing the old version of the plugin.'); 337 $this->strings['remove_old_failed'] = __('Could not remove the old plugin.'); 338 $this->strings['process_failed'] = __('Plugin upgrade Failed.'); 339 $this->strings['process_success'] = __('Plugin upgraded successfully.'); 340 } 341 342 function install_strings() { 343 $this->generic_strings(); 344 $this->strings['no_package'] = __('Install package not available.'); 345 $this->strings['downloading_package'] = __('Downloading install package from %s.'); 346 $this->strings['unpack_package'] = __('Unpacking the package.'); 347 $this->strings['installing_package'] = __('Installing the plugin.'); 348 $this->strings['process_failed'] = __('Plugin Install Failed.'); 349 $this->strings['process_success'] = __('Plugin Installed successfully.'); 350 } 351 352 function install($package) { 353 354 $this->install_strings(); 355 356 $this->run(array( 357 'package' => $package, 358 'destination' => WP_PLUGIN_DIR, 359 'clear_destination' => false, //Do not overwrite files. 360 'clear_working' => true, 361 'hook_extra' => array() 362 )); 363 364 // Force refresh of plugin update information 365 delete_transient('update_plugins'); 366 367 } 368 369 function upgrade($plugin) { 370 371 $this->upgrade_strings(); 372 373 $current = get_transient( 'update_plugins' ); 374 if ( !isset( $current->response[ $plugin ] ) ) { 375 $this->skin->error('up_to_date'); 376 return false; 377 //return new WP_Error('up_to_date', $this->strings['up_to_date']); 378 } 379 380 // Get the URL to the zip file 381 $r = $current->response[ $plugin ]; 382 383 add_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'), 10, 2); 384 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4); 385 //'source_selection' => array(&$this, 'source_selection'), //theres a track ticket to move up the directory for zip's which are made a bit differently, useful for non-.org plugins. 386 387 $this->run(array( 388 'package' => $r->package, 389 'destination' => WP_PLUGIN_DIR, 390 'clear_destination' => true, 391 'clear_working' => true, 392 'hook_extra' => array( 393 'plugin' => $plugin 394 ) 395 )); 396 397 //Cleanup our hooks, incase something else does a upgrade on this connection. 398 remove_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade')); 399 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin')); 400 401 if ( ! $this->result || is_wp_error($this->result) ) 402 return $this->result; 403 404 // Force refresh of plugin update information 405 delete_transient('update_plugins'); 406 } 407 408 //return plugin info. 409 function plugin_info() { 410 if ( ! is_array($this->result) ) 411 return false; 412 if ( empty($this->result['destination_name']) ) 413 return false; 414 415 $plugin = get_plugins('/' . $this->result['destination_name']); //Ensure to pass with leading slash 416 if ( empty($plugin) ) 417 return false; 418 419 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list 420 421 return $this->result['destination_name'] . '/' . $pluginfiles[0]; 422 } 423 424 //Hooked to pre_install 425 function deactivate_plugin_before_upgrade($return, $plugin) { 426 427 if ( is_wp_error($return) ) //Bypass. 428 return $return; 429 430 $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : ''; 431 if ( empty($plugin) ) 432 return new WP_Error('bad_request', $this->strings['bad_request']); 433 434 if ( is_plugin_active($plugin) ) { 435 $this->skin->feedback('deactivate_plugin'); 436 //Deactivate the plugin silently, Prevent deactivation hooks from running. 437 deactivate_plugins($plugin, true); 438 } 439 } 440 441 //Hooked to upgrade_clear_destination 442 function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin) { 443 global $wp_filesystem; 444 445 if ( is_wp_error($removed) ) 446 return $removed; //Pass errors through. 447 448 $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : ''; 449 if ( empty($plugin) ) 450 return new WP_Error('bad_request', $this->strings['bad_request']); 451 452 $plugins_dir = $wp_filesystem->wp_plugins_dir(); 453 $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) ); 454 455 if ( ! $wp_filesystem->exists($this_plugin_dir) ) //If its already vanished. 456 return $removed; 457 458 // If plugin is in its own directory, recursively delete the directory. 459 if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory seperator AND that its not the root plugin folder 460 $deleted = $wp_filesystem->delete($this_plugin_dir, true); 461 else 462 $deleted = $wp_filesystem->delete($plugins_dir . $plugin); 463 464 if ( ! $deleted ) 465 return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']); 466 467 return $removed; 468 } 469 } 470 471 472 class Theme_Upgrader extends WP_Upgrader { 473 474 var $result; 475 476 function upgrade_strings() { 477 $this->generic_strings(); 478 $this->strings['up_to_date'] = __('The theme is at the latest version.'); 479 $this->strings['no_package'] = __('Upgrade package not available.'); 480 $this->strings['downloading_package'] = __('Downloading update from %s.'); 481 $this->strings['unpack_package'] = __('Unpacking the update.'); 482 $this->strings['remove_old'] = __('Removing the old version of the theme.'); 483 $this->strings['remove_old_failed'] = __('Could not remove the old theme.'); 484 $this->strings['process_failed'] = __('Theme upgrade Failed.'); 485 $this->strings['process_success'] = __('Theme upgraded successfully.'); 486 } 487 488 function install_strings() { 489 $this->generic_strings(); 490 $this->strings['no_package'] = __('Install package not available.'); 491 $this->strings['downloading_package'] = __('Downloading install package from %s.'); 492 $this->strings['unpack_package'] = __('Unpacking the package.'); 493 $this->strings['installing_package'] = __('Installing the theme.'); 494 $this->strings['process_failed'] = __('Theme Install Failed.'); 495 $this->strings['process_success'] = __('Theme Installed successfully.'); 496 } 497 498 function install($package) { 499 500 $this->install_strings(); 501 502 $options = array( 503 'package' => $package, 504 'destination' => WP_CONTENT_DIR . '/themes', 505 'clear_destination' => false, //Do not overwrite files. 506 'clear_working' => true 507 ); 508 509 $this->run($options); 510 511 if ( ! $this->result || is_wp_error($this->result) ) 512 return $this->result; 513 514 // Force refresh of theme update information 515 delete_transient('update_themes'); 516 517 if ( empty($result['destination_name']) ) 518 return false; 519 else 520 return $result['destination_name']; 521 } 522 523 function upgrade($theme) { 524 525 $this->upgrade_strings(); 526 527 // Is an update available? 528 $current = get_transient( 'update_themes' ); 529 if ( !isset( $current->response[ $theme ] ) ) 530 return new WP_Error('up_to_date', $this->strings['up_to_date']); 531 532 $r = $current->response[ $theme ]; 533 534 add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2); 535 add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2); 536 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4); 537 538 $options = array( 539 'package' => $r['package'], 540 'destination' => WP_CONTENT_DIR . '/themes', 541 'clear_destination' => true, 542 'clear_working' => true, 543 'hook_extra' => array( 544 'theme' => $theme 545 ) 546 ); 547 548 $this->run($options); 549 550 if ( ! $this->result || is_wp_error($this->result) ) 551 return $this->result; 552 553 // Force refresh of theme update information 554 delete_transient('update_themes'); 555 556 return true; 557 } 558 559 function current_before($return, $theme) { 560 561 if ( is_wp_error($return) ) 562 return $return; 563 564 $theme = isset($theme['theme']) ? $theme['theme'] : ''; 565 566 if ( $theme != get_stylesheet() ) //If not current 567 return $return; 568 //Change to maintainence mode now. 569 $this->maintenance_mode(true); 570 571 return $return; 572 } 573 function current_after($return, $theme) { 574 if ( is_wp_error($return) ) 575 return $return; 576 577 $theme = isset($theme['theme']) ? $theme['theme'] : ''; 578 579 if ( $theme != get_stylesheet() ) //If not current 580 return $return; 581 582 //Ensure stylesheet name hasnt changed after the upgrade: 583 if ( $theme == get_stylesheet() && $theme != $this->result['destination_name'] ) { 584 $theme_info = $this->theme_info(); 585 $stylesheet = $this->result['destination_name']; 586 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet; 587 switch_theme($template, $stylesheet, true); 588 } 589 590 //Time to remove maintainence mode 591 $this->maintenance_mode(false); 592 return $return; 593 } 594 595 function delete_old_theme($removed, $local_destination, $remote_destination, $theme) { 596 global $wp_filesystem; 597 598 $theme = isset($theme['theme']) ? $theme['theme'] : ''; 599 600 if ( is_wp_error($removed) || empty($theme) ) 601 return $removed; //Pass errors through. 602 603 $themes_dir = $wp_filesystem->wp_themes_dir(); 604 if ( $wp_filesystem->exists( trailingslashit($themes_dir) . $theme ) ) 605 if ( ! $wp_filesystem->delete( trailingslashit($themes_dir) . $theme, true ) ) 606 return false; 607 return true; 608 } 609 610 function theme_info() { 611 if ( empty($this->result['destination_name']) ) 612 return false; 613 return get_theme_data(WP_CONTENT_DIR . '/themes/' . $this->result['destination_name'] . '/style.css'); 614 } 615 616 } 617 618 //Untested. 619 class Core_Upgrader extends WP_Upgrader { 620 621 function upgrade_strings() { 622 $this->generic_strings(); 623 $this->strings['up_to_date'] = __('WordPress is at the latest version.'); 624 $this->strings['no_package'] = __('Upgrade package not available.'); 625 $this->strings['downloading_package'] = __('Downloading update from %s.'); 626 $this->strings['unpack_package'] = __('Unpacking the update.'); 627 $this->strings['copy_failed'] = __('Could not copy files.'); 628 } 629 630 function upgrade($current) { 631 global $wp_filesystem; 632 $this->upgrade_strings(); 633 634 635 if ( !empty($feedback) ) 636 add_filter('update_feedback', $feedback); 637 638 // Is an update available? 639 if ( !isset( $current->response ) || $current->response == 'latest' ) 640 return new WP_Error('up_to_date', $this->strings['up_to_date']); 641 642 $res = $this->fs_connect( array(ABSPATH, WP_CONTENT_DIR) ); 643 if ( is_wp_error($res) ) 644 return $res; 645 646 $wp_dir = trailingslashit($wp_filesystem->abspath()); 647 648 $download = $this->download_package( $current->package ); 649 if ( is_wp_error($download) ) 650 return $download; 651 652 $working_dir = $this->unpack_package( $download ); 653 if ( is_wp_error($working_dir) ) 654 return $working_dir; 655 656 // Copy update-core.php from the new version into place. 657 if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) { 658 $wp_filesystem->delete($working_dir, true); 659 return new WP_Error('copy_failed', $this->strings['copy_failed']); 660 } 661 $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE); 662 663 require(ABSPATH . 'wp-admin/includes/update-core.php'); 664 665 return update_core($working_dir, $wp_dir); 666 } 667 668 } 669 670 671 /** 672 * Skin stuff here. 673 * ============================================ 674 * ============================================ 675 * ============================================ 676 */ 677 678 class WP_Upgrader_Skin { 679 680 var $upgrader; 681 var $done_header = false; 682 683 function WP_Upgrader_Skin($args) { 684 return __construct($args); 685 } 686 function __construct($args) { 687 $defaults = array( 'url' => '', 'nonce' => '', 'title' => '' ); 688 $this->options = wp_parse_args($args, $defaults); 689 } 690 691 function set_upgrader(&$upgrader) { 692 if ( is_object($upgrader) ) 693 $this->upgrader =& $upgrader; 694 } 695 function set_result($result) { 696 $this->result = $result; 697 } 698 699 function request_filesystem_credentials($error = false) { 700 $url = $this->options['url']; 701 if ( !empty($this->options['nonce']) ) 702 $url = wp_nonce_url($url, $this->options['nonce']); 703 return request_filesystem_credentials($url, '', $error); //Possible to bring inline, Leaving as0is for now. 704 } 705 706 function header() { 707 if ( $this->done_header ) 708 return; 709 $this->done_header = true; 710 echo '<div class="wrap">'; 711 echo screen_icon(); 712 echo '<h2>' . $this->options['title'] . '</h2>'; 713 } 714 function footer() { 715 echo '</div>'; 716 } 717 718 function error($errors) { 719 if ( ! $this->done_header ) 720 $this->header(); 721 if ( is_string($errors) ) { 722 $this->feedback($errors); 723 } elseif ( is_wp_error($errors) && $errors->get_error_code() ) { 724 foreach ( $errors->get_error_messages() as $message ) 725 $this->feedback($message); 726 } 727 } 728 729 function feedback($string) { 730 if ( isset( $this->upgrader->strings[$string]) ) 731 $string = $this->upgrader->strings[$string]; 732 733 $args = func_get_args(); 734 $args = array_splice($args, 1); 735 if ( !empty($args) ) 736 $string = vsprintf($string, $args); 737 if ( empty($string) ) 738 return; 739 show_message($string); 740 } 741 function before() {} 742 function after() {} 743 744 } 745 746 class Plugin_Upgrader_Skin extends WP_Upgrader_Skin { 747 var $plugin = ''; 748 var $plugin_active = false; 749 750 function Plugin_Upgrader_Skin($args = array()) { 751 return __construct($args); 752 } 753 754 function __construct($args = array()) { 755 $defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Upgrade Plugin') ); 756 $args = wp_parse_args($args, $defaults); 757 758 $this->plugin = $args['plugin']; 759 760 $this->plugin_active = is_plugin_active($this->plugin); 761 762 parent::__construct($args); 763 } 764 765 function after() { 766 $this->plugin = $this->upgrader->plugin_info(); 767 if( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){ 768 show_message(__('Attempting reactivation of the plugin')); 769 echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&plugin=' . $this->plugin, 'activate-plugin_' . $this->plugin) .'"></iframe>'; 770 } 771 $update_actions = array( 772 'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $this->plugin, 'activate-plugin_' . $this->plugin) . '" title="' . attribute_escape(__('Activate this plugin')) . '" target="_parent">' . __('Activate Plugin') . '</a>', 773 'plugins_page' => '<a href="' . admin_url('plugins.php') . '" title="' . attribute_escape(__('Goto plugins page')) . '" target="_parent">' . __('Return to Plugins page') . '</a>' 774 ); 775 if ( $this->plugin_active ) 776 unset( $update_actions['activate_plugin'] ); 777 if ( ! $this->result || is_wp_error($this->result) ) 778 unset( $update_actions['activate_plugin'] ); 779 780 $update_actions = apply_filters('update_plugin_complete_actions', $update_actions, $this->plugin); 781 if ( ! empty($update_actions) ) 782 $this->feedback('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$update_actions)); 783 } 784 } 785 786 787 class Plugin_Installer_Skin extends WP_Upgrader_Skin { 788 var $api; 789 var $type; 790 791 function Plugin_Installer_Skin($args = array()) { 792 return __construct($args); 793 } 794 795 function __construct($args = array()) { 796 $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' ); 797 $args = wp_parse_args($args, $defaults); 798 799 $this->type = $args['type']; 800 $this->api = isset($args['api']) ? $args['api'] : array(); 801 802 parent::__construct($args); 803 } 804 805 function before() { 806 if ( !empty($this->api) ) 807 $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version); 808 } 809 810 function after() { 811 812 $plugin_file = $this->upgrader->plugin_info(); 813 814 $install_actions = array( 815 'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . attribute_escape(__('Activate this plugin')) . '" target="_parent">' . __('Activate Plugin') . '</a>', 816 ); 817 818 if ( $this->type == 'web' ) 819 $install_actions['plugins_page'] = '<a href="' . admin_url('plugin-install.php') . '" title="' . attribute_escape(__('Return to Plugin Installer')) . '" target="_parent">' . __('Return to Plugin Installer') . '</a>'; 820 else 821 $install_actions['plugins_page'] = '<a href="' . admin_url('plugins.php') . '" title="' . attribute_escape(__('Return to Plugins page')) . '" target="_parent">' . __('Return to Plugins page') . '</a>'; 822 823 824 if ( ! $this->result || is_wp_error($this->result) ) 825 unset( $update_actions['activate_plugin'] ); 826 827 $install_actions = apply_filters('install_plugin_complete_actions', $install_actions, $this->api, $plugin_file); 828 if ( ! empty($install_actions) ) 829 $this->feedback('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$install_actions)); 830 } 831 } 832 833 class Theme_Installer_Skin extends WP_Upgrader_Skin { 834 var $api; 835 var $type; 836 837 function Theme_Installer_Skin($args = array()) { 838 return __construct($args); 839 } 840 841 function __construct($args = array()) { 842 $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' ); 843 $args = wp_parse_args($args, $defaults); 844 845 $this->type = $args['type']; 846 $this->api = isset($args['api']) ? $args['api'] : array(); 847 848 parent::__construct($args); 849 } 850 851 function before() { 852 if ( !empty($this->api) ) 853 $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the theme <strong>%s %s</strong>.'), $this->api->name, $this->api->version); 854 } 855 856 function after() { 857 if ( empty($this->upgrader->result['destination_name']) ) 858 return; 859 860 $theme_info = $this->upgrader->theme_info(); 861 if ( empty($theme_info) ) 862 return; 863 $name = $theme_info['Name']; 864 $stylesheet = $this->upgrader->result['destination_name']; 865 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet; 866 867 $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), trailingslashit(clean_url(get_option('home'))) ) ); 868 $activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template); 869 870 $install_actions = array( 871 'preview' => '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . attribute_escape(sprintf(__('Preview "%s"'), $name)) . '">' . __('Preview') . '</a>', 872 'activate' => '<a href="' . $activate_link . '" class="activatelink" title="' . attribute_escape( sprintf( __('Activate "%s"'), $name ) ) . '">' . __('Activate') . '</a>' 873 ); 874 875 if ( $this->type == 'web' ) 876 $install_actions['themes_page'] = '<a href="' . admin_url('theme-install.php') . '" title="' . attribute_escape(__('Back to Theme Installer')) . '" target="_parent">' . __('Return to Theme Installer.') . '</a>'; 877 else 878 $install_actions['themes_page'] = '<a href="' . admin_url('themes.php') . '" title="' . attribute_escape(__('Themes page')) . '" target="_parent">' . __('Return to Themes page') . '</a>'; 879 880 if ( ! $this->result || is_wp_error($this->result) ) 881 unset( $update_actions['activate'], $update_actions['preview'] ); 882 883 $install_actions = apply_filters('install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info); 884 if ( ! empty($install_actions) ) 885 $this->feedback('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$install_actions)); 886 } 887 } 888 889 class Theme_Upgrader_Skin extends WP_Upgrader_Skin { 890 var $theme = ''; 891 892 function Theme_Upgrader_Skin($args = array()) { 893 return __construct($args); 894 } 895 896 function __construct($args = array()) { 897 $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Upgrade Theme') ); 898 $args = wp_parse_args($args, $defaults); 899 900 $this->theme = $args['theme']; 901 902 parent::__construct($args); 903 } 904 905 function after() { 906 907 if ( empty($this->upgrader->result['destination_name']) ) 908 return; 909 910 $theme_info = $this->upgrader->theme_info(); 911 if ( empty($theme_info) ) 912 return; 913 $name = $theme_info['Name']; 914 $stylesheet = $this->upgrader->result['destination_name']; 915 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet; 916 917 $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), trailingslashit(clean_url(get_option('home'))) ) ); 918 $activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template); 919 920 $update_actions = array( 921 'preview' => '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . attribute_escape(sprintf(__('Preview "%s"'), $name)) . '">' . __('Preview') . '</a>', 922 'activate' => '<a href="' . $activate_link . '" class="activatelink" title="' . attribute_escape( sprintf( __('Activate "%s"'), $name ) ) . '">' . __('Activate') . '</a>', 923 'themes_page' => '<a href="' . admin_url('themes.php') . '" title="' . attribute_escape(__('Return to Themes page')) . '" target="_parent">' . __('Return to Themes page') . '</a>', 924 ); 925 if ( ( ! $this->result || is_wp_error($this->result) ) || $stylesheet == get_stylesheet() ) 926 unset($update_actions['preview'], $update_actions['activate']); 927 928 $update_actions = apply_filters('update_theme_complete_actions', $update_actions, $this->theme); 929 if ( ! empty($update_actions) ) 930 $this->feedback('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$update_actions)); 931 } 932 } 933 934 class File_Upload_Upgrader { 935 var $package; 936 var $filename; 937 938 function File_Upload_Upgrader($form, $urlholder) { 939 return __construct($form, $urlholder); 940 } 941 function __construct($form, $urlholder) { 942 if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) ) 943 wp_die($uploads['error']); 944 945 if ( empty($_FILES[$form]['name']) && empty($_GET[$urlholder]) ) 946 wp_die(__('Please select a file')); 947 948 if ( !empty($_FILES) ) 949 $this->filename = $_FILES[$form]['name']; 950 else if ( isset($_GET[$urlholder]) ) 951 $this->filename = $_GET[$urlholder]; 952 953 //Handle a newly uploaded file, Else assume its already been uploaded 954 if ( !empty($_FILES) ) { 955 $this->filename = wp_unique_filename( $uploads['basedir'], $this->filename ); 956 $this->package = $uploads['basedir'] . '/' . $this->filename; 957 958 // Move the file to the uploads dir 959 if ( false === @ move_uploaded_file( $_FILES[$form]['tmp_name'], $this->package) ) 960 wp_die( sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'])); 961 } else { 962 $this->package = $uploads['basedir'] . '/' . $this->filename; 963 } 964 } 965 }