Ticket #7395: 7395.2.diff
| File 7395.2.diff, 8.3 KB (added by DD32, 4 years ago) |
|---|
-
wp-admin/includes/file.php
482 482 if ( 0 == count($archive_files) ) 483 483 return new WP_Error('empty_archive', __('Empty archive')); 484 484 485 //Prepend another directory level if there are files in the root directory of the zip 486 foreach ( $archive_files as $archive_file ) { 487 if ( false === strpos($archive_file['filename'], '/') ) { 488 $to = trailingslashit($to) . basename($file, '.zip'); 489 break; 490 } 491 } 492 485 493 $path = explode('/', untrailingslashit($to)); 486 494 for ( $i = count($path); $i > 0; $i-- ) { //>0 = first element is empty allways for paths starting with '/' 487 495 $tmppath = implode('/', array_slice($path, 0, $i) ); … … 558 566 } 559 567 560 568 /** 569 * Locates the lowest safe directory in a Plugin folder to copy to the plugins directory. 570 * 571 * Note: Desination directory will allways be unique. 572 * 573 * @since 2.7.0 574 * 575 * @param string $from the Working directory of the plugin files 576 * @param string $to the proposed destination for the for the plugin files 577 * @return array an array of the keys 'from' and 'to' for the actual copy. 578 */ 579 function update_pluginfiles_base_dir($from, $to) { 580 $files = list_files($from); 581 582 //Remove non-php files 583 foreach ( (array)$files as $key => $file ) 584 if ( ! preg_match('!.php$!i', $file) ) 585 unset($files[$key]); 586 587 //remove non-plugin files 588 foreach ( (array)$files as $key => $file ) { 589 $details = get_plugin_data($file, false, false); 590 if ( empty($details['Name']) ) 591 unset($files[$key]); 592 } 593 594 if ( empty($files) ) 595 return false; 596 597 //Left with paths to files which ARE plugins. 598 $min_num = 100; //assume no zips with deeper paths will come along 599 $min_file = ''; 600 foreach ( (array)$files as $key => $file ) { 601 $this_num = substr_count($file, '/'); 602 if ( $this_num < $min_num ) { 603 $min_file = $file; 604 $min_num = $this_num; 605 } 606 } 607 unset($min_num); 608 609 $from = dirname($min_file); 610 //Ensure its a unique install folder, Upgrades delete the folder prior to this. 611 $to = dirname($to) . '/' . wp_unique_filename(dirname($to), basename($to)); 612 613 return compact('from', 'to'); 614 } 615 616 /** 561 617 * {@internal Missing Short Description}} 562 618 * 563 619 * @since unknown -
wp-admin/includes/plugin-install.php
745 745 return $result; 746 746 } 747 747 748 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin 748 apply_filters('install_feedback', __('Installing the plugin')); 749 749 750 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) ); 750 751 751 if( $wp_filesystem->exists( $plugins_dir . $filelist[0] ) ) { 752 $wp_filesystem->delete($working_dir, true); 753 return new WP_Error('install_folder_exists', __('Folder allready exists.'), $filelist[0] ); 754 } 752 //find base plugin directory 753 $res = update_pluginfiles_base_dir($working_dir . '/' . $filelist[0], $plugins_dir . $filelist[0]); 755 754 756 apply_filters('install_feedback', __('Installing the plugin')); 755 //Create folder if not exists. 756 if( ! $wp_filesystem->exists( $res['to'] ) ) 757 if ( ! $wp_filesystem->mkdir( $res['to'] ) ) 758 return new WP_Error('mkdir_failed', __('Could not create directory'), $res['to']); 759 757 760 // Copy new version of plugin into place. 758 $result = copy_dir($ working_dir, $plugins_dir);761 $result = copy_dir($res['from'], $res['to']); 759 762 if ( is_wp_error($result) ) { 760 763 $wp_filesystem->delete($working_dir, true); 761 764 return $result; 762 765 } 763 766 764 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin765 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );766 767 767 // Remove working directory 768 768 $wp_filesystem->delete($working_dir, true); 769 769 770 if( empty($filelist) ) 771 return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup. 772 773 $folder = $filelist[0]; 770 $folder = trailingslashit(str_replace($plugins_dir, '', $res['to'])); 774 771 $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash 775 772 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list 776 773 777 774 //Return the plugin files name. 778 return $folder . '/'. $pluginfiles[0];775 return $folder . $pluginfiles[0]; 779 776 } 780 777 781 778 /** … … 840 837 return $result; 841 838 } 842 839 843 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin 840 apply_filters('install_feedback', __('Installing the plugin')); 841 844 842 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) ); 845 843 846 if( $wp_filesystem->exists( $plugins_dir . $filelist[0] ) ) { 847 $wp_filesystem->delete($working_dir, true); 848 return new WP_Error('install_folder_exists', __('Folder allready exists.'), $filelist[0] ); 849 } 844 //find base plugin directory 845 $res = update_pluginfiles_base_dir($working_dir . '/' . $filelist[0], $plugins_dir . $filelist[0]); 850 846 851 apply_filters('install_feedback', __('Installing the plugin')); 847 //Create folder if not exists. 848 if( ! $wp_filesystem->exists( $res['to'] ) ) 849 if ( ! $wp_filesystem->mkdir( $res['to'] ) ) 850 return new WP_Error('mkdir_failed', __('Could not create directory'), $res['to']); 851 852 852 // Copy new version of plugin into place. 853 $result = copy_dir($ working_dir, $plugins_dir);853 $result = copy_dir($res['from'], $res['to']); 854 854 if ( is_wp_error($result) ) { 855 855 $wp_filesystem->delete($working_dir, true); 856 856 return $result; 857 857 } 858 858 859 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin860 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );861 862 859 // Remove working directory 863 860 $wp_filesystem->delete($working_dir, true); 864 861 865 if( empty($filelist) ) 866 return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup. 867 868 $folder = $filelist[0]; 862 $folder = trailingslashit(str_replace($plugins_dir, '', $res['to'])); 869 863 $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash 870 864 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list 871 865 872 866 //Return the plugin files name. 873 return $folder . '/'. $pluginfiles[0];867 return $folder . $pluginfiles[0]; 874 868 } 875 869 876 ?> 870 ?> 871 No newline at end of file -
wp-admin/includes/update.php
241 241 } 242 242 243 243 apply_filters('update_feedback', __('Installing the latest version')); 244 245 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) ); 246 247 //find base plugin directory 248 $res = update_pluginfiles_base_dir($working_dir . '/' . $filelist[0], $plugins_dir . $filelist[0]); 249 250 //Create folder if not exists. 251 if( ! $wp_filesystem->exists( $res['to'] ) ) 252 if ( ! $wp_filesystem->mkdir( $res['to'] ) ) 253 return new WP_Error('mkdir_failed', __('Could not create directory'), $res['to']); 254 244 255 // Copy new version of plugin into place. 245 $result = copy_dir($ working_dir, $plugins_dir);256 $result = copy_dir($res['from'], $res['to']); 246 257 if ( is_wp_error($result) ) { 247 258 $wp_filesystem->delete($working_dir, true); 248 259 return $result; 249 260 } 250 261 251 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin252 $filelist = array_keys( $wp_filesystem->dirlist($working_dir) );253 254 262 // Remove working directory 255 263 $wp_filesystem->delete($working_dir, true); 256 264 257 265 // Force refresh of plugin update information 258 266 delete_option('update_plugins'); 259 267 260 if( empty($filelist) ) 261 return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup. 262 263 $folder = $filelist[0]; 268 $folder = trailingslashit(str_replace($plugins_dir, '', $res['to'])); 264 269 $plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash 265 270 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list 266 271 267 return $folder . '/' . $pluginfiles[0]; 272 //Return the plugin files name. 273 return $folder . $pluginfiles[0]; 268 274 } 269 275 270 276 function wp_update_theme($theme, $feedback = '') {
