Skip to content

Commit

Permalink
Merge pull request #936 from humanmade/backup-engines
Browse files Browse the repository at this point in the history
The Great Backup Refactor of 2015
  • Loading branch information
willmot committed Jan 19, 2016
2 parents ccc0ab7 + 7031a2b commit 11eccae
Show file tree
Hide file tree
Showing 78 changed files with 4,917 additions and 5,105 deletions.
215 changes: 101 additions & 114 deletions admin/actions.php

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions admin/backups-table.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<?php

namespace HM\BackUpWordPress;

?>

<table class="widefat">

<thead>

<tr>

<th scope="col"><?php hmbkp_backups_number( $schedule ); ?></th>
<th scope="col"><?php backups_number( $schedule ); ?></th>
<th scope="col"><?php _e( 'Size', 'backupwordpress' ); ?></th>
<th scope="col"><?php _e( 'Type', 'backupwordpress' ); ?></th>
<th scope="col"><?php _e( 'Actions', 'backupwordpress' ); ?></th>
Expand All @@ -25,7 +31,7 @@
continue;
}

hmbkp_get_backup_row( $file, $schedule );
get_backup_row( $file, $schedule );

}

Expand Down
17 changes: 10 additions & 7 deletions admin/backups.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
<?php

namespace HM\BackUpWordPress;

// Refresh the schedules from the database to make sure we have the latest changes
HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules();
Schedules::get_instance()->refresh_schedules();

$schedules = HM\BackUpWordPress\Schedules::get_instance()->get_schedules();
$schedules = Schedules::get_instance()->get_schedules();

if ( ! empty( $_GET['hmbkp_schedule_id'] ) ) {
$current_schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $_GET['hmbkp_schedule_id'] ) );
$current_schedule = new Scheduled_Backup( sanitize_text_field( $_GET['hmbkp_schedule_id'] ) );
} else {
$current_schedule = reset( $schedules );
} ?>

<h2 class="nav-tab-wrapper">

<?php foreach ( $schedules as $schedule ) : ?>
<?php foreach ( $schedules as $schedule ) :
$status = new Backup_Status( $schedule->get_id() ); ?>

<a class="nav-tab<?php if ( $schedule->get_status() ) { ?> hmbkp-running<?php } ?><?php if ( $schedule->get_id() === $current_schedule->get_id() ) { ?> nav-tab-active<?php } ?>" <?php if ( $schedule->get_status() ) { ?>title="<?php echo esc_attr( strip_tags( $schedule->get_status() ) ); ?>"<?php } ?> href="<?php echo esc_url( add_query_arg( 'hmbkp_schedule_id', $schedule->get_id(), HMBKP_ADMIN_URL ) ); ?> "><?php echo esc_html( hmbkp_translated_schedule_title( $schedule->get_slug(), $schedule->get_name() ) ); ?> <span class="count">(<?php echo esc_html( count( $schedule->get_backups() ) ); ?>)</span></a>
<a class="nav-tab<?php if ( $status->get_status() ) { ?> hmbkp-running<?php } ?><?php if ( $schedule->get_id() === $current_schedule->get_id() ) { ?> nav-tab-active<?php } ?>" <?php if ( $status->get_status() ) { ?>title="<?php echo esc_attr( strip_tags( $status->get_status() ) ); ?>"<?php } ?> href="<?php echo esc_url( add_query_arg( 'hmbkp_schedule_id', $schedule->get_id(), HMBKP_ADMIN_URL ) ); ?> "><?php echo esc_html( translated_schedule_title( $schedule->get_slug(), $schedule->get_name() ) ); ?> <span class="count">(<?php echo esc_html( count( $schedule->get_backups() ) ); ?>)</span></a>

<?php endforeach; ?>

