Ubuntu 14.04系统WordPress 4.5升级到PHP7之后执行插件升级报错“无法定位WordPress内容目录(wp-content)”

Ubuntu 14.04系统上WordPress 4.5升级到PHP7之后执行插件升级报错,

无法定位WordPress内容目录(wp-content)

如下图所示:WordPres_wp-content

这个是由于PHP升级之后,有些函数的支持出现了变化,导致调用失败。

目前已知的修复方法是修改wp-admin/includes/class-wp-filesystem-ssh2.php中的如下的几个函数:

/**
 * @access public
 *
 * @param string $file
 * @return bool
 */
public function exists($file) {
	return file_exists( $this->sftp_path( $file ) );
}

/**
 * @access public
 *
 * @param string $file
 * @return bool
 */
public function is_file($file) {
	return is_file( $this->sftp_path( $file ) );
}

/**
 * @access public
 *
 * @param string $path
 * @return bool
 */
public function is_dir($path) {
	return is_dir( $this->sftp_path( $path ) );
}
/**
 * @access public
 *
 * @param string $file
 * @return bool
 */
public function is_readable($file) {
    return is_readable( $this->sftp_path( $file ) );
}

/**
 * @access public
 *
 * @param string $file
 * @return int
 */
public function atime($file) {
    return fileatime( $this->sftp_path( $file ) );
}

/**
 * @access public
 *
 * @param string $file
 * @return int
 */
public function mtime($file) {
    return filemtime( $this->sftp_path( $file ) );
}

/**
 * @access public
 *
 * @param string $file
 * @return int
 */
public function size($file) {
    return filesize( $this->sftp_path( $file ) );
}

修改为:

/**
 * @access public
 *
 * @param string $file
 * @return bool
 */
public function exists($file) {
	//return file_exists( $this->sftp_path( $file ) );
	if(version_compare(PHP_VERSION,'7.0.0','ge')){
		$stat = @ssh2_sftp_stat( $this->sftp_link, $file );
		if ( false === $stat ) {
			return false; 
		}
		return (true);
	}else{
		return file_exists( $this->sftp_path( $file ) );
	}
}

/**
 * @access public
 *
 * @param string $file
 * @return bool
 */
public function is_file($file) {
	//return is_file( $this->sftp_path( $file ) );
	if(version_compare(PHP_VERSION,'7.0.0','ge')){
		$stat = @ssh2_sftp_stat( $this->sftp_link, $file ); 
		if( false === $stat ){
			return false;
		}
		$mode = $stat['mode'];
		$type = $mode & 0xf000;
		return ($type == 0x8000);
	}else{
		return is_file( $this->sftp_path( $file ) );
	}
}

/**
 * @access public
 *
 * @param string $path
 * @return bool
 */
public function is_dir($path) {
	//return is_dir( $this->sftp_path( $path ) );
	if(version_compare(PHP_VERSION,'7.0.0','ge')){
		$stat = @ssh2_sftp_stat( $this->sftp_link, $path );
		if ( false === $stat ) {
			return false;
		}
		$mode = $stat['mode'];
		$type = $mode & 0xf000;
		return ($type == 0x4000);
	}else{
		return is_dir( $this->sftp_path( $path ) );
	}
}

/**
 * @access public
 *
 * @param string $file
 * @return bool
 */
public function is_readable($file) {
    //return is_readable( $this->sftp_path( $file ) );
    if(version_compare(PHP_VERSION,'7.0.0','ge')){
	    $stat = @ssh2_sftp_stat( $this->sftp_link, $file );
	    if ( false === $stat ) {
	        return false; 
	    }
	    $mode = $stat['mode'];
	    return ($mode & 0x0004);
	}else{
		return is_readable( $this->sftp_path( $file ) );
	}
}

/**
 * @access public
 *
 * @param string $file
 * @return int
 */
public function atime($file) {
    //return fileatime( $this->sftp_path( $file ) );
	if(version_compare(PHP_VERSION,'7.0.0','ge')){
	    $stat = @ssh2_sftp_stat( $this->sftp_link, $file );
	    if ( false === $stat ) {
	        return false;
	    }
	    return $stat['atime']; 
	}else{
    	return fileatime( $this->sftp_path( $file ) );
	}
}

/**
 * @access public
 *
 * @param string $file
 * @return int
 */
public function mtime($file) {
    //return filemtime( $this->sftp_path( $file ) );
	if(version_compare(PHP_VERSION,'7.0.0','ge')){
    	$stat = @ssh2_sftp_stat( $this->sftp_link, $file );
    	if ( false === $stat ) {
        	return false; 
    	}
    	return $stat['mtime'];
	}else{
		return filemtime( $this->sftp_path( $file ) );
	}
}

/**
 * @access public
 *
 * @param string $file
 * @return int
 */
public function size($file) {
    //return filesize( $this->sftp_path( $file ) );
	if(version_compare(PHP_VERSION,'7.0.0','ge')){
	    $stat = @ssh2_sftp_stat( $this->sftp_link, $file );
	    if ( false === $stat ) {
	        return false;
	    }
	    return $stat['size'];
	}else{
		return filesize( $this->sftp_path( $file ) );
	}
}

参考链接


Work around PHP7 php-ssh2 breakage

发布者

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注