Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 3e213ac
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion hm-backup.php
Expand Up @@ -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;
Expand All @@ -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 ) ) ) );
Expand Down

2 comments on commit 3e213ac

@mikelittle
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.