Make WP_Filesystem work with new directory constants. Props DD32. fixes #7059
git-svn-id: http://svn.automattic.com/wordpress/trunk@8009 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
f3511b048c
commit
ffd63e3b33
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
class WP_Filesystem_Direct{
|
||||
class WP_Filesystem_Direct extends WP_Filesystem_Base {
|
||||
var $permission = null;
|
||||
var $errors = array();
|
||||
function WP_Filesystem_Direct($arg) {
|
||||
|
@ -13,14 +13,6 @@ class WP_Filesystem_Direct{
|
|||
function setDefaultPermissions($perm) {
|
||||
$this->permission = $perm;
|
||||
}
|
||||
function find_base_dir($path = false, $base = '.', $echo = false){
|
||||
if (!$path)
|
||||
$path = ABSPATH;
|
||||
return str_replace('\\','/',$path);
|
||||
}
|
||||
function get_base_dir($path = false, $base = '.', $echo = false){
|
||||
return $this->find_base_dir($base, $echo);
|
||||
}
|
||||
function get_contents($file) {
|
||||
return @file_get_contents($file);
|
||||
}
|
||||
|
@ -99,75 +91,6 @@ class WP_Filesystem_Direct{
|
|||
function getchmod($file) {
|
||||
return @fileperms($file);
|
||||
}
|
||||
function gethchmod($file){
|
||||
//From the PHP.net page for ...?
|
||||
$perms = $this->getchmod($file);
|
||||
if (($perms & 0xC000) == 0xC000) {
|
||||
// Socket
|
||||
$info = 's';
|
||||
} elseif (($perms & 0xA000) == 0xA000) {
|
||||
// Symbolic Link
|
||||
$info = 'l';
|
||||
} elseif (($perms & 0x8000) == 0x8000) {
|
||||
// Regular
|
||||
$info = '-';
|
||||
} elseif (($perms & 0x6000) == 0x6000) {
|
||||
// Block special
|
||||
$info = 'b';
|
||||
} elseif (($perms & 0x4000) == 0x4000) {
|
||||
// Directory
|
||||
$info = 'd';
|
||||
} elseif (($perms & 0x2000) == 0x2000) {
|
||||
// Character special
|
||||
$info = 'c';
|
||||
} elseif (($perms & 0x1000) == 0x1000) {
|
||||
// FIFO pipe
|
||||
$info = 'p';
|
||||
} else {
|
||||
// Unknown
|
||||
$info = 'u';
|
||||
}
|
||||
|
||||
// Owner
|
||||
$info .= (($perms & 0x0100) ? 'r' : '-');
|
||||
$info .= (($perms & 0x0080) ? 'w' : '-');
|
||||
$info .= (($perms & 0x0040) ?
|
||||
(($perms & 0x0800) ? 's' : 'x' ) :
|
||||
(($perms & 0x0800) ? 'S' : '-'));
|
||||
|
||||
// Group
|
||||
$info .= (($perms & 0x0020) ? 'r' : '-');
|
||||
$info .= (($perms & 0x0010) ? 'w' : '-');
|
||||
$info .= (($perms & 0x0008) ?
|
||||
(($perms & 0x0400) ? 's' : 'x' ) :
|
||||
(($perms & 0x0400) ? 'S' : '-'));
|
||||
|
||||
// World
|
||||
$info .= (($perms & 0x0004) ? 'r' : '-');
|
||||
$info .= (($perms & 0x0002) ? 'w' : '-');
|
||||
$info .= (($perms & 0x0001) ?
|
||||
(($perms & 0x0200) ? 't' : 'x' ) :
|
||||
(($perms & 0x0200) ? 'T' : '-'));
|
||||
return $info;
|
||||
}
|
||||
function getnumchmodfromh($mode) {
|
||||
$realmode = "";
|
||||
$legal = array("","w","r","x","-");
|
||||
$attarray = preg_split("//",$mode);
|
||||
for($i=0;$i<count($attarray);$i++){
|
||||
if($key = array_search($attarray[$i],$legal)){
|
||||
$realmode .= $legal[$key];
|
||||
}
|
||||
}
|
||||
$mode = str_pad($realmode,9,'-');
|
||||
$trans = array('-'=>'0','r'=>'4','w'=>'2','x'=>'1');
|
||||
$mode = strtr($mode,$trans);
|
||||
$newmode = '';
|
||||
$newmode .= $mode[0]+$mode[1]+$mode[2];
|
||||
$newmode .= $mode[3]+$mode[4]+$mode[5];
|
||||
$newmode .= $mode[6]+$mode[7]+$mode[8];
|
||||
return $newmode;
|
||||
}
|
||||
function group($file) {
|
||||
$gid = @filegroup($file);
|
||||
if( ! $gid )
|
||||
|
@ -330,9 +253,5 @@ class WP_Filesystem_Direct{
|
|||
unset($dir);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function __destruct(){
|
||||
return;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
<?php
|
||||
class WP_Filesystem_FTPext{
|
||||
class WP_Filesystem_FTPext extends WP_Filesystem_Base{
|
||||
var $link;
|
||||
var $timeout = 5;
|
||||
var $errors = array();
|
||||
var $options = array();
|
||||
|
||||
var $wp_base = '';
|
||||
var $permission = null;
|
||||
|
||||
var $filetypes = array(
|
||||
|
@ -24,6 +23,7 @@ class WP_Filesystem_FTPext{
|
|||
);
|
||||
|
||||
function WP_Filesystem_FTPext($opt='') {
|
||||
$this->method = 'ftpext';
|
||||
$this->errors = new WP_Error();
|
||||
|
||||
//Check if possible to use ftp functions.
|
||||
|
@ -61,11 +61,10 @@ class WP_Filesystem_FTPext{
|
|||
}
|
||||
|
||||
function connect() {
|
||||
if ( $this->options['ssl'] && function_exists('ftp_ssl_connect') ) {
|
||||
if ( $this->options['ssl'] && function_exists('ftp_ssl_connect') )
|
||||
$this->link = @ftp_ssl_connect($this->options['hostname'], $this->options['port'],$this->timeout);
|
||||
} else {
|
||||
else
|
||||
$this->link = @ftp_connect($this->options['hostname'], $this->options['port'],$this->timeout);
|
||||
}
|
||||
|
||||
if ( ! $this->link ) {
|
||||
$this->errors->add('connect', sprintf(__('Failed to connect to FTP Server %1$s:%2$s'), $this->options['hostname'], $this->options['port']));
|
||||
|
@ -84,74 +83,6 @@ class WP_Filesystem_FTPext{
|
|||
$this->permission = $perm;
|
||||
}
|
||||
|
||||
function find_base_dir($path = false, $base = '.',$echo = false, $loop = false) {
|
||||
if (!$path)
|
||||
$path = ABSPATH;
|
||||
|
||||
//Sanitize the Windows path formats, This allows easier conparison and aligns it to FTP output.
|
||||
$path = str_replace('\\','/',$path); //windows: Straighten up the paths..
|
||||
if( strpos($path, ':') ){ //Windows, Strip out the driveletter
|
||||
if( preg_match("|.{1}\:(.+)|i", $path, $mat) )
|
||||
$path = $mat[1];
|
||||
}
|
||||
|
||||
//Set up the base directory (Which unless specified, is the current one)
|
||||
if( empty( $base ) || '.' == $base ) $base = $this->cwd();
|
||||
$base = trailingslashit($base);
|
||||
|
||||
//Can we see the Current directory as part of the ABSPATH?
|
||||
$location = strpos($path, $base);
|
||||
if( false !== $location ) {
|
||||
$newbase = path_join($base, substr($path, $location + strlen($base)));
|
||||
|
||||
if( false !== $this->chdir($newbase) ){ //chdir sometimes returns null under certain circumstances, even when its changed correctly, FALSE will be returned if it doesnt change correctly.
|
||||
if($echo) printf( __('Changing to %s') . '<br/>', $newbase );
|
||||
//Check to see if it exists in that folder.
|
||||
if( $this->exists($newbase . 'wp-settings.php') ){
|
||||
if($echo) printf( __('Found %s'), $newbase . 'wp-settings.php<br/>' );
|
||||
return $newbase;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Ok, Couldnt do a magic location from that particular folder level
|
||||
|
||||
//Get a list of the files in the current directory, See if we can locate where we are in the folder stucture.
|
||||
$files = $this->dirlist($base);
|
||||
|
||||
$arrPath = explode('/', $path);
|
||||
foreach($arrPath as $key){
|
||||
//Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder,
|
||||
// If its found, change into it and follow through looking for it.
|
||||
// If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on.
|
||||
// If it reaches the end, and still cant find it, it'll return false for the entire function.
|
||||
if( isset($files[ $key ]) ){
|
||||
//Lets try that folder:
|
||||
$folder = path_join($base, $key);
|
||||
if($echo) printf( __('Changing to %s') . '<br/>', $folder );
|
||||
$ret = $this->find_base_dir( $path, $folder, $echo, $loop);
|
||||
if( $ret )
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
//Only check this as a last resort, to prevent locating the incorrect install. All above proceeedures will fail quickly if this is the right branch to take.
|
||||
if(isset( $files[ 'wp-settings.php' ]) ){
|
||||
if($echo) printf( __('Found %s'), $base . 'wp-settings.php<br/>' );
|
||||
return $base;
|
||||
}
|
||||
if( $loop )
|
||||
return false;//Prevent tihs function looping again.
|
||||
//As an extra last resort, Change back to / if the folder wasnt found. This comes into effect when the CWD is /home/user/ but WP is at /var/www/.... mainly dedicated setups.
|
||||
return $this->find_base_dir($path, '/', $echo, true);
|
||||
}
|
||||
|
||||
function get_base_dir($path = false, $base = '.', $echo = false){
|
||||
if( defined('FTP_BASE') )
|
||||
$this->wp_base = FTP_BASE;
|
||||
if( empty($this->wp_base) )
|
||||
$this->wp_base = $this->find_base_dir($path, $base, $echo);
|
||||
return $this->wp_base;
|
||||
}
|
||||
function get_contents($file, $type = '', $resumepos = 0 ){
|
||||
if( empty($type) ){
|
||||
$extension = substr(strrchr($file, "."), 1);
|
||||
|
@ -229,75 +160,6 @@ class WP_Filesystem_FTPext{
|
|||
$dir = $this->dirlist($file);
|
||||
return $dir[$file]['permsn'];
|
||||
}
|
||||
function gethchmod($file){
|
||||
//From the PHP.net page for ...?
|
||||
$perms = $this->getchmod($file);
|
||||
if (($perms & 0xC000) == 0xC000) {
|
||||
// Socket
|
||||
$info = 's';
|
||||
} elseif (($perms & 0xA000) == 0xA000) {
|
||||
// Symbolic Link
|
||||
$info = 'l';
|
||||
} elseif (($perms & 0x8000) == 0x8000) {
|
||||
// Regular
|
||||
$info = '-';
|
||||
} elseif (($perms & 0x6000) == 0x6000) {
|
||||
// Block special
|
||||
$info = 'b';
|
||||
} elseif (($perms & 0x4000) == 0x4000) {
|
||||
// Directory
|
||||
$info = 'd';
|
||||
} elseif (($perms & 0x2000) == 0x2000) {
|
||||
// Character special
|
||||
$info = 'c';
|
||||
} elseif (($perms & 0x1000) == 0x1000) {
|
||||
// FIFO pipe
|
||||
$info = 'p';
|
||||
} else {
|
||||
// Unknown
|
||||
$info = 'u';
|
||||
}
|
||||
|
||||
// Owner
|
||||
$info .= (($perms & 0x0100) ? 'r' : '-');
|
||||
$info .= (($perms & 0x0080) ? 'w' : '-');
|
||||
$info .= (($perms & 0x0040) ?
|
||||
(($perms & 0x0800) ? 's' : 'x' ) :
|
||||
(($perms & 0x0800) ? 'S' : '-'));
|
||||
|
||||
// Group
|
||||
$info .= (($perms & 0x0020) ? 'r' : '-');
|
||||
$info .= (($perms & 0x0010) ? 'w' : '-');
|
||||
$info .= (($perms & 0x0008) ?
|
||||
(($perms & 0x0400) ? 's' : 'x' ) :
|
||||
(($perms & 0x0400) ? 'S' : '-'));
|
||||
|
||||
// World
|
||||
$info .= (($perms & 0x0004) ? 'r' : '-');
|
||||
$info .= (($perms & 0x0002) ? 'w' : '-');
|
||||
$info .= (($perms & 0x0001) ?
|
||||
(($perms & 0x0200) ? 't' : 'x' ) :
|
||||
(($perms & 0x0200) ? 'T' : '-'));
|
||||
return $info;
|
||||
}
|
||||
function getnumchmodfromh($mode) {
|
||||
$realmode = "";
|
||||
$legal = array("","w","r","x","-");
|
||||
$attarray = preg_split("//",$mode);
|
||||
for($i=0;$i<count($attarray);$i++){
|
||||
if($key = array_search($attarray[$i],$legal)){
|
||||
$realmode .= $legal[$key];
|
||||
}
|
||||
}
|
||||
$mode = str_pad($realmode,9,'-');
|
||||
$trans = array('-'=>'0','r'=>'4','w'=>'2','x'=>'1');
|
||||
$mode = strtr($mode,$trans);
|
||||
$newmode = '';
|
||||
$newmode .= $mode[0]+$mode[1]+$mode[2];
|
||||
$newmode .= $mode[3]+$mode[4]+$mode[5];
|
||||
$newmode .= $mode[6]+$mode[7]+$mode[8];
|
||||
return $newmode;
|
||||
}
|
||||
function group($file) {
|
||||
$dir = $this->dirlist($file);
|
||||
return $dir[$file]['group'];
|
||||
|
@ -338,8 +200,7 @@ class WP_Filesystem_FTPext{
|
|||
function is_dir($path) {
|
||||
$cwd = $this->cwd();
|
||||
$result = @ftp_chdir($this->link, $path);
|
||||
if( $result && $path == $this->cwd() ||
|
||||
$this->cwd() != $cwd ) {
|
||||
if( $result && $path == $this->cwd() || $this->cwd() != $cwd ) {
|
||||
@ftp_chdir($this->link, $cwd);
|
||||
return true;
|
||||
}
|
||||
|
@ -467,7 +328,7 @@ class WP_Filesystem_FTPext{
|
|||
if ( empty($entry) )
|
||||
continue;
|
||||
|
||||
if ( $entry["name"]=="." or $entry["name"]==".." )
|
||||
if ( '.' == $entry["name"] || '..' == $entry["name"] )
|
||||
continue;
|
||||
|
||||
$dirlist[ $entry['name'] ] = $entry;
|
||||
|
|
|
@ -5,7 +5,6 @@ class WP_Filesystem_ftpsockets{
|
|||
var $errors;
|
||||
var $options = array();
|
||||
|
||||
var $wp_base = '';
|
||||
var $permission = null;
|
||||
|
||||
var $filetypes = array(
|
||||
|
@ -24,6 +23,7 @@ class WP_Filesystem_ftpsockets{
|
|||
);
|
||||
|
||||
function WP_Filesystem_ftpsockets($opt='') {
|
||||
$this->method = 'ftpsockets';
|
||||
$this->errors = new WP_Error();
|
||||
|
||||
//Check if possible to use ftp functions.
|
||||
|
@ -86,75 +86,6 @@ class WP_Filesystem_ftpsockets{
|
|||
$this->permission = $perm;
|
||||
}
|
||||
|
||||
function find_base_dir($path = false, $base = '.',$echo = false, $loop = false) {
|
||||
if (!$path)
|
||||
$path = ABSPATH;
|
||||
|
||||
//Sanitize the Windows path formats, This allows easier conparison and aligns it to FTP output.
|
||||
$path = str_replace('\\','/',$path); //windows: Straighten up the paths..
|
||||
if( strpos($path, ':') ){ //Windows, Strip out the driveletter
|
||||
if( preg_match("|.{1}\:(.+)|i", $path, $mat) )
|
||||
$path = $mat[1];
|
||||
}
|
||||
|
||||
//Set up the base directory (Which unless specified, is the current one)
|
||||
if( empty( $base ) || '.' == $base ) $base = $this->cwd();
|
||||
$base = trailingslashit($base);
|
||||
|
||||
//Can we see the Current directory as part of the ABSPATH?
|
||||
$location = strpos($path, $base);
|
||||
if( false !== $location ) {
|
||||
$newbase = path_join($base, substr($path, $location + strlen($base)));
|
||||
|
||||
if( false !== $this->chdir($newbase) ){ //chdir sometimes returns null under certain circumstances, even when its changed correctly, FALSE will be returned if it doesnt change correctly.
|
||||
if($echo) printf( __('Changing to %s') . '<br/>', $newbase );
|
||||
//Check to see if it exists in that folder.
|
||||
if( $this->exists($newbase . 'wp-settings.php') ){
|
||||
if($echo) printf( __('Found %s'), $newbase . 'wp-settings.php<br/>' );
|
||||
return $newbase;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Ok, Couldnt do a magic location from that particular folder level
|
||||
|
||||
//Get a list of the files in the current directory, See if we can locate where we are in the folder stucture.
|
||||
$files = $this->dirlist($base);
|
||||
|
||||
$arrPath = explode('/', $path);
|
||||
foreach($arrPath as $key){
|
||||
//Working from /home/ to /user/ to /wordpress/ see if that file exists within the current folder,
|
||||
// If its found, change into it and follow through looking for it.
|
||||
// If it cant find WordPress down that route, it'll continue onto the next folder level, and see if that matches, and so on.
|
||||
// If it reaches the end, and still cant find it, it'll return false for the entire function.
|
||||
if( isset($files[ $key ]) ){
|
||||
//Lets try that folder:
|
||||
$folder = path_join($base, $key);
|
||||
if($echo) printf( __('Changing to %s') . '<br/>', $folder );
|
||||
$ret = $this->find_base_dir($path, $folder, $echo, $loop);
|
||||
if( $ret )
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
//Only check this as a last resort, to prevent locating the incorrect install. All above proceeedures will fail quickly if this is the right branch to take.
|
||||
if(isset( $files[ 'wp-settings.php' ]) ){
|
||||
if($echo) printf( __('Found %s'), $base . 'wp-settings.php<br/>' );
|
||||
return $base;
|
||||
}
|
||||
if( $loop )
|
||||
return false;//Prevent tihs function looping again.
|
||||
//As an extra last resort, Change back to / if the folder wasnt found. This comes into effect when the CWD is /home/user/ but WP is at /var/www/.... mainly dedicated setups.
|
||||
return $this->find_base_dir($path, '/', $echo, true);
|
||||
}
|
||||
|
||||
function get_base_dir($path = false, $base = '.', $echo = false){
|
||||
if( defined('FTP_BASE') )
|
||||
$this->wp_base = FTP_BASE;
|
||||
if( empty($this->wp_base) )
|
||||
$this->wp_base = $this->find_base_dir($path, $base, $echo);
|
||||
return $this->wp_base;
|
||||
}
|
||||
|
||||
function get_contents($file,$type='',$resumepos=0){
|
||||
if( ! $this->exists($file) )
|
||||
return false;
|
||||
|
|
|
@ -256,13 +256,13 @@ function unzip_file($file, $to) {
|
|||
$tmppath .= $path[$j] . '/';
|
||||
if ( ! $fs->is_dir($to . $tmppath) )
|
||||
if ( !$fs->mkdir($to . $tmppath, 0755) )
|
||||
return new WP_Error('mkdir_failed', __('Could not create directory'));
|
||||
return new WP_Error('mkdir_failed', __('Could not create directory'), $to . $tmppath);
|
||||
}
|
||||
|
||||
// We've made sure the folders are there, so let's extract the file now:
|
||||
if ( ! $file['folder'] )
|
||||
if ( !$fs->put_contents( $to . $file['filename'], $file['content']) )
|
||||
return new WP_Error('copy_failed', __('Could not copy file'));
|
||||
return new WP_Error('copy_failed', __('Could not copy file'), $to . $file['filename']);
|
||||
$fs->chmod($to . $file['filename'], 0644);
|
||||
}
|
||||
|
||||
|
@ -280,22 +280,23 @@ function copy_dir($from, $to) {
|
|||
foreach ( (array) $dirlist as $filename => $fileinfo ) {
|
||||
if ( 'f' == $fileinfo['type'] ) {
|
||||
if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true) )
|
||||
return false;
|
||||
return new WP_Error('copy_failed', __('Could not copy file'), $to . $filename);
|
||||
$wp_filesystem->chmod($to . $filename, 0644);
|
||||
} elseif ( 'd' == $fileinfo['type'] ) {
|
||||
if ( !$wp_filesystem->mkdir($to . $filename, 0755) )
|
||||
return false;
|
||||
if ( !copy_dir($from . $filename, $to . $filename) )
|
||||
return false;
|
||||
return new WP_Error('mkdir_failed', __('Could not create directory'), $to . $filename);
|
||||
$result = copy_dir($from . $filename, $to . $filename);
|
||||
if ( is_wp_error($result) )
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function WP_Filesystem( $args = false ) {
|
||||
global $wp_filesystem;
|
||||
|
||||
require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
|
||||
|
||||
$method = get_filesystem_method();
|
||||
|
||||
if ( ! $method )
|
||||
|
|
|
@ -160,10 +160,17 @@ function wp_update_plugin($plugin, $feedback = '') {
|
|||
return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);
|
||||
|
||||
//Get the base plugin folder
|
||||
$base = $wp_filesystem->get_base_dir(WP_PLUGIN_DIR);
|
||||
$plugins_dir = $wp_filesystem->wp_plugins_dir();
|
||||
if ( empty($plugins_dir) )
|
||||
return new WP_Error('fs_no)plugins_dir', __('Unable to locate WordPress Plugin directory.'));
|
||||
|
||||
if ( empty($base) )
|
||||
return new WP_Error('fs_nowordpress', __('Unable to locate WordPress directory.'));
|
||||
//And the same for the Content directory.
|
||||
$content_dir = $wp_filesystem->wp_content_dir();
|
||||
if( empty($content_dir) )
|
||||
return new WP_Error('fs_no_content_dor', __('Unable to locate WordPress Content directory (wp-content).'));
|
||||
|
||||
$plugins_dir = trailingslashit( $plugins_dir );
|
||||
$content_dir = trailingslashit( $content_dir );
|
||||
|
||||
// Get the URL to the zip file
|
||||
$r = $current->response[ $plugin ];
|
||||
|
@ -174,12 +181,12 @@ function wp_update_plugin($plugin, $feedback = '') {
|
|||
// Download the package
|
||||
$package = $r->package;
|
||||
apply_filters('update_feedback', sprintf(__('Downloading update from %s'), $package));
|
||||
$file = download_url($package);
|
||||
$download_file = download_url($package);
|
||||
|
||||
if ( is_wp_error($file) )
|
||||
if ( is_wp_error($download_file) )
|
||||
return new WP_Error('download_failed', __('Download failed.'), $file->get_error_message());
|
||||
|
||||
$working_dir = $wp_filesystem->get_base_dir(WP_CONTENT_DIR) . '/upgrade/' . basename($plugin, '.php');
|
||||
$working_dir = $content_dir . 'upgrade/' . basename($plugin, '.php');
|
||||
|
||||
// Clean up working directory
|
||||
if ( $wp_filesystem->is_dir($working_dir) )
|
||||
|
@ -187,16 +194,16 @@ function wp_update_plugin($plugin, $feedback = '') {
|
|||
|
||||
apply_filters('update_feedback', __('Unpacking the update'));
|
||||
// Unzip package to working directory
|
||||
$result = unzip_file($file, $working_dir);
|
||||
$result = unzip_file($download_file, $working_dir);
|
||||
|
||||
// Once extracted, delete the package
|
||||
unlink($download_file);
|
||||
|
||||
if ( is_wp_error($result) ) {
|
||||
unlink($file);
|
||||
$wp_filesystem->delete($working_dir, true);
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Once extracted, delete the package
|
||||
unlink($file);
|
||||
|
||||
if ( is_plugin_active($plugin) ) {
|
||||
//Deactivate the plugin silently, Prevent deactivation hooks from running.
|
||||
apply_filters('update_feedback', __('Deactivating the plugin'));
|
||||
|
@ -205,14 +212,13 @@ function wp_update_plugin($plugin, $feedback = '') {
|
|||
|
||||
// Remove the existing plugin.
|
||||
apply_filters('update_feedback', __('Removing the old version of the plugin'));
|
||||
$plugin_dir = dirname($base . "/$plugin");
|
||||
$plugin_dir = trailingslashit($plugin_dir);
|
||||
$this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) );
|
||||
|
||||
// If plugin is in its own directory, recursively delete the directory.
|
||||
if ( strpos($plugin, '/') && $plugin_dir != $base . '/' ) //base check on if plugin includes directory seperator AND that its not the root plugin folder
|
||||
$deleted = $wp_filesystem->delete($plugin_dir, true);
|
||||
if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory seperator AND that its not the root plugin folder
|
||||
$deleted = $wp_filesystem->delete($this_plugin_dir, true);
|
||||
else
|
||||
$deleted = $wp_filesystem->delete($base . '/' . $plugin);
|
||||
$deleted = $wp_filesystem->delete($plugins_dir . $plugin);
|
||||
|
||||
if ( ! $deleted ) {
|
||||
$wp_filesystem->delete($working_dir, true);
|
||||
|
@ -221,9 +227,10 @@ function wp_update_plugin($plugin, $feedback = '') {
|
|||
|
||||
apply_filters('update_feedback', __('Installing the latest version'));
|
||||
// Copy new version of plugin into place.
|
||||
if ( !copy_dir($working_dir, $base) ) {
|
||||
$result = copy_dir($working_dir, $plugins_dir);
|
||||
if ( is_wp_error($result) ) {
|
||||
//$wp_filesystem->delete($working_dir, true); //TODO: Uncomment? This DOES mean that the new files are available in the upgrade folder if it fails.
|
||||
return new WP_Error('install_failed', __('Installation failed'));
|
||||
return $result;
|
||||
}
|
||||
|
||||
//Get a list of the directories in the working directory before we delete it, We need to know the new folder for the plugin
|
||||
|
@ -236,13 +243,13 @@ function wp_update_plugin($plugin, $feedback = '') {
|
|||
delete_option('update_plugins');
|
||||
|
||||
if( empty($filelist) )
|
||||
return false; //We couldnt find any files in the working dir
|
||||
return false; //We couldnt find any files in the working dir, therefor no plugin installed? Failsafe backup.
|
||||
|
||||
$folder = $filelist[0];
|
||||
$plugin = get_plugins('/' . $folder); //Pass it with a leading slash, search out the plugins in the folder,
|
||||
$plugin = get_plugins('/' . $folder); //Ensure to pass with leading slash
|
||||
$pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
|
||||
|
||||
return $folder . '/' . $pluginfiles[0]; //Pass it without a leading slash as WP requires
|
||||
return $folder . '/' . $pluginfiles[0];
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -110,12 +110,13 @@ function do_plugin_upgrade($plugin) {
|
|||
return;
|
||||
}
|
||||
|
||||
$was_activated = is_plugin_active($plugin); //Check now, It'll be deactivated by the next line if it is,
|
||||
$was_activated = is_plugin_active($plugin); //Check now, It'll be deactivated by the next line if it is
|
||||
|
||||
$result = wp_update_plugin($plugin, 'show_message');
|
||||
|
||||
if ( is_wp_error($result) ) {
|
||||
show_message($result);
|
||||
show_message( __('Installation Failed') );
|
||||
} else {
|
||||
//Result is the new plugin file relative to WP_PLUGIN_DIR
|
||||
show_message( __('Plugin upgraded successfully') );
|
||||
|
|
Loading…
Reference in New Issue