mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-01 15:50:09 +00:00
Allow wp-content to exist outside of webroot. Props sambauers. see #6938
git-svn-id: https://develop.svn.wordpress.org/trunk@7999 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -13,10 +13,12 @@ class WP_Filesystem_Direct{
|
||||
function setDefaultPermissions($perm){
|
||||
$this->permission = $perm;
|
||||
}
|
||||
function find_base_dir($base = '.', $echo = false){
|
||||
return str_replace('\\','/',ABSPATH);
|
||||
function find_base_dir($path = false, $base = '.', $echo = false){
|
||||
if (!$path)
|
||||
$path = ABSPATH;
|
||||
return str_replace('\\','/',$path);
|
||||
}
|
||||
function get_base_dir($base = '.', $echo = false){
|
||||
function get_base_dir($path = false, $base = '.', $echo = false){
|
||||
return $this->find_base_dir($base, $echo);
|
||||
}
|
||||
function get_contents($file){
|
||||
|
||||
@@ -84,12 +84,15 @@ class WP_Filesystem_FTPext{
|
||||
$this->permission = $perm;
|
||||
}
|
||||
|
||||
function find_base_dir($base = '.',$echo = false, $loop = false) {
|
||||
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.
|
||||
$abspath = str_replace('\\','/',ABSPATH); //windows: Straighten up the paths..
|
||||
if( strpos($abspath, ':') ){ //Windows, Strip out the driveletter
|
||||
if( preg_match("|.{1}\:(.+)|i", $abspath, $mat) )
|
||||
$abspath = $mat[1];
|
||||
$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)
|
||||
@@ -97,9 +100,9 @@ class WP_Filesystem_FTPext{
|
||||
$base = trailingslashit($base);
|
||||
|
||||
//Can we see the Current directory as part of the ABSPATH?
|
||||
$location = strpos($abspath, $base);
|
||||
$location = strpos($path, $base);
|
||||
if( false !== $location ) {
|
||||
$newbase = path_join($base, substr($abspath, $location + strlen($base)));
|
||||
$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 );
|
||||
@@ -116,7 +119,7 @@ class WP_Filesystem_FTPext{
|
||||
//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('/', $abspath);
|
||||
$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.
|
||||
@@ -126,7 +129,7 @@ class WP_Filesystem_FTPext{
|
||||
//Lets try that folder:
|
||||
$folder = path_join($base, $key);
|
||||
if($echo) printf( __('Changing to %s') . '<br/>', $folder );
|
||||
$ret = $this->find_base_dir( $folder, $echo, $loop);
|
||||
$ret = $this->find_base_dir( $path, $folder, $echo, $loop);
|
||||
if( $ret )
|
||||
return $ret;
|
||||
}
|
||||
@@ -139,14 +142,14 @@ class WP_Filesystem_FTPext{
|
||||
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('/', $echo, true);
|
||||
return $this->find_base_dir($path, '/', $echo, true);
|
||||
}
|
||||
|
||||
function get_base_dir($base = '.', $echo = false){
|
||||
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($base,$echo);
|
||||
$this->wp_base = $this->find_base_dir($path, $base, $echo);
|
||||
return $this->wp_base;
|
||||
}
|
||||
function get_contents($file,$type='',$resumepos=0){
|
||||
|
||||
@@ -86,12 +86,15 @@ class WP_Filesystem_ftpsockets{
|
||||
$this->permission = $perm;
|
||||
}
|
||||
|
||||
function find_base_dir($base = '.',$echo = false, $loop = false) {
|
||||
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.
|
||||
$abspath = str_replace('\\','/',ABSPATH); //windows: Straighten up the paths..
|
||||
if( strpos($abspath, ':') ){ //Windows, Strip out the driveletter
|
||||
if( preg_match("|.{1}\:(.+)|i", $abspath, $mat) )
|
||||
$abspath = $mat[1];
|
||||
$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)
|
||||
@@ -99,9 +102,9 @@ class WP_Filesystem_ftpsockets{
|
||||
$base = trailingslashit($base);
|
||||
|
||||
//Can we see the Current directory as part of the ABSPATH?
|
||||
$location = strpos($abspath, $base);
|
||||
$location = strpos($path, $base);
|
||||
if( false !== $location ) {
|
||||
$newbase = path_join($base, substr($abspath, $location + strlen($base)));
|
||||
$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 );
|
||||
@@ -118,7 +121,7 @@ class WP_Filesystem_ftpsockets{
|
||||
//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('/', $abspath);
|
||||
$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.
|
||||
@@ -128,7 +131,7 @@ class WP_Filesystem_ftpsockets{
|
||||
//Lets try that folder:
|
||||
$folder = path_join($base, $key);
|
||||
if($echo) printf( __('Changing to %s') . '<br/>', $folder );
|
||||
$ret = $this->find_base_dir( $folder, $echo, $loop);
|
||||
$ret = $this->find_base_dir($path, $folder, $echo, $loop);
|
||||
if( $ret )
|
||||
return $ret;
|
||||
}
|
||||
@@ -141,14 +144,14 @@ class WP_Filesystem_ftpsockets{
|
||||
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('/', $echo, true);
|
||||
return $this->find_base_dir($path, '/', $echo, true);
|
||||
}
|
||||
|
||||
function get_base_dir($base = '.', $echo = false){
|
||||
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($base, $echo);
|
||||
$this->wp_base = $this->find_base_dir($path, $base, $echo);
|
||||
return $this->wp_base;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ function get_temp_dir() {
|
||||
if ( defined('WP_TEMP_DIR') )
|
||||
return trailingslashit(WP_TEMP_DIR);
|
||||
|
||||
$temp = ABSPATH . 'wp-content/';
|
||||
$temp = WP_CONTENT_DIR . '/';
|
||||
if ( is_dir($temp) && is_writable($temp) )
|
||||
return $temp;
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ function get_plugins($plugin_folder = '') {
|
||||
}
|
||||
|
||||
$wp_plugins = array ();
|
||||
$plugin_root = ABSPATH . PLUGINDIR;
|
||||
$plugin_root = WP_PLUGIN_DIR;
|
||||
if( !empty($plugin_folder) )
|
||||
$plugin_root .= $plugin_folder;
|
||||
|
||||
@@ -104,7 +104,7 @@ function activate_plugin($plugin, $redirect = '') {
|
||||
if ( !empty($redirect) )
|
||||
wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); // we'll override this later if the plugin can be included without fatal error
|
||||
ob_start();
|
||||
@include(ABSPATH . PLUGINDIR . '/' . $plugin);
|
||||
@include(WP_PLUGIN_DIR . '/' . $plugin);
|
||||
$current[] = $plugin;
|
||||
sort($current);
|
||||
update_option('active_plugins', $current);
|
||||
@@ -179,7 +179,7 @@ function validate_active_plugins() {
|
||||
// If a plugin file does not exist, remove it from the list of active
|
||||
// plugins.
|
||||
foreach ( $check_plugins as $check_plugin ) {
|
||||
if ( !file_exists(ABSPATH . PLUGINDIR . '/' . $check_plugin) ) {
|
||||
if ( !file_exists(WP_PLUGIN_DIR . '/' . $check_plugin) ) {
|
||||
$current = get_option('active_plugins');
|
||||
$key = array_search($check_plugin, $current);
|
||||
if ( false !== $key && NULL !== $key ) {
|
||||
@@ -193,7 +193,7 @@ function validate_active_plugins() {
|
||||
function validate_plugin($plugin) {
|
||||
if ( validate_file($plugin) )
|
||||
return new WP_Error('plugin_invalid', __('Invalid plugin.'));
|
||||
if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) )
|
||||
if ( ! file_exists(WP_PLUGIN_DIR . '/' . $plugin) )
|
||||
return new WP_Error('plugin_not_found', __('Plugin file does not exist.'));
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -226,10 +226,10 @@ function populate_options() {
|
||||
if ( ini_get('safe_mode') ) {
|
||||
// Safe mode screws up mkdir(), so we must use a flat structure.
|
||||
add_option('uploads_use_yearmonth_folders', 0);
|
||||
add_option('upload_path', 'wp-content');
|
||||
add_option('upload_path', WP_CONTENT_DIR);
|
||||
} else {
|
||||
add_option('uploads_use_yearmonth_folders', 1);
|
||||
add_option('upload_path', 'wp-content/uploads');
|
||||
add_option('upload_path', WP_CONTENT_DIR . '/uploads');
|
||||
}
|
||||
|
||||
// 2.0.3
|
||||
|
||||
@@ -159,8 +159,8 @@ function wp_update_plugin($plugin, $feedback = '') {
|
||||
if ( $wp_filesystem->errors->get_error_code() )
|
||||
return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);
|
||||
|
||||
//Get the Base folder
|
||||
$base = $wp_filesystem->get_base_dir();
|
||||
//Get the base plugin folder
|
||||
$base = $wp_filesystem->get_base_dir(WP_PLUGIN_DIR);
|
||||
|
||||
if ( empty($base) )
|
||||
return new WP_Error('fs_nowordpress', __('Unable to locate WordPress directory.'));
|
||||
@@ -179,7 +179,7 @@ function wp_update_plugin($plugin, $feedback = '') {
|
||||
if ( is_wp_error($file) )
|
||||
return new WP_Error('download_failed', __('Download failed.'), $file->get_error_message());
|
||||
|
||||
$working_dir = $base . 'wp-content/upgrade/' . basename($plugin, '.php');
|
||||
$working_dir = $wp_filesystem->get_base_dir(WP_CONTENT_DIR) . '/upgrade/' . basename($plugin, '.php');
|
||||
|
||||
// Clean up working directory
|
||||
if ( $wp_filesystem->is_dir($working_dir) )
|
||||
@@ -205,14 +205,14 @@ 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 . PLUGINDIR . "/$plugin");
|
||||
$plugin_dir = dirname($base . "/$plugin");
|
||||
$plugin_dir = trailingslashit($plugin_dir);
|
||||
|
||||
// If plugin is in its own directory, recursively delete the directory.
|
||||
if ( strpos($plugin, '/') && $plugin_dir != $base . PLUGINDIR . '/' ) //base check on if plugin includes directory seperator AND that its not the root plugin folder
|
||||
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);
|
||||
else
|
||||
$deleted = $wp_filesystem->delete($base . PLUGINDIR . "/$plugin");
|
||||
$deleted = $wp_filesystem->delete($base . '/' . $plugin);
|
||||
|
||||
if ( !$deleted ) {
|
||||
$wp_filesystem->delete($working_dir, true);
|
||||
@@ -221,7 +221,7 @@ 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 . PLUGINDIR) ) {
|
||||
if ( !copy_dir($working_dir, $base) ) {
|
||||
//$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'));
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
if ( file_exists(ABSPATH . 'wp-content/install.php') )
|
||||
require (ABSPATH . 'wp-content/install.php');
|
||||
if ( file_exists(WP_CONTENT_DIR . '/install.php') )
|
||||
require (WP_CONTENT_DIR . '/install.php');
|
||||
require_once(ABSPATH . 'wp-admin/includes/admin.php');
|
||||
require_once(ABSPATH . 'wp-admin/includes/schema.php');
|
||||
|
||||
@@ -1086,7 +1086,7 @@ function make_db_current_silent() {
|
||||
|
||||
function make_site_theme_from_oldschool($theme_name, $template) {
|
||||
$home_path = get_home_path();
|
||||
$site_dir = ABSPATH . "wp-content/themes/$template";
|
||||
$site_dir = WP_CONTENT_DIR . "/themes/$template";
|
||||
|
||||
if (! file_exists("$home_path/index.php"))
|
||||
return false;
|
||||
@@ -1105,7 +1105,7 @@ function make_site_theme_from_oldschool($theme_name, $template) {
|
||||
if ($oldfile == 'index.php') { // Check to make sure it's not a new index
|
||||
$index = implode('', file("$oldpath/$oldfile"));
|
||||
if (strpos($index, 'WP_USE_THEMES') !== false) {
|
||||
if (! @copy(ABSPATH . 'wp-content/themes/default/index.php', "$site_dir/$newfile"))
|
||||
if (! @copy(WP_CONTENT_DIR . '/themes/default/index.php', "$site_dir/$newfile"))
|
||||
return false;
|
||||
continue; // Don't copy anything
|
||||
}
|
||||
@@ -1153,8 +1153,8 @@ function make_site_theme_from_oldschool($theme_name, $template) {
|
||||
}
|
||||
|
||||
function make_site_theme_from_default($theme_name, $template) {
|
||||
$site_dir = ABSPATH . "wp-content/themes/$template";
|
||||
$default_dir = ABSPATH . 'wp-content/themes/default';
|
||||
$site_dir = WP_CONTENT_DIR . "/themes/$template";
|
||||
$default_dir = WP_CONTENT_DIR . '/themes/default';
|
||||
|
||||
// Copy files from the default theme to the site theme.
|
||||
//$files = array('index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css');
|
||||
@@ -1211,7 +1211,7 @@ function make_site_theme() {
|
||||
// Name the theme after the blog.
|
||||
$theme_name = __get_option('blogname');
|
||||
$template = sanitize_title($theme_name);
|
||||
$site_dir = ABSPATH . "wp-content/themes/$template";
|
||||
$site_dir = WP_CONTENT_DIR . "/themes/$template";
|
||||
|
||||
// If the theme already exists, nothing to do.
|
||||
if ( is_dir($site_dir)) {
|
||||
@@ -1219,7 +1219,7 @@ function make_site_theme() {
|
||||
}
|
||||
|
||||
// We must be able to write to the themes dir.
|
||||
if (! is_writable(ABSPATH . "wp-content/themes")) {
|
||||
if (! is_writable(WP_CONTENT_DIR . "/themes")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user