PluginProbe
UpdraftPlus: WP Backup & Migration Plugin / 1.16.5
UpdraftPlus: WP Backup & Migration Plugin v1.16.5
1.26.7 1.26.6 1.26.5 1.26.4 1.26.3 1.9.19 1.9.25 1.9.26 1.9.30 1.9.31 1.9.32 1.9.4 1.9.40 1.9.41 1.9.42 1.9.43 1.9.44 1.9.45 1.9.46 1.9.5 1.9.50 1.9.51 1.9.60 1.9.62 1.9.63 All 371 releases
updraftplus / includes / updraftplus-tour.php

updraftplus-tour.php in UpdraftPlus: WP Backup & Migration Plugin 1.16.5, at includes/updraftplus-tour.php

268 lines 11.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) die('No direct access allowed');
3 /**
4 * Class UpdraftPlus_Tour
5 *
6 * Adds the guided tour when activating the plugin for the first time.
7 */
8 class UpdraftPlus_Tour {
9
10 /**
11 * The class instance
12 *
13 * @var object
14 */
15 protected static $instance;
16
17 /**
18 * Get the instance
19 *
20 * @return object
21 */
22 public static function get_instance() {
23 if (!self::$instance) {
24 self::$instance = new self();
25 }
26 return self::$instance;
27 }
28
29 /**
30 * __construct
31 */
32 private function __construct() {
33 }
34
35 /**
36 * Sets up the notices, security and loads assets for the admin page
37 */
38 public function init() {
39 // Add plugin action link
40 add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
41
42 // only init and load assets if the tour hasn't been canceled
43 if (isset($_REQUEST['updraftplus_tour']) && 0 === intval($_REQUEST['updraftplus_tour'])) {
44 $this->set_tour_status(array('current_step' => 'start'));
45 return;
46 }
47
48 // if backups already exist and
49 if ($this->updraftplus_was_already_installed() && !isset($_REQUEST['updraftplus_tour'])) {
50 return;
51 }
52
53 // if 'Take tour' link was used, reset tour
54 if (isset($_REQUEST['updraftplus_tour']) && 1 === intval($_REQUEST['updraftplus_tour'])) {
55 $this->reset_tour_status();
56 }
57
58 if (!UpdraftPlus_Options::get_updraft_option('updraftplus_tour_cancelled_on')) {
59 add_action('admin_enqueue_scripts', array($this, 'load_tour'));
60 }
61 }
62
63 /**
64 * Loads in tour assets
65 *
66 * @param string $hook - current page
67 */
68 public function load_tour($hook) {
69
70 $pages = array('settings_page_updraftplus', 'plugins.php');
71
72 if (!in_array($hook, $pages)) return;
73 if (!UpdraftPlus_Options::user_can_manage()) return;
74
75 global $updraftplus, $updraftplus_addons2;
76 $script_suffix = $updraftplus->use_unminified_scripts() ? '' : '.min';
77 wp_enqueue_script('updraftplus-tether-js', trailingslashit(UPDRAFTPLUS_URL).'includes/tether/tether'.$script_suffix.'.js', $updraftplus->version, true);
78 wp_enqueue_script('updraftplus-shepherd-js', trailingslashit(UPDRAFTPLUS_URL).'includes/tether-shepherd/shepherd'.$script_suffix.'.js', array('updraftplus-tether-js'), $updraftplus->version, true);
79 wp_enqueue_style('updraftplus-shepherd-css', trailingslashit(UPDRAFTPLUS_URL).'css/tether-shepherd/shepherd-theme-arrows-plain-buttons'.$script_suffix.'.css', false, $updraftplus->version);
80 wp_enqueue_style('updraftplus-tour-css', trailingslashit(UPDRAFTPLUS_URL).'css/updraftplus-tour'.$script_suffix.'.css', false, $updraftplus->version);
81 wp_register_script('updraftplus-tour-js', trailingslashit(UPDRAFTPLUS_URL).'js/tour.js', array('updraftplus-tether-js'), $updraftplus->version, true);
82 $tour_data = array(
83 'nonce' => wp_create_nonce('updraftplus-credentialtest-nonce'),
84 'show_tab_on_load' => '#updraft-navtab-status',
85 'next' => __('Next', 'updraftplus'),
86 'back' => __('Back', 'updraftplus'),
87 'skip' => __('Skip this step', 'updraftplus'),
88 'end_tour' => __('End tour', 'updraftplus'),
89 'close' => __('Close', 'updraftplus'),
90 'plugins_page' => array(
91 'title' => __("UpdraftPlus settings", 'updraftplus'),
92 'text' => '<div class="updraftplus-welcome-logo"><img src="'.trailingslashit(UPDRAFTPLUS_URL).'images/ud-logo.png" alt="" /></div><strong>'.__('Welcome to UpdraftPlus', 'updraftplus').'</strong>, '.__("the world’s most trusted backup plugin!", 'updraftplus'),
93 'button' => array(
94 'url' => UpdraftPlus_Options::admin_page_url().'?page=updraftplus',
95 'text' => __('Press here to start!', 'updraftplus')
96 )
97 ),
98 'backup_now' => array(
99 'title' => __('Your first backup', 'updraftplus'),
100 'text' => sprintf(_x('To make a simple backup to your server, press this button. Or to setup regular backups and remote storage, go to %s settings %s', 'updraftplus'), '<strong><a href="#settings" class="js--go-to-settings">', '</a></strong>')
101 ),
102 'backup_options' => array(
103 'title' => __("Manual backup options", 'updraftplus'),
104 'text' => __('Select what you want to backup', 'updraftplus')
105 ),
106 'backup_now_btn' => array(
107 'title' => __("Creating your first backup", 'updraftplus'),
108 'text' => __("Press here to run a manual backup.", 'updraftplus').'<br>'.sprintf(_x("But to avoid server-wide threats backup regularly to remote cloud storage in %s settings %s", 'Translators: %s is a bold tag.', 'updraftplus'), '<strong><a href="#settings" class="js--go-to-settings">', '</a></strong>'),
109 'btn_text' => __('Go to settings', 'updraftplus')
110 ),
111 'backup_now_btn_success' => array(
112 'title' => __('Creating your first backup', 'updraftplus'),
113 'text' => __('Congratulations! Your first backup is running.', 'updraftplus').'<br>'.sprintf(_x('But to avoid server-wide threats backup regularly to remote cloud storage in %s settings %s', 'Translators: %s is a bold tag.', 'updraftplus'), '<strong>', '</strong>'),
114 'btn_text' => __('Go to settings', 'updraftplus')
115 ),
116 'settings_timing' => array(
117 'title' => __("Choose your backup schedule", 'updraftplus'),
118 'text' => __("Choose the schedule that you want your backups to run on.", 'updraftplus')
119 ),
120 'settings_remote_storage' => array(
121 'title' => __("Remote storage", 'updraftplus'),
122 'text' => __("Now select a remote storage destination to protect against server-wide threats. If not, your backups remain on the same server as your site.", 'updraftplus')
123 .'<div class="ud-notice">'
124 .'<h3>'.__('Try UpdraftVault!').'</h3>'
125 .__("UpdraftVault is our remote storage which works seamlessly with UpdraftPlus.", 'updraftplus')
126 .' <a href="'.apply_filters('updraftplus_com_link', 'https://updraftplus.com/updraftvault/').'" target="_blank">'.__('Find out more here.', 'updraftplus').'</a>'
127 .'</div>'
128 ),
129 'settings_more' => array(
130 'title' => __("More settings", 'updraftplus'),
131 'text' => __("Look through the other settings here, making any changes you’d like.", 'updraftplus')
132 ),
133 'settings_save' => array(
134 'title' => __("Save", 'updraftplus'),
135 'text' => __('Press here to save your settings.', 'updraftplus')
136 ),
137 'settings_saved' => array(
138 'title' => __("Save", 'updraftplus'),
139 'text' => __('Congratulations, your settings have successfully been saved.', 'updraftplus')
140 ),
141 'updraft_central' => array(
142 'title' => __("UpdraftCentral", 'updraftplus'),
143 'text' => '<div class="ud-notice">'
144 .'<h3>'.__('Control all your backups in one place', 'updraftplus').'</h3>'
145 .__('Do you have a few more WordPress sites you want to backup? If yes you can save hours by controlling all your backups in one place from UpdraftCentral.', 'updraftplus')
146 .'</div>'
147 ),
148 'premium' => array(
149 'title' => 'UpdraftPlus Premium',
150 'text' => __('Thank you for taking the tour.', 'updraftplus')
151 .'<div class="ud-notice">'
152 .'<h3>'.__('UpdraftPlus Premium and addons', 'updraftplus').'</h3>'
153 .__('UpdraftPlus Premium has many more exciting features!', 'updraftplus').' <a href="'.apply_filters('updraftplus_com_link', 'https://updraftplus.com/shop/updraftplus-premium/').'" target="_blank">'.__('Find out more here.', 'updraftplus').'</a>'
154 .'</div>',
155 'attach_to' => '#updraft-navtab-addons top',
156 'button' => __('Finish', 'updraftplus')
157 ),
158 'vault_selected' => array(
159 'title' => 'UpdraftVault',
160 'text' => _x('To get started with UpdraftVault, select one of the options below:', 'Translators: UpdraftVault is a product name and should not be translated.', 'updraftplus')
161 )
162 );
163
164 if (isset($_REQUEST['tab']) && 'addons' === $_REQUEST['tab']) {
165 $tour_data['show_tab_on_load'] = '#updraft-navtab-addons';
166 }
167
168 if ($updraftplus_addons2 && method_exists($updraftplus_addons2, 'connection_status')) {
169 if ($updraftplus_addons2->connection_status() && !is_wp_error($updraftplus_addons2->connection_status())) {
170 $tour_data['premium'] = array(
171 'title' => 'UpdraftPlus Premium',
172 'text' => __('Thank you for taking the tour. You are now all set to use UpdraftPlus!', 'updraftplus'),
173 'attach_to' => '#updraft-navtab-addons top',
174 'button' => __('Finish', 'updraftplus')
175 );
176 } else {
177 $tour_data['premium'] = array(
178 'title' => 'UpdraftPlus Premium',
179 'text' => __('Thank you for taking the tour.', 'updraftplus')
180 .'<div class="ud-notice">'
181 .'<h3>'.__('Connect to updraftplus.com', 'updraftplus').'</h3>'
182 .__('Log in here to enable all the features you have access to.', 'updraftplus')
183 .'</div>',
184 'attach_to' => '#updraftplus-addons_options_email right',
185 'button' => __('Finish', 'updraftplus')
186 );
187 }
188 }
189
190 wp_localize_script('updraftplus-tour-js', 'updraftplus_tour_i18n', $tour_data);
191 wp_enqueue_script('updraftplus-tour-js');
192 }
193
194 /**
195 * Removes the tour status so the tour can be seen again
196 *
197 * @return string|WP_Error not visible by the user
198 */
199 public function reset_tour_status() {
200
201 // If the option isn't set, the tour hasn't been cancelled
202 if (!UpdraftPlus_Options::get_updraft_option('updraftplus_tour_cancelled_on')) {
203 // string not visible by the user
204 return 'The tour is still active. Everything should be ok.';
205 }
206
207 $result = UpdraftPlus_Options::delete_updraft_option('updraftplus_tour_cancelled_on');
208 // strings not visible by the user
209 return $result ? 'The tour status was successfully reset' : new WP_Error('update_failed', 'The attempt to update the tour option failed.', array('status' => 409));
210 }
211
212 /**
213 * Updates the stored value for which step the tour ended on
214 *
215 * @param object $request - the http $_REQUEST obj
216 * @return bool
217 */
218 public function set_tour_status($request) {
219 if (!isset($request['current_step'])) return false;
220 return UpdraftPlus_Options::update_updraft_option('updraftplus_tour_cancelled_on', $request['current_step']);
221 }
222
223 /**
224 * Adds the Tour link under the plugin on the plugin screen.
225 *
226 * @param Array $links Set of links for the plugin, before being filtered
227 * @param String $file File name (relative to the plugin directory)
228 * @return Array filtered results
229 */
230 public function plugin_action_links($links, $file) {
231 if (is_array($links) && 'updraftplus/updraftplus.php' === $file) {
232 $links['updraftplus_tour'] = '<a href="'.UpdraftPlus_Options::admin_page_url().'?page=updraftplus&updraftplus_tour=1" class="js-updraftplus-tour">'.__("Take Tour", "updraftplus").'</a>';
233 }
234 return $links;
235 }
236
237 /**
238 * Checks if UDP was newly installed.
239 *
240 * Checks if there are backups, and if there are more than 1,
241 * checks if the folder is older than 1 day old
242 *
243 * @return bool
244 */
245 public function updraftplus_was_already_installed() {
246 // If backups already exist
247 $backup_history = UpdraftPlus_Backup_History::get_history();
248
249 // No backup history
250 if (!$backup_history) return false;
251 if (is_array($backup_history) && 0 === count($backup_history)) {
252 return false;
253 }
254 // If there is at least 1 backup, we check if the folder is older than 1 day old
255 if (0 < count($backup_history)) {
256 $backups_timestamps = array_keys($backup_history);
257 $last_backlup_age = time() - end($backups_timestamps);
258 if (DAY_IN_SECONDS < $last_backlup_age) {
259 // the oldest backup is older than 1 day old, so it's likely that UDP was already installed, and the backups aren't a product of the user testing while doing the tour.
260 return true;
261 }
262 }
263 return false;
264 }
265 }
266
267 add_action('admin_init', array(UpdraftPlus_Tour::get_instance(), 'init'));
268