Ticket #7395: 7395.diff
| File 7395.diff, 4.8 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 * @since 2.7.0 572 * 573 * @param string $working_dir the Working directory of the plugin files 574 * @return string The directory from the folder to copy from. 575 */ 576 function update_pluginfiles_base_dir($working_dir) { 577 $files = list_files($working_dir); 578 //Remove non-php files 579 foreach ( (array)$files as $key => $file ) 580 if ( ! preg_match('!.php$!i', $file) ) 581 unset($files[$key]); 582 //remove non-plugin files 583 foreach ( (array)$files as $key => $file ) { 584 $details = get_plugin_data($file, false, false); 585 if ( empty($details['Name']) ) 586 unset($files[$key]); 587 } 588 if ( empty($files) ) 589 return false; 590 //Left with paths to files which ARE plugins. 591 $min_num = 100; //assume no zips with deeper paths will come along 592 $min_file = ''; 593 foreach ( (array)$files as $key => $file ) { 594 $this_num = substr_count($file, '/'); 595 if ( $this_num < $min_num ) { 596 $min_file = $file; 597 $min_num = $this_num; 598 } 599 } 600 unset($min_num); 601 return dirname(dirname($min_file)); 602 } 603 604 /** 561 605 * {@internal Missing Short Description}} 562 606 * 563 607 * @since unknown -
wp-admin/includes/plugin-install.php
752 752 } 753 753 754 754 apply_filters('install_feedback', __('Installing the plugin')); 755 756 //find base plugin directory 757 $plugin_working_dir = update_pluginfiles_base_dir($working_dir); 758 755 759 // Copy new version of plugin into place. 756 $result = copy_dir($ working_dir, $plugins_dir);760 $result = copy_dir($plugin_working_dir, $plugins_dir); 757 761 if ( is_wp_error($result) ) { 758 762 $wp_filesystem->delete($working_dir, true); 759 763 return $result; 760 764 } 761 765 762 766 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin 763 $filelist = array_keys( $wp_filesystem->dirlist($ working_dir) );767 $filelist = array_keys( $wp_filesystem->dirlist($plugin_working_dir) ); 764 768 765 769 // Remove working directory 766 770 $wp_filesystem->delete($working_dir, true); … … 847 851 } 848 852 849 853 apply_filters('install_feedback', __('Installing the plugin')); 854 855 //find base plugin directory 856 $plugin_working_dir = update_pluginfiles_base_dir($working_dir); 857 850 858 // Copy new version of plugin into place. 851 $result = copy_dir($ working_dir, $plugins_dir);859 $result = copy_dir($plugin_working_dir, $plugins_dir); 852 860 if ( is_wp_error($result) ) { 853 861 $wp_filesystem->delete($working_dir, true); 854 862 return $result; 855 863 } 856 864 857 865 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin 858 $filelist = array_keys( $wp_filesystem->dirlist($ working_dir) );866 $filelist = array_keys( $wp_filesystem->dirlist($plugin_working_dir) ); 859 867 860 868 // Remove working directory 861 869 $wp_filesystem->delete($working_dir, true); … … 871 879 return $folder . '/' . $pluginfiles[0]; 872 880 } 873 881 874 ?> 882 ?> 883 No newline at end of file -
wp-admin/includes/update.php
173 173 } 174 174 175 175 apply_filters('update_feedback', __('Installing the latest version')); 176 177 //find base plugin directory 178 $plugin_working_dir = update_pluginfiles_base_dir($working_dir); 179 176 180 // Copy new version of plugin into place. 177 $result = copy_dir($ working_dir, $plugins_dir);181 $result = copy_dir($plugin_working_dir, $plugins_dir); 178 182 if ( is_wp_error($result) ) { 179 183 $wp_filesystem->delete($working_dir, true); 180 184 return $result; 181 185 } 182 186 183 187 //Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin 184 $filelist = array_keys( $wp_filesystem->dirlist($ working_dir) );188 $filelist = array_keys( $wp_filesystem->dirlist($plugin_working_dir) ); 185 189 186 190 // Remove working directory 187 191 $wp_filesystem->delete($working_dir, true);