<a class="nav-tab<?php if ( ! HM\BackUpWordPress\Schedules::get_instance()->get_schedule( $current_schedule->get_id() ) ) { ?> nav-tab-active<?php } ?>" href="<?php echo esc_url( add_query_arg( array( 'hmbkp_add_schedule' => '1', 'action' => 'hmbkp_edit_schedule', 'hmbkp_schedule_id' => time(), 'hmbkp_panel' => 'hmbkp_edit_schedule_settings' ), HMBKP_ADMIN_URL ) ); ?>"> + <?php _e( 'add schedule', 'backupwordpress' ); ?></a>
<a class="nav-tab<?php if ( ! Schedules::get_instance()->get_schedule( $current_schedule->get_id() ) ) { ?> nav-tab-active<?php } ?>" href="<?php echo esc_url( add_query_arg( array( 'hmbkp_add_schedule' => '1', 'action' => 'hmbkp_edit_schedule', 'hmbkp_schedule_id' => time(), 'hmbkp_panel' => 'hmbkp_edit_schedule_settings' ), HMBKP_ADMIN_URL ) ); ?>"> + <?php _e( 'add schedule', 'backupwordpress' ); ?></a>

</h2>

Expand All @@ -34,4 +37,4 @@

<?php require( HMBKP_PLUGIN_PATH . 'admin/backups-table.php' ); ?>

</div>
</div>
12 changes: 9 additions & 3 deletions admin/constants.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<?php

namespace HM\BackUpWordPress;

?>

<div id="hmbkp-constants">

<p><?php printf( __( 'You can %1$s any of the following %2$s in your %3$s to control advanced settings. %4$s. Defined %5$s will be highlighted.', 'backupwordpress' ), '<code>define</code>', '<code>' . __( 'Constants', 'backupwordpress' ) . '</code>', '<code>wp-config.php</code>', '<a href="http://codex.wordpress.org/Editing_wp-config.php">' . __( 'The Codex can help', 'backupwordpress' ) . '</a>', '<code>' . __( 'Constants', 'backupwordpress' ) . '</code>' ); ?></p>
Expand All @@ -14,7 +20,7 @@
<p><?php printf( __( 'You\'ve set it to: %s', 'backupwordpress' ), '<code>' . esc_html( HMBKP_PATH ) . '</code>' ); ?></p>
<?php } ?>

<p><?php printf( __( 'The path to the folder you would like to store your backup files in, defaults to %s.', 'backupwordpress' ), '<code>' . esc_html( hmbkp_path() ) . '</code>' ); ?> <?php _e( 'e.g.', 'backupwordpress' ); ?> <code>define( 'HMBKP_PATH', '/home/willmot/backups' );</code></p>
<p><?php printf( __( 'The path to the folder you would like to store your backup files in, defaults to %s.', 'backupwordpress' ), '<code>' . esc_html( Path::get_path() ) . '</code>' ); ?> <?php _e( 'e.g.', 'backupwordpress' ); ?> <code>define( 'HMBKP_PATH', '/home/willmot/backups' );</code></p>

</td>

Expand Down Expand Up @@ -94,7 +100,7 @@
<p><?php printf( __( 'You\'ve set it to: %s', 'backupwordpress' ), '<code>' . esc_html( HMBKP_ROOT ) . '</code>' ); ?></p>
<?php } ?>

<p><?php printf( __( 'The root directory that is backed up. Defaults to %s.', 'backupwordpress' ), '<code>' . HM\BackUpWordPress\Backup::get_home_path() . '</code>' ); ?> <?php _e( 'e.g.', 'backupwordpress' ); ?> <code>define( 'HMBKP_ROOT', ABSPATH . 'wp/' );</code></p>
<p><?php printf( __( 'The root directory that is backed up. Defaults to %s.', 'backupwordpress' ), '<code>' . Path::get_home_path() . '</code>' ); ?> <?php _e( 'e.g.', 'backupwordpress' ); ?> <code>define( 'HMBKP_ROOT', ABSPATH . 'wp/' );</code></p>

</td>

Expand All @@ -116,7 +122,7 @@

</tr>

<?php foreach ( HM\BackUpWordPress\Services::get_services() as $file => $service ) {
<?php foreach ( Services::get_services() as $file => $service ) {
echo wp_kses_post( call_user_func( array( $service, 'constant' ) ) );
} ?>

Expand Down
26 changes: 12 additions & 14 deletions admin/menu.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
<?php

namespace HM\BackUpWordPress;

/**
* Add the backups menu item
* to the tools menu
*
* @return null
*/
function hmbkp_admin_menu() {
function admin_menu() {

if ( is_multisite() ) {

add_submenu_page( 'settings.php', __( 'Manage Backups', 'backupwordpress' ), __( 'Backups', 'backupwordpress' ), ( defined( 'HMBKP_CAPABILITY' ) && HMBKP_CAPABILITY ) ? HMBKP_CAPABILITY : 'manage_options', HMBKP_PLUGIN_SLUG, 'hmbkp_manage_backups' );

add_submenu_page( 'settings.php', __( 'Manage Backups', 'backupwordpress' ), __( 'Backups', 'backupwordpress' ), ( defined( 'HMBKP_CAPABILITY' ) && HMBKP_CAPABILITY ) ? HMBKP_CAPABILITY : 'manage_options', HMBKP_PLUGIN_SLUG, 'HM\BackUpWordPress\manage_backups' );
} else {

add_management_page( __( 'Manage Backups', 'backupwordpress' ), __( 'Backups', 'backupwordpress' ), ( defined( 'HMBKP_CAPABILITY' ) && HMBKP_CAPABILITY ) ? HMBKP_CAPABILITY : 'manage_options', HMBKP_PLUGIN_SLUG, 'hmbkp_manage_backups' );

add_management_page( __( 'Manage Backups', 'backupwordpress' ), __( 'Backups', 'backupwordpress' ), ( defined( 'HMBKP_CAPABILITY' ) && HMBKP_CAPABILITY ) ? HMBKP_CAPABILITY : 'manage_options', HMBKP_PLUGIN_SLUG, 'HM\BackUpWordPress\manage_backups' );
}
}

add_action( 'network_admin_menu', 'hmbkp_admin_menu' );
add_action( 'admin_menu', 'hmbkp_admin_menu' );
add_action( 'network_admin_menu', 'HM\BackUpWordPress\admin_menu' );
add_action( 'admin_menu', 'HM\BackUpWordPress\admin_menu' );

/**
* Load the backups admin page
* when the menu option is clicked
*
* @return null
*/
function hmbkp_manage_backups() {
function manage_backups() {
require_once( HMBKP_PLUGIN_PATH . 'admin/page.php' );
}

Expand All @@ -40,7 +38,7 @@ function hmbkp_manage_backups() {
*
* @return array $links
*/
function hmbkp_plugin_action_link( $links, $file ) {
function plugin_action_link( $links, $file ) {

if ( false !== strpos( $file, HMBKP_PLUGIN_SLUG ) ) {
array_push( $links, '<a href="' . esc_url( HMBKP_ADMIN_URL ) . '">' . __( 'Backups', 'backupwordpress' ) . '</a>' );
Expand All @@ -50,7 +48,7 @@ function hmbkp_plugin_action_link( $links, $file ) {

}

add_filter( 'plugin_action_links', 'hmbkp_plugin_action_link', 10, 2 );
add_filter( 'plugin_action_links', 'HM\BackUpWordPress\plugin_action_link', 10, 2 );

/**
* Add Contextual Help to Backups tools page.
Expand All @@ -59,7 +57,7 @@ function hmbkp_plugin_action_link( $links, $file ) {
*
* @return null
*/
function hmbkp_contextual_help() {
function contextual_help() {

// Pre WordPress 3.3 compat
if ( ! method_exists( get_current_screen(), 'add_help_tab' ) ) {
Expand Down Expand Up @@ -104,4 +102,4 @@ function hmbkp_contextual_help() {

}

add_action( 'load-' . HMBKP_ADMIN_PAGE, 'hmbkp_contextual_help' );
add_action( 'load-' . HMBKP_ADMIN_PAGE, 'HM\BackUpWordPress\contextual_help' );
8 changes: 7 additions & 1 deletion admin/page.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<?php

namespace HM\BackUpWordPress;

?>

<div class="wrap">

<h1>
Expand All @@ -12,7 +18,7 @@

</h1>

<?php if ( hmbkp_possible() ) : ?>
<?php if ( is_backup_possible() ) : ?>

<?php include_once( HMBKP_PLUGIN_PATH . 'admin/backups.php' ); ?>

Expand Down
Loading

0 comments on commit 11eccae

Please sign in to comment.