Skip to content
Permalink
Browse files

Use the location of wp-config.php when attempting to work out the hom…

…e path
  • Loading branch information...
willmot committed Mar 14, 2014
1 parent 0b540f7 commit 3e213ac2bbd06d02383ed5290d6475cc1bed0c36
Showing with 6 additions and 1 deletion.
  1. +6 −1 hm-backup.php
@@ -181,7 +181,7 @@ public static function is_shell_exec_available() {
// Is shell_exec or escapeshellcmd or escapeshellarg disabled?
if ( array_intersect( array( 'shell_exec', 'escapeshellarg', 'escapeshellcmd' ), array_map( 'trim', explode( ',', @ini_get( 'disable_functions' ) ) ) ) )
return false;
// Functions can also be disabled via suhosin
if ( array_intersect( array( 'shell_exec', 'escapeshellarg', 'escapeshellcmd' ), array_map( 'trim', explode( ',', @ini_get( 'suhosin.executor.func.blacklist' ) ) ) ) )
return false;
@@ -208,6 +208,11 @@ public static function get_home_path() {
$home_path = ABSPATH;
// Attempt to guess the home path based on the location of wp-config.php
if ( ! file_exists( ABSPATH . 'wp-config.php' ) ) {
$home_path = trailingslashit( dirname( ABSPATH ) );
}
// If site_url contains home_url and they differ then assume WordPress is installed in a sub directory
if ( $home_url !== $site_url && strpos( $site_url, $home_url ) === 0 )
$home_path = trailingslashit( substr( self::conform_dir( ABSPATH ), 0, strrpos( self::conform_dir( ABSPATH ), str_replace( $home_url, '', $site_url ) ) ) );

2 comments on commit 3e213ac

@mikelittle

This comment has been minimized.

Copy link

mikelittle replied Mar 26, 2014

This change on line 213 breaks installs with wp-config.php one directory above ABSPATH. It ends up stripping (in my case) public_html from the real ABSPATH path. So an attempt to download a backup zip using the path calculated in admin/actions.php (https://github.com/humanmade/backupwordpress/blob/master/admin/actions.php#L125) it ends up looking like http//mydomain.com/public_html/wp-content/backupwordpress-xxxx... where the public_html should not be there.

Two things:

  1. Why do you think you cannot trust ABSPATH? WordPress has already worked it out in wp-load.php
  2. Why are the path calculations not based on WP_CONTENT_DIR/WP_CONTENT_URL/wp_upload_dir() as they seem to be in other places in the code?
@willmot

This comment has been minimized.

Copy link
Member Author

willmot replied Mar 26, 2014

This is definitely a regression, I've opened #64 so we can fix.

  1. Why do you think you cannot trust ABSPATH? WordPress has already worked it out in wp-load.php

ABSPATH is the path equivalent of site_url(), thus if WordPress is installed in a subdirectory ABSPATH is the path to the subdirectory, we need the path to the root of the site (as that is where we backup from).

  1. Why are the path calculations not based on WP_CONTENT_DIR/WP_CONTENT_URL/wp_upload_dir() as they seem to be in other places in the code?

The backup download url could be calculated using WP_CONTENT_URL however that would break download urls for people who store backups in a folder outside of WP_CONTENT_DIR but still inside web root (admittedly that's probably not something many/anyone is doing).

HM_Backup::get_home_path() needs unit tests ideally.

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.