path = $assoc_args['path']; if ( ! empty( $assoc_args['root'] ) ) $hm_backup->root = $assoc_args['root']; if ( ( ! is_dir( $hm_backup->path() ) && ( ! is_writable( dirname( $hm_backup->path() ) ) || ! mkdir( $hm_backup->path() ) ) ) || ! is_writable( $hm_backup->path() ) ) { WP_CLI::error( 'Invalid backup path' ); return false; } if ( ! is_dir( $hm_backup->root() ) || ! is_readable( $hm_backup->root() ) ) { WP_CLI::error( 'Invalid root path' ); return false; } // Default to both $hm_backup->files_only = false; $hm_backup->database_only = false; if ( ! empty( $assoc_args['files_only'] ) ) $hm_backup->files_only = true; if ( ! empty( $assoc_args['database_only'] ) ) $hm_backup->database_only = true; if ( ! empty( $assoc_args['mysqldump_command_path'] ) ) $hm_backup->mysqldump_command_path = empty( $assoc_args['mysqldump_command_path'] ) || $assoc_args['mysqldump_command_path'] === 'false' ? false : true; if ( ! empty( $assoc_args['zip_command_path'] ) ) $hm_backup->zip_command_path = empty( $assoc_args['zip_command_path'] ) || $assoc_args['zip_command_path'] === 'false' ? false : true; if ( ! empty( $assoc_args['excludes'] ) ) $hm_backup->excludes = $valid_rules = array_filter( array_map( 'trim', explode( ',', $assoc_args['excludes'] ) ) ); $hm_backup->backup(); WP_CLI::line( 'Backup: deleting old backups...' ); // Delete any old backup files hmbkp_delete_old_backups(); if ( file_exists( HM_Backup::get_instance()->archive_filepath() ) ) WP_CLI::success( 'Backup Complete: ' . HM_Backup::get_instance()->archive_filepath() ); else WP_CLI::success( 'Backup Failed' ); } static function help() { WP_CLI::line( <<] [--root] [--zip_command_path=] [--mysqldump_command_path=] --files_only Backup files only, default to off --database_only Backup database only, defaults to off --path dir that the backup should be save in, defaults to wp-content/backups/ --root dir that should be backed up, defaults to ABSPATH --zip_command_path path to your zip binary, standard locations are automatically used --mysqldump_command_path path to your mysqldump binary, standard locations are automatically used EOB ); } } WP_CLI::addCommand( 'backup', 'BackUpCommand' );