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-clone.php

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

193 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('UPDRAFTPLUS_DIR')) die('No direct access allowed.');
4
5 if (!class_exists('UpdraftPlus_Login')) require_once('updraftplus-login.php');
6
7 class UpdraftPlus_Clone extends UpdraftPlus_Login {
8
9 /**
10 * Pulls the appropriate message for the given code and translate it before
11 * returning it to the caller
12 *
13 * @internal
14 * @param string $code The code of the message to pull
15 * @return string - The translated message
16 */
17 protected function translate_message($code) {
18 switch ($code) {
19 case 'generic':
20 default:
21 return __('An error has occurred while processing your request. The server might be busy or you have lost your connection to the internet at the time of the request. Please try again later.', 'updraftplus');
22 break;
23 }
24 }
25
26 /**
27 * This function will check the passed in response from the remote call and check for various errors and return the parsed response
28 *
29 * @param array $response - the response from the remote call
30 *
31 * @return array - the parsed response
32 */
33 private function parse_response($response) {
34
35 if (is_wp_error($response)) {
36 $response = array('status' => 'error', 'code' => $response->get_error_code(), 'message' => $response->get_error_message());
37 } else {
38 if (isset($response['status'])) {
39 if ('error' === $response['status']) {
40 $response = array(
41 'status' => 'error',
42 'code' => isset($response['code']) ? $response['code'] : -1,
43 'message' => isset($response['message']) ? $response['message'] : $this->translate_message('generic'),
44 'response' => $response,
45 );
46 }
47 } else {
48 $response = array('status' => 'error', 'message' => $this->translate_message('generic'));
49 }
50 }
51
52 return $response;
53 }
54
55 /**
56 * Executes login or registration process. Connects and sends request to the UpdraftPlus clone
57 * and returns the response coming from the server
58 *
59 * @internal
60 * @param array $data The submitted form data
61 * @param boolean $register Indicates whether the current call is for a registration process or not. Defaults to false. Currently will always be false.
62 * @return array - The response from the request
63 */
64 protected function login_or_register($data, $register = false) {
65
66 $action = ($register) ? 'updraftplus_clone_register' : 'updraftplus_clone_login';
67 if (empty($data['site_url'])) $data['site_url'] = trailingslashit(network_site_url());
68
69 $response = $this->send_remote_request($data, $action);
70
71 return $this->parse_response($response);
72 }
73
74 /**
75 * The ajax based request point of entry for the create clone process
76 *
77 * @param array $data - The submitted form data
78 *
79 * @return array - Response of the process
80 */
81 public function ajax_process_clone($data = array()) {
82 try {
83 if (isset($data['form_data']) && is_array($data['form_data'])) {
84 $form_data = $data['form_data'];
85 }
86
87 $response = $this->create_clone($form_data);
88 } catch (Exception $e) {
89 $response = array('error' => true, 'message' => $e->getMessage());
90 }
91
92 return $response;
93 }
94
95 /**
96 * Executes the create clone process. Connects and sends request to the UpdraftPlus clone and returns the response coming from the server
97 *
98 * @internal
99 * @param array $data - The submitted form data
100 * @return array - The response from the request
101 */
102 public function create_clone($data) {
103 global $table_prefix;
104
105 $action = 'updraftplus_clone_create';
106 if (empty($data['site_url'])) $data['site_url'] = trailingslashit(network_site_url());
107 if (empty($data['install_info']['table_prefix'])) $data['install_info']['table_prefix'] = $table_prefix;
108 $subdirectory = parse_url(network_site_url(), PHP_URL_PATH);
109 if (empty($data['install_info']['subdirectory'])) $data['install_info']['subdirectory'] = !empty($subdirectory) ? $subdirectory : '/';
110 if (empty($data['install_info']['locale'])) $data['install_info']['locale'] = get_locale();
111 if (empty($data['install_info']['owner_id']) && empty($data['install_info']['owner_login'])) {
112 $user = wp_get_current_user();
113 $data['install_info']['owner_id'] = $user->ID;
114 $data['install_info']['owner_login'] = $user->user_login;
115 }
116 if (is_multisite()) {
117 $data['install_info']['multisite'] = true;
118 $data['install_info']['multisite_subdomain_install'] = is_subdomain_install();
119 }
120
121 $response = $this->send_remote_request($data, $action);
122
123 return $this->parse_response($response);
124 }
125
126 /**
127 * Executes the clone status process. Connects and sends request to the UpdraftPlus clone and returns the response coming from the server
128 *
129 * @internal
130 * @param array $data - The submitted form data
131 * @return array - The response from the request
132 */
133 public function clone_status($data) {
134
135 $action = 'updraftplus_clone_status';
136 if (empty($data['site_url'])) $data['site_url'] = trailingslashit(network_site_url());
137
138 $response = $this->send_remote_request($data, $action);
139
140 return $this->parse_response($response);
141 }
142
143 /**
144 * Executes the clone info poll. Connects and sends request to the UpdraftPlus clone and returns the response coming from the server
145 *
146 * @internal
147 * @param array $data - The submitted form data
148 * @return array - The response from the request
149 */
150 public function clone_info_poll($data) {
151
152 $action = 'updraftplus_clone_info_poll';
153 if (empty($data['site_url'])) $data['site_url'] = trailingslashit(network_site_url());
154
155 $response = $this->send_remote_request($data, $action);
156
157 return $this->parse_response($response);
158 }
159
160 /**
161 * Executes the clone checkin. Connects and sends request to UpdraftPlus and returns the response coming from the server
162 *
163 * @internal
164 * @param array $data - The submitted form data
165 * @return array - The response from the request
166 */
167 public function clone_checkin($data) {
168 $action = 'updraftplus_clone_checkin';
169 if (empty($data['site_url'])) $data['site_url'] = trailingslashit(network_site_url());
170
171 $response = $this->send_remote_request($data, $action);
172
173 return $this->parse_response($response);
174 }
175
176 /**
177 * Executes the clone failed delete process. Connects and sends request to the UpdraftPlus clone and returns the response coming from the server
178 *
179 * @internal
180 * @param array $data - The submitted form data
181 * @return array - The response from the request
182 */
183 public function clone_failed_delete($data) {
184
185 $action = 'updraftplus_clone_failed_delete';
186 if (empty($data['site_url'])) $data['site_url'] = trailingslashit(network_site_url());
187
188 $response = $this->send_remote_request($data, $action);
189
190 return $this->parse_response($response);
191 }
192 }
193