| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) die('No direct access allowed'); |
| 4 |
|
| 5 |
global $wpo_backup_initialized, $wpo_take_backup_checkbox_id; |
| 6 |
|
| 7 |
$updraftplus_admin = empty($GLOBALS['updraftplus_admin']) ? null : $GLOBALS['updraftplus_admin']; |
| 8 |
$updraftplus = empty($GLOBALS['updraftplus']) ? null : $GLOBALS['updraftplus']; |
| 9 |
|
| 10 |
// Check if UpdraftPlus plugin status. |
| 11 |
$updraftplus_status = $this->is_installed('UpdraftPlus - Backup/Restore'); |
| 12 |
$check_version = false; |
| 13 |
|
| 14 |
// If UpdraftPlus Admin exists along with Method and active, then call the update modal. |
| 15 |
if (is_a($updraftplus_admin, 'UpdraftPlus_Admin') && is_callable(array($updraftplus_admin, 'add_backup_scaffolding'))) { |
| 16 |
if (!$wpo_backup_initialized) { |
| 17 |
$updraftplus_admin->add_backup_scaffolding(esc_html__('Backup before running optimizations', 'wp-optimize'), array($updraftplus_admin, 'backupnow_modal_contents')); |
| 18 |
} |
| 19 |
$wpo_backup_initialized = true; |
| 20 |
$check_version = true; |
| 21 |
} else { |
| 22 |
|
| 23 |
// When pulling this template from UDC-RPC it gives $updraftplus_admin as null and the above condition |
| 24 |
// will always result into $disabled_backup = 'disabled', making the backup checkbox on UDC unclickable, |
| 25 |
// this makes sense since we're not logging directly into the admin dashboard but through UDC. Since, |
| 26 |
// we're giving the user an option to make a backup using UDP before optimizing on UDC, therefore we |
| 27 |
// need a way to enable the checkbox (making it clickable), giving control to the user whether he or she |
| 28 |
// needs to backup before running the optimization process. |
| 29 |
// |
| 30 |
// Having to check whether UDP is installed and active is enough for UDC to run its local backup process |
| 31 |
// if the user wishes to backup before optimizing. Of course, when $updraftplus_admin is null we assumed |
| 32 |
// that the request is coming from UDC-RPC. |
| 33 |
if (null === $updraftplus_admin && true === $updraftplus_status['installed'] && true === $updraftplus_status['active']) { |
| 34 |
$disabled_backup = ''; |
| 35 |
$check_version = true; |
| 36 |
|
| 37 |
} else { |
| 38 |
// Disabled UpdraftPlus. |
| 39 |
$disabled_backup = 'disabled'; |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
if (true === $check_version) { |
| 44 |
// Check version. |
| 45 |
if (version_compare($updraftplus->version, '1.12.33', '<')) { |
| 46 |
$disabled_backup = 'disabled'; |
| 47 |
$updraftplus_version_check = true; |
| 48 |
} else { |
| 49 |
$disabled_backup = ''; |
| 50 |
$updraftplus_version_check = false; |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
$label_text = (isset($label) && '' !== $label) ? $label : __('Take a backup with UpdraftPlus before doing this', 'wp-optimize'); |
| 55 |
|
| 56 |
if (!isset($default_checkbox_value)) { |
| 57 |
$default_checkbox_value = 'false'; |
| 58 |
} |
| 59 |
|
| 60 |
$option_value = $options->get_option($checkbox_name, $default_checkbox_value); |
| 61 |
|
| 62 |
$is_checked = ('true' === $option_value); |
| 63 |
|
| 64 |
?> |
| 65 |
<p class="wpo-take-a-backup"> |
| 66 |
<input class="enable-auto-backup" name="<?php echo esc_attr($checkbox_name); ?>" id="<?php echo esc_attr($checkbox_name); ?>" type="checkbox" value="true" <?php checked($is_checked);?> <?php echo esc_attr($disabled_backup); ?> /> |
| 67 |
<label for="<?php echo esc_attr($checkbox_name); ?>"> <?php echo esc_html($label_text); ?> </label> |
| 68 |
|
| 69 |
<?php |
| 70 |
// UpdraftPlus is not installed. |
| 71 |
if ('disabled' === $disabled_backup && !$updraftplus_status['installed']) { |
| 72 |
echo '<small><a href="'.esc_url(wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=updraftplus'), 'install-plugin_updraftplus')).'"> '.esc_html__('Follow this link to install UpdraftPlus, to take a backup before optimization', 'wp-optimize').' </a></small>'; |
| 73 |
} else { |
| 74 |
// Build activate url. |
| 75 |
$activate_url = add_query_arg(array( |
| 76 |
'_wpnonce' => wp_create_nonce('activate-plugin_updraftplus/updraftplus.php'), |
| 77 |
'action' => 'activate', |
| 78 |
'plugin' => 'updraftplus/updraftplus.php' |
| 79 |
), network_admin_url('plugins.php')); |
| 80 |
|
| 81 |
// If is network admin then add to link network activation. |
| 82 |
if (is_network_admin()) { |
| 83 |
$activate_url = add_query_arg(array('networkwide' => 1), $activate_url); |
| 84 |
} |
| 85 |
|
| 86 |
// Check updraftplus version first. |
| 87 |
if (!empty($updraftplus_version_check)) { |
| 88 |
echo '<small>'.esc_html__('UpdraftPlus needs to be updated to 1.12.33 or higher in order to backup the database before optimization.', 'wp-optimize').' <a href="'.esc_url(admin_url('update-core.php')).'">'.esc_html__('Please update UpdraftPlus to the latest version.', 'wp-optimize').'</a></small>'; |
| 89 |
} else { |
| 90 |
if ($updraftplus_status['installed'] && !$updraftplus_status['active']) { |
| 91 |
echo '<small><a href="'.esc_url($activate_url).'"> '.esc_html__('UpdraftPlus is installed but currently not active.', 'wp-optimize').' '.esc_html__('Follow this link to activate UpdraftPlus, to take a backup before optimization.', 'wp-optimize') .'</a></small>'; |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
?> |
| 96 |
</p> |