PHP Class HM\BackUpWordPress\Path

Handles calculating & protecting the directory that backups will be stored in as well as the directory that is being backed up
Datei anzeigen Open project: humanmade/backupwordpress Class Usage Examples

Public Methods

Method Description
calculate_path ( ) Calculate the backup path and create the directory if it doesn't exist.
cleanup ( ) Clean any temporary / incomplete backups from the backups directory
get_custom_path ( ) Get the path to the custom backup location if it's been set
get_default_path ( ) Get the path to the default backup location in wp-content
get_existing_path ( ) : string Returns the first existing path if there is one
get_existing_paths ( ) : array Builds an array containing existing backups folders.
get_fallback_path ( ) Get the path to the fallback backup location in uploads
get_home_path ( string $site_path = ABSPATH ) Calculate the path to the site "home" directory.
get_instance ( ) : Path Returns the *Singleton* instance of this class.
get_path ( ) Convenience method for quickly grabbing the path
get_root ( ) Convenience method for quickly grabbing the root
merge_existing_paths ( ) If we have more than one path then move any existing backups to the current path and remove them
move_old_backups ( string $from ) Move backup files from an existing directory and the new location.
protect_path ( string $reset = 'no' ) Protect the directory that backups are stored in
reset_path ( )
set_path ( $path ) Set the path directly, overriding the default
set_root ( $root ) Set the root path directly, overriding the default

Protected Methods

Method Description
__construct ( ) Protected constructor to prevent creating a new instance of the *Singleton* via the new operator from outside of this class.

Private Methods

Method Description
__clone ( ) Private clone method to prevent cloning of the instance of the *Singleton* instance.
__wakeup ( ) Private unserialize method to prevent unserializing of the *Singleton* instance.
get_calculated_path ( ) get the calculated path to the directory where backups will be stored
get_calculated_root ( ) get the calculated path to the directory that will be backed up

Method Details

__construct() protected method

Protected constructor to prevent creating a new instance of the *Singleton* via the new operator from outside of this class.
protected __construct ( )

calculate_path() public method

Tries all possible locations and uses the first one possible.
public calculate_path ( )

cleanup() public method

Clean any temporary / incomplete backups from the backups directory
public cleanup ( )

get_custom_path() public method

Get the path to the custom backup location if it's been set
public get_custom_path ( )

get_default_path() public method

Get the path to the default backup location in wp-content
public get_default_path ( )

get_existing_path() public method

Returns the first existing path if there is one
public get_existing_path ( ) : string
return string Backup path if found empty string if not

get_existing_paths() public method

Builds an array containing existing backups folders.
public get_existing_paths ( ) : array
return array

get_fallback_path() public method

Get the path to the fallback backup location in uploads
public get_fallback_path ( )

get_home_path() public static method

The home directory is the path equivalent to the home_url. That is, the path to the true root of the website. In situations where WordPress is installed in a subdirectory the home path is different to ABSPATH
public static get_home_path ( string $site_path = ABSPATH )
$site_path string The site_path to use when calculating the home path, defaults to ABSPATH

get_instance() public static method

Returns the *Singleton* instance of this class.
public static get_instance ( ) : Path
return Path The *Singleton* instance.

get_path() public static method

Convenience method for quickly grabbing the path
public static get_path ( )

get_root() public static method

Convenience method for quickly grabbing the root
public static get_root ( )

merge_existing_paths() public method

If we have more than one path then move any existing backups to the current path and remove them

move_old_backups() public method

Move backup files from an existing directory and the new location.
public move_old_backups ( string $from )
$from string The path to move the backups from.

protect_path() public method

- Adds an index.html file in an attempt to disable directory browsing - Adds a .httaccess file to deny direct access if on Apache
public protect_path ( string $reset = 'no' )
$reset string

reset_path() public method

public reset_path ( )

set_path() public method

Set the path directly, overriding the default
public set_path ( $path )
$path

set_root() public method

Set the root path directly, overriding the default
public set_root ( $root )
$root