PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.0.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.0.2
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / modules / api-backups / classes / class-api-backups-settings.php

class-api-backups-settings.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.0.2, at modules/api-backups/classes/class-api-backups-settings.php

1,048 lines 58.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * =======================================
4 * MainWP API Backups Admin
5 * =======================================
6 *
7 * @package MainWP\Dashboard
8 * @version 5.0
9 */
10
11 namespace MainWP\Dashboard\Module\ApiBackups;
12
13 use function MainWP\Dashboard\mainwp_current_user_have_right;
14 use function MainWP\Dashboard\mainwp_do_not_have_permissions;
15
16 /**
17 * MainWP API Backups Admin
18 */
19 class Api_Backups_Settings {
20
21 /**
22 * Static variable to hold the single instance of the class.
23 *
24 * @static
25 *
26 * @var mixed Default null
27 */
28 public static $instance = null;
29
30 /**
31 * Get Instance
32 *
33 * Creates public static instance.
34 *
35 * @static
36 *
37 * @return Api_Backups_Settings
38 */
39 public static function get_instance() {
40 if ( null === self::$instance ) {
41 self::$instance = new self();
42 }
43 return self::$instance;
44 }
45
46 /**
47 * Method get_class_name()
48 *
49 * Get Class Name.
50 *
51 * @return string __CLASS__
52 */
53 public static function get_class_name() {
54 return __CLASS__;
55 }
56
57 /**
58 * Constructor
59 *
60 * Runs each time the class is called.
61 */
62 public function __construct() {
63 add_action( 'admin_init', array( &$this, 'admin_init' ) );
64 add_action( 'mainwp_manage_sites_edit', array( &$this, 'hook_render_mainwp_manage_sites_edit' ), 10, 2 );
65 add_action( 'mainwp_update_site', array( &$this, 'hook_mainwp_update_site' ), 10, 2 );
66 }
67
68 /**
69 * Initiate Hooks
70 *
71 * Initiates hooks for the API Backups extension.
72 */
73 public function admin_init() {
74 }
75
76 /**
77 * Render settings
78 *
79 * Renders the settings page.
80 */
81 public function render_settings_page() {
82
83 if ( ! mainwp_current_user_have_right( 'dashboard', 'manage_api_backups' ) ) {
84 mainwp_do_not_have_permissions( esc_html__( 'manage api backups', 'mainwp' ) );
85 return;
86 }
87
88 do_action( 'mainwp_pageheader_settings', 'ApiBackups' );
89
90 ?>
91 <div id="mainwp-module-log-settings-wrapper">
92 <?php
93 if ( isset( $_GET['message'] ) && ! empty( $_GET['message'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
94 $message = esc_html__( 'Settings saved.', 'mainwp' );
95 ?>
96 <div class="ui green message" id="mainwp-module-api-backups-message-zone" >
97 <?php echo esc_html( $message ); ?>
98 <i class="ui close icon"></i>
99 </div>
100 <?php
101 }
102 ?>
103 <form id="mainwp-module-api-backups-settings-form" method="post" action="admin.php?page=SettingsApiBackups" class="ui form">
104 <?php $this->render_settings_content(); ?>
105 </form>
106 </div>
107 <?php
108 do_action( 'mainwp_pagefooter_settings', 'ApiBackups' );
109 }
110
111 /**
112 * Render settings
113 *
114 * Renders the extension settings page.
115 *
116 * @param bool $individual Individual settings True|False.
117 */
118 public function render_settings_content( $individual = false ) {
119 self::render_3rd_party_api_manager( $individual );
120 }
121
122 /**
123 * Render 3rd party api settings
124 *
125 * Renders the extension settings page.
126 *
127 * @param bool $individual Individual settings True|False.
128 */
129 public static function render_3rd_party_api_manager( $individual = false ) { //phpcs:ignore -- complex method.
130 $_nonce_slug = $individual ? 'cloudways_api_form_individual' : 'cloudways_api_form_general';
131 ?>
132 <div id="3rd-party-api-manager">
133 <div class="ui segment">
134 <div class="ui grid">
135 <div class="three wide column">
136 <div class="ui vertical fluid pointing menu">
137 <h3 class="item ui header"><?php esc_html_e( 'Backup API Providers', 'mainwp' ); ?></h3>
138 <a class="item active" data-tab="cloudways"><?php esc_html_e( 'Cloudways', 'mainwp' ); ?></a>
139 <a class="item" data-tab="gridpane"><?php esc_html_e( 'GridPane', 'mainwp' ); ?></a>
140
141 <a class="item" data-tab="vultr"><?php echo esc_html__( 'Vultr', 'mainwp' ); ?></a>
142 <a class="item" data-tab="linode"><?php echo esc_html__( 'Akamai (Linode)', 'mainwp' ); ?></a>
143 <a class="item" data-tab="digitalocean"><?php echo esc_html__( 'DigitalOcean', 'mainwp' ); ?></a>
144
145 <a class="item" data-tab="cpanel"><?php echo esc_html__( 'cPanel (WP Toolkit)', 'mainwp' ); ?></a>
146 <a class="item" data-tab="plesk"><?php echo esc_html__( 'Plesk (WP Toolkit)', 'mainwp' ); ?></a>
147 </div>
148 </div>
149 <div class="thirteen wide column">
150 <?php if ( Api_Backups_Utility::show_mainwp_message( 'mainwp-module-api-backups-manager-info-message' ) ) : ?>
151 <div class="ui info message">
152 <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-module-api-backups-manager-info-message"></i>
153 <?php
154 printf(
155 esc_html__(
156 'These settings allow you to Enable 3rd-Party API functionality within your
157 MainWP Dashboard. Check this %1$shelp document%2$s to see all available services & the endpoints that MainWP currently supports.',
158 'mainwp'
159 ),
160 '<a href="https://kb.mainwp.com/docs/api-backups-extension/" target="_blank">',
161 '</a> <i class="external alternate icon"></i>'
162 );
163 ?>
164 </div>
165 <?php endif; ?>
166
167 <?php
168 // Save CloudWays Data.
169 //phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
170 ?>
171 <?php if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce_cloudways'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce_cloudways'] ), 'cloudways_api_form_general' ) ) : ?>
172 <?php Api_Backups_Utility::update_option( 'mainwp_enable_cloudways_api', ( ! isset( $_POST['mainwp_enable_cloudways_api'] ) ? 0 : 1 ) ); ?>
173 <?php Api_Backups_Utility::update_option( 'mainwp_cloudways_api_account_email', ( isset( $_POST['mainwp_cloudways_api_account_email'] ) ? wp_unslash( $_POST['mainwp_cloudways_api_account_email'] ) : '' ) ); ?>
174 <?php Api_Backups_Utility::get_instance()->update_api_key( 'cloudways', ( isset( $_POST['mainwp_cloudways_api_key'] ) ? wp_unslash( $_POST['mainwp_cloudways_api_key'] ) : '' ) ); ?>
175 <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'API credentials have been successfully saved.', 'mainwp' ); ?></div>
176 <?php Api_Backups_3rd_Party::cloudways_action_update_ids(); ?>
177 <?php endif; ?>
178 <?php // END Save CloudWays Data. ?>
179 <?php // Save GridPane Data. ?>
180 <?php if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce_gridpane'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce_gridpane'] ), 'cloudways_api_form_general' ) ) : ?>
181 <?php Api_Backups_Utility::update_option( 'mainwp_enable_gridpane_api', ( ! isset( $_POST['mainwp_enable_gridpane_api'] ) ? 0 : 1 ) ); ?>
182 <?php Api_Backups_Utility::get_instance()->update_api_key( 'gridpane', ( isset( $_POST['mainwp_gridpane_api_key'] ) ? wp_unslash( $_POST['mainwp_gridpane_api_key'] ) : '' ) ); ?>
183 <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'API credentials have been successfully saved.', 'mainwp' ); ?></div>
184 <?php Api_Backups_3rd_Party::gridpane_action_update_ids(); ?>
185 <?php endif; ?>
186 <?php // END Save GridPane Data. ?>
187 <?php // Save Vultr Data. ?>
188 <?php if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce_vultr'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce_vultr'] ), 'cloudways_api_form_general' ) ) : ?>
189 <?php Api_Backups_Utility::update_option( 'mainwp_enable_vultr_api', ( ! isset( $_POST['mainwp_enable_vultr_api'] ) ? 0 : 1 ) ); ?>
190 <?php Api_Backups_Utility::get_instance()->update_api_key( 'vultr', ( isset( $_POST['mainwp_vultr_api_key'] ) ? wp_unslash( $_POST['mainwp_vultr_api_key'] ) : '' ) ); ?>
191 <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'API credentials have been successfully saved.', 'mainwp' ); ?></div>
192 <?php endif; ?>
193 <?php // END Save Vultr Data. ?>
194 <?php // Save Linode Data. ?>
195 <?php if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce_linode'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce_linode'] ), 'cloudways_api_form_general' ) ) : ?>
196 <?php Api_Backups_Utility::update_option( 'mainwp_enable_linode_api', ( ! isset( $_POST['mainwp_enable_linode_api'] ) ? 0 : 1 ) ); ?>
197 <?php Api_Backups_Utility::get_instance()->update_api_key( 'linode', ( isset( $_POST['mainwp_linode_api_key'] ) ? wp_unslash( $_POST['mainwp_linode_api_key'] ) : '' ) ); ?>
198 <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'API credentials have been successfully saved.', 'mainwp' ); ?></div>
199 <?php endif; ?>
200 <?php // END Save Linode Data. ?>
201 <?php // Save DigitalOcean Data. ?>
202 <?php if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce_digitalocean'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce_digitalocean'] ), 'cloudways_api_form_general' ) ) : ?>
203 <?php Api_Backups_Utility::update_option( 'mainwp_enable_digitalocean_api', ( ! isset( $_POST['mainwp_enable_digitalocean_api'] ) ? 0 : 1 ) ); ?>
204 <?php Api_Backups_Utility::get_instance()->update_api_key( 'digitalocean', ( isset( $_POST['mainwp_digitalocean_api_key'] ) ? wp_unslash( $_POST['mainwp_digitalocean_api_key'] ) : '' ) ); ?>
205 <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'API credentials have been successfully saved.', 'mainwp' ); ?></div>
206 <?php endif; ?>
207 <?php // END Save Linode Data. ?>
208 <?php // Save cPanel Data. ?>
209 <?php if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce_cpanel'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce_cpanel'] ), 'cloudways_api_form_general' ) ) : ?>
210 <?php Api_Backups_Utility::update_option( 'mainwp_enable_cpanel_api', ( ! isset( $_POST['mainwp_enable_cpanel_api'] ) ? 0 : 1 ) ); ?>
211 <?php Api_Backups_Utility::update_option( 'mainwp_cpanel_url', ( isset( $_POST['mainwp_cpanel_url'] ) ? wp_unslash( $_POST['mainwp_cpanel_url'] ) : '' ) ); ?>
212 <?php Api_Backups_Utility::update_option( 'mainwp_cpanel_site_path', ( isset( $_POST['mainwp_cpanel_site_path'] ) ? wp_unslash( $_POST['mainwp_cpanel_site_path'] ) : '' ) ); ?>
213 <?php Api_Backups_Utility::update_option( 'mainwp_cpanel_account_username', ( isset( $_POST['mainwp_cpanel_account_username'] ) ? wp_unslash( $_POST['mainwp_cpanel_account_username'] ) : '' ) ); ?>
214 <?php Api_Backups_Utility::get_instance()->update_api_key( 'cpanel', ( isset( $_POST['mainwp_cpanel_account_password'] ) ? wp_unslash( $_POST['mainwp_cpanel_account_password'] ) : '' ) ); ?>
215 <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'API credentials have been successfully saved.', 'mainwp' ); ?></div>
216 <?php endif; ?>
217 <?php // END Save cPanel Data. ?>
218 <?php // Save Plesk Data. ?>
219 <?php if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce_plesk'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce_plesk'] ), 'cloudways_api_form_general' ) ) : ?>
220 <?php Api_Backups_Utility::update_option( 'mainwp_enable_plesk_api', ( ! isset( $_POST['mainwp_enable_plesk_api'] ) ? 0 : 1 ) ); ?>
221 <?php Api_Backups_Utility::update_option( 'mainwp_plesk_api_url', ( isset( $_POST['mainwp_plesk_api_url'] ) ? wp_unslash( $_POST['mainwp_plesk_api_url'] ) : '' ) ); ?>
222 <?php Api_Backups_Utility::get_instance()->update_api_key( 'plesk', ( isset( $_POST['mainwp_plesk_api_key'] ) ? wp_unslash( $_POST['mainwp_plesk_api_key'] ) : '' ) ); ?>
223 <?php
224 if ( isset( $_POST['mainwp_plesk_installation_id'] ) ) {
225 Api_Backups_Utility::update_option( 'mainwp_plesk_installation_id', sanitize_text_field( wp_unslash( $_POST['mainwp_plesk_installation_id'] ) ) );
226 }
227 ?>
228 <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'API credentials have been successfully saved.', 'mainwp' ); ?></div>
229 <?php endif; ?>
230 <?php
231 //phpcs:enable
232 // END Save GridPane Data.
233 ?>
234 <div class="ui tab segment active" data-tab="cloudways">
235 <h3 class="ui dividing header"><?php esc_html_e( 'Cloudways API Settings', 'mainwp' ); ?></h3>
236 <ul>
237 <li><?php printf( esc_html__( "1. If you don't already have one, get a %s", 'mainwp' ), '<a target="_blank" href="https://mainwp.com/go/cloudways-mainwp/">Cloudways account</a>' ); ?></li>
238 <li><?php printf( esc_html__( '2. Get your API Key from here: %s', 'mainwp' ), '<a target="_blank" href="https://platform.cloudways.com/api">https://platform.cloudways.com/api</a>' ); ?></li>
239 <li><?php esc_html_e( '3. Enter in your account email address and API Key below.', 'mainwp' ); ?></li>
240 </ul>
241 <div class="ui hidden divider"></div>
242 <div class="ui form">
243 <form method="POST" action="">
244 <?php
245 wp_nonce_field( 'mainwp-admin-nonce' );
246 ?>
247 <input type="hidden" name="wp_nonce_cloudways" value="<?php echo esc_attr( wp_create_nonce( $_nonce_slug ) ); ?>" />
248 <?php
249 /**
250 * Action: cloudways_api_form_top
251 *
252 * Fires at the top of CloudWays API form.
253 *
254 * @since 4.1
255 */
256 do_action( 'cloudways_api_form_top' );
257 ?>
258 <div class="ui grid field">
259 <label class="six wide column middle aligned"><?php esc_html_e( 'Enable Cloudways API', 'mainwp' ); ?></label>
260 <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, the Cloudways API will be activated.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
261 <input type="checkbox" name="mainwp_enable_cloudways_api" id="mainwp_enable_cloudways_api" <?php echo ( ( 1 === (int) get_option( 'mainwp_enable_cloudways_api', 0 ) ) ? 'checked="true"' : '' ); ?> />
262 </div>
263 </div>
264 <div class="ui grid field">
265 <label class="six wide column middle aligned"><?php esc_html_e( 'Account Email', 'mainwp' ); ?></label>
266
267 <div class="five wide column">
268 <input type="text" name="mainwp_cloudways_api_account_email" id="mainwp_cloudways_api_account_email" value="<?php echo ( ( false === get_option( 'mainwp_cloudways_api_account_email' ) ) ? '' : esc_attr( get_option( 'mainwp_cloudways_api_account_email' ) ) ); ?>" />
269 </div>
270 </div>
271
272 <div class="ui grid field">
273 <label class="six wide column middle aligned"><?php esc_html_e( 'API Key', 'mainwp' ); ?></label>
274 <?php
275 $_api_key = Api_Backups_3rd_Party::get_cloudways_api_key();
276 ?>
277 <div class="five wide column">
278 <input type="password" name="mainwp_cloudways_api_key" id="mainwp_cloudways_api_key" value="<?php echo esc_attr( $_api_key ); ?>" />
279 </div>
280 </div>
281 <?php
282 /**
283 * Action: cloudways_api_form_bottom
284 *
285 * Fires at the bottom of CloudWays API form.
286 *
287 * @since 4.1
288 */
289 do_action( 'cloudways_api_form_bottom' );
290 ?>
291 <div class="ui divider"></div>
292 <input type="submit" name="submit" id="submit" class="ui green big button" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
293 <div style="clear:both"></div>
294 </form>
295 </div>
296 </div>
297
298 <div class="ui tab segment" data-tab="gridpane">
299 <h3 class="ui dividing header"><?php esc_html_e( 'GridPane API Settings', 'mainwp' ); ?></h3>
300 <div class="ui info message"><?php printf( esc_html__( 'Must be the %1$sGridPane Owners Account%2$s &amp; have a %1$sDeveloper Plan or above%2$s in order to use this feature.', 'mainwp' ), '<b>', '</b>' ); ?></div>
301 <ul>
302 <li><?php printf( esc_html__( "1. If you don't already have one, get a %s", 'mainwp' ), '<a target="_blank" href="https://mainwp.com/go/gridpane/">GridPane account</a>' ); ?></li>
303 <li><?php printf( esc_html__( '2. Get your %1$sAPI Personal Access Token%2$s here: %3$s', 'mainwp' ), '<b>', '</b>', '<a target="_blank" href="https://my.gridpane.com/settings">https://my.gridpane.com/settings</a>' ); ?></li>
304 <li><?php printf( esc_html__( '3. %1$sClick GridPare API%2$s in the left hand menu &amp; %1$sCreate your Personal Access Token%2$s', 'mainwp' ), '<b>', '</b>' ); ?></li>
305 <li><?php printf( esc_html__( '4. Copy &amp; Paste your %1$sAPI Personal Access Token%2$s below', 'mainwp' ), '<b>', '</b>' ); ?></li>
306 </ul>
307 <div class="ui hidden divider"></div>
308 <div class="ui form">
309 <form method="POST" action="">
310 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
311 <input type="hidden" name="wp_nonce_gridpane" value="<?php echo esc_attr( wp_create_nonce( $_nonce_slug ) ); ?>" />
312 <?php
313 /**
314 * Action: gridpane_api_form_top
315 *
316 * Fires at the top of GridPane API form.
317 *
318 * @since 4.1
319 */
320 do_action( 'gridpane_api_form_top' );
321 ?>
322 <div class="ui grid field">
323 <label class="six wide column middle aligned"><?php esc_html_e( 'Enable GridPane API', 'mainwp' ); ?></label>
324 <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, the GridPane API will be activated.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
325 <input type="checkbox" name="mainwp_enable_gridpane_api" id="mainwp_enable_gridpane_api" <?php echo ( ( 1 === (int) get_option( 'mainwp_enable_gridpane_api', 0 ) ) ? 'checked="true"' : '' ); ?> />
326 </div>
327 </div>
328 <div class="ui grid field">
329 <label class="six wide column middle aligned"><?php esc_html_e( 'Personal Access Token', 'mainwp' ); ?></label>
330
331 <?php
332 $_api_key = Api_Backups_3rd_Party::get_gridpane_api_key();
333 ?>
334 <div class="five wide column">
335 <input type="password" name="mainwp_gridpane_api_key" id="mainwp_gridpane_api_key" value="<?php echo esc_attr( $_api_key ); ?>" />
336 </div>
337 </div>
338 <?php
339 /**
340 * Action: gridpane_api_form_bottom
341 *
342 * Fires at the bottom of GridPane API form.
343 *
344 * @since 4.1
345 */
346 do_action( 'gridpane_api_form_bottom' );
347 ?>
348 <div class="ui divider"></div>
349 <input type="submit" name="submit" id="submit" class="ui green big button" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
350 <div style="clear:both"></div>
351 </form>
352 </div>
353 </div>
354
355 <div class="ui tab segment" data-tab="vultr">
356 <h3 class="ui dividing header"><?php esc_html_e( 'Vultr API Settings', 'mainwp' ); ?></h3>
357 <ul>
358 <li><?php printf( esc_html__( "1. If you don't already have one, get a %s", 'mainwp' ), '<a target="_blank" href="https://mainwp.com/go/vultr/">Vultr account</a>' ); ?></li>
359 <li><?php printf( esc_html__( '2. Use this %3$s to find your MainWP Dashboard IP Address %1$s"Mask Bits"%2$s', 'mainwp' ), '<b>', '</b>', '<a target="_blank" href="https://www.vultr.com/resources/subnet-calculator/">Subnet Calculator Tool</a>' ); ?></b></li>
360 <li><?php printf( esc_html__( '3. Navigate to %3$s and Whitelist your MainWP Dashboard %1$sIP/Mask Bits%2$s and %1$sActivate/Copy%2$s your %1$sAPI Key%2$s', 'mainwp' ), '<b>', '</b>', '<a target="_blank" href="https://my.vultr.com/settings/#settingsapi">Vultr API Settings</a>' ); ?></li>
361 <li><?php esc_html_e( '4. Paste in your account API Key below and click the Save Settings button.', 'mainwp' ); ?></li>
362 <li><?php esc_html_e( '5. Once the API is connected, go to the Site Edit page (for all sites on this host) and set the correct Provider and Instance ID.', 'mainwp' ); ?></li>
363 </ul>
364 <div class="ui hidden divider"></div>
365 <div class="ui form">
366 <form method="POST" action="">
367 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
368 <input type="hidden" name="wp_nonce_vultr" value="<?php echo esc_attr( wp_create_nonce( $_nonce_slug ) ); ?>" />
369 <?php
370 /**
371 * Action: vultr_api_form_top
372 *
373 * Fires at the top of Vultr API form.
374 *
375 * @since 4.1
376 */
377 do_action( 'vultr_api_form_top' );
378 ?>
379 <div class="ui grid field">
380 <label class="six wide column middle aligned"><?php esc_html_e( 'Enable Vultr API', 'mainwp' ); ?></label>
381 <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, the Vultr API will be activated.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
382 <input type="checkbox" name="mainwp_enable_vultr_api" id="mainwp_enable_vultr_api" <?php echo ( ( 1 === (int) get_option( 'mainwp_enable_vultr_api', 0 ) ) ? 'checked="true"' : '' ); ?> />
383 </div>
384 </div>
385 <div class="ui grid field">
386 <label class="six wide column middle aligned"><?php esc_html_e( 'API Key', 'mainwp' ); ?></label>
387 <div class="five wide column">
388 <?php
389 $_api_key = Api_Backups_3rd_Party::get_vultr_api_key();
390 ?>
391 <input type="password" name="mainwp_vultr_api_key" id="mainwp_vultr_api_key" value="<?php echo esc_attr( $_api_key ); ?>" />
392 </div>
393 </div>
394 <?php
395 /**
396 * Action: vultr_api_form_bottom
397 *
398 * Fires at the bottom of Vultr API form.
399 *
400 * @since 4.1
401 */
402 do_action( 'vultr_api_form_bottom' );
403 ?>
404 <div class="ui divider"></div>
405 <input type="submit" name="submit" id="submit" class="ui green big button" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
406 <div style="clear:both"></div>
407 </form>
408 </div>
409 </div>
410
411 <div class="ui tab segment" data-tab="linode">
412 <h3 class="ui dividing header"><?php esc_html_e( 'Akamai (Linode) API Settings', 'mainwp' ); ?></h3>
413 <ul>
414 <li><?php printf( esc_html__( "1. If you don't already have one, get a %s", 'mainwp' ), '<a target="_blank" href="https://mainwp.com/go/akamai-linode/">Akamai (Linode) account</a>' ); ?></li>
415 <li><?php printf( esc_html__( '2. You may create a %1$sPersonal Access Token%2$s by navigating here: %3$s', 'mainwp' ), '<b>', '</b>', '<a target="_blank" href="https://cloud.linode.com/profile/tokens">https://cloud.linode.com/profile/tokens</a>' ); ?></b></li>
416 <li><?php printf( esc_html__( '3. Paste in your account %1$sPersonal Access Token%2$s below and click the Save Settings button.', 'mainwp' ), '<b>', '</b>' ); ?></li>
417 <li><?php esc_html_e( '4. Once the API is connected, go to the Site Edit page (for all sites on this host) and set the correct Provider and Instance ID.', 'mainwp' ); ?></li>
418 </ul>
419 <div class="ui hidden divider"></div>
420 <div class="ui form">
421 <form method="POST" action="">
422 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
423 <input type="hidden" name="wp_nonce_linode" value="<?php echo esc_attr( wp_create_nonce( $_nonce_slug ) ); ?>" />
424 <?php
425 /**
426 * Action: linode_api_form_top
427 *
428 * Fires at the top of Vultr API form.
429 *
430 * @since 4.1
431 */
432 do_action( 'linode_api_form_top' );
433 ?>
434 <div class="ui grid field">
435 <label class="six wide column middle aligned"><?php esc_html_e( 'Enable Akamai (Linode) API', 'mainwp' ); ?></label>
436 <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, the Akamai (Linode) API will be activated.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
437 <input type="checkbox" name="mainwp_enable_linode_api" id="mainwp_enable_linode_api" <?php echo ( ( 1 === (int) get_option( 'mainwp_enable_linode_api', 0 ) ) ? 'checked="true"' : '' ); ?> />
438 </div>
439 </div>
440 <?php
441 $_api_key = Api_Backups_3rd_Party::get_linode_api_key();
442 ?>
443 <div class="ui grid field">
444 <label class="six wide column middle aligned"><?php esc_html_e( 'API Key', 'mainwp' ); ?></label>
445 <div class="five wide column">
446 <input type="password" name="mainwp_linode_api_key" id="mainwp_linode_api_key" value="<?php echo esc_attr( $_api_key ); ?>" />
447 </div>
448 </div>
449 <?php
450 /**
451 * Action: linode_api_form_bottom
452 *
453 * Fires at the bottom of Vultr API form.
454 *
455 * @since 4.1
456 */
457 do_action( 'linode_api_form_bottom' );
458 ?>
459 <div class="ui divider"></div>
460 <input type="submit" name="submit" id="submit" class="ui green big button" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
461 <div style="clear:both"></div>
462 </form>
463 </div>
464 </div>
465
466 <div class="ui tab segment" data-tab="digitalocean">
467 <h3 class="ui dividing header"><?php esc_html_e( 'DigitalOcean', 'mainwp' ); ?></h3>
468 <ul>
469 <li><?php printf( esc_html__( "1. If you don't already have one, get a %s", 'mainwp' ), '<a target="_blank" href="https://mainwp.com/go/digital-ocean/">DigitalOcean account</a>' ); ?></li>
470 <li><?php printf( esc_html__( '2. You can generate an %1$sOAuth token%2$s by visiting the %3$s section of the DigitalOcean control panel for your account.', 'mainwp' ), '<b>', '</b>', '<a target="_blank" href="https://cloud.digitalocean.com/account/api/tokens">Apps & API</a>' ); ?></b></li>
471 <li><?php printf( esc_html__( '3. Paste in your %1$sPersonal Access Token%2$s below and click the Save Settings button.', 'mainwp' ), '<b>', '</b>' ); ?></li>
472 <li><?php esc_html_e( '4. Once the API is connected, go to the Site Edit page (for all sites on this host) and set the correct Provider and Instance ID.', 'mainwp' ); ?></li>
473 </ul>
474 <div class="ui hidden divider"></div>
475 <div class="ui form">
476 <form method="POST" action="">
477 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
478 <input type="hidden" name="wp_nonce_digitalocean" value="<?php echo esc_attr( wp_create_nonce( $_nonce_slug ) ); ?>" />
479 <?php
480 /**
481 * Action: digitalocean_api_form_top
482 *
483 * Fires at the top of DigitalOcean API form.
484 *
485 * @since 4.1
486 */
487 do_action( 'digitalocean_api_form_top' );
488 ?>
489 <div class="ui grid field">
490 <label class="six wide column middle aligned"><?php esc_html_e( 'Enable DigitalOcean API', 'mainwp' ); ?></label>
491 <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, the DigitalOcean API will be activated.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
492 <input type="checkbox" name="mainwp_enable_digitalocean_api" id="mainwp_enable_digitalocean_api" <?php echo ( ( 1 === (int) get_option( 'mainwp_enable_digitalocean_api', 0 ) ) ? 'checked="true"' : '' ); ?> />
493 </div>
494 </div>
495 <?php
496 $_api_key = Api_Backups_3rd_Party::get_digitalocean_api_key();
497 ?>
498 <div class="ui grid field">
499 <label class="six wide column middle aligned"><?php esc_html_e( 'API Key', 'mainwp' ); ?></label>
500 <div class="five wide column">
501 <input type="password" name="mainwp_digitalocean_api_key" id="mainwp_digitalocean_api_key" value="<?php echo esc_attr( $_api_key ); ?>" />
502 </div>
503 </div>
504 <?php
505 /**
506 * Action: digitalocean_api_form_bottom
507 *
508 * Fires at the bottom of DigitalOcean API form.
509 *
510 * @since 4.1
511 */
512 do_action( 'digitalocean_api_form_bottom' );
513 ?>
514 <div class="ui divider"></div>
515 <input type="submit" name="submit" id="submit" class="ui green big button" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
516 <div style="clear:both"></div>
517 </form>
518 </div>
519 </div>
520
521 <div class="ui tab segment" data-tab="cpanel">
522 <h3 class="ui dividing header"><?php esc_html_e( 'cPanel (WP Toolkit)', 'mainwp' ); ?></h3>
523 <ul>
524 <li><?php esc_html_e( '1. Enter in your cPanel URL below. ( eg. https://my-site.com:2083 )', 'mainwp' ); ?></li>
525 <li><?php esc_html_e( '2. Enter in your cPanel account Username and Password below.', 'mainwp' ); ?></li>
526 <li><?php esc_html_e( 'This information can be provided by your Child Site&#39;s Host.', 'mainwp' ); ?></li>
527 </ul>
528 <div class="ui hidden divider"></div>
529 <div class="ui form">
530 <form method="POST" action="">
531 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
532 <input type="hidden" name="wp_nonce_cpanel" value="<?php echo esc_attr( wp_create_nonce( $_nonce_slug ) ); ?>" />
533 <?php
534 /**
535 * Action: cpanel_api_form
536 *
537 * Fires at the top of cPanel API form.
538 *
539 * @since 4.1
540 */
541 do_action( 'cpanel_api_form' );
542 ?>
543 <div class="ui grid field">
544 <label class="six wide column middle aligned"><?php esc_html_e( 'Enable cPanel API', 'mainwp' ); ?></label>
545 <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, the cPanel API will be activated.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
546 <input type="checkbox" name="mainwp_enable_cpanel_api" id="mainwp_enable_cpanel_api" <?php echo ( ( 1 === (int) get_option( 'mainwp_enable_cpanel_api', 0 ) ) ? 'checked="true"' : '' ); ?> />
547 </div>
548 </div>
549 <div class="ui grid field">
550 <label class="six wide column middle aligned"><?php esc_html_e( 'cPanel URL', 'mainwp' ); ?></label>
551
552 <div class="five wide column">
553 <input type="text" name="mainwp_cpanel_url" id="mainwp_cpanel_url" value="<?php echo ( ( false === get_option( 'mainwp_cpanel_url' ) ) ? '' : esc_attr( get_option( 'mainwp_cpanel_url' ) ) ); ?>" />
554 </div>
555 </div>
556 <div class="ui grid field">
557 <label class="six wide column middle aligned"><?php esc_html_e( 'Username', 'mainwp' ); ?></label>
558
559 <div class="five wide column">
560 <input type="text" name="mainwp_cpanel_account_username" id="mainwp_cpanel_account_username" value="<?php echo ( ( false === get_option( 'mainwp_cpanel_account_username' ) ) ? '' : esc_attr( get_option( 'mainwp_cpanel_account_username' ) ) ); ?>" />
561 </div>
562 </div>
563 <div class="ui grid field">
564 <label class="six wide column middle aligned"><?php esc_html_e( 'Password', 'mainwp' ); ?></label>
565 <div class="five wide column">
566 <?php
567 $_api_key = Api_Backups_3rd_Party::get_cpanel_account_password();
568 ?>
569 <input type="password" name="mainwp_cpanel_account_password" id="mainwp_cpanel_account_password" value="<?php echo esc_attr( $_api_key ); ?>" />
570 </div>
571 </div>
572 <div class="ui grid field">
573 <label class="six wide column middle aligned"><?php esc_html_e( 'cPanel Site Path', 'mainwp' ); ?></label>
574
575 <div class="five wide column">
576 <input type="text" name="mainwp_cpanel_site_path" id="mainwp_cpanel_site_path" value="<?php echo ( ( false === get_option( 'mainwp_cpanel_site_path' ) ) ? '' : esc_attr( get_option( 'mainwp_cpanel_site_path' ) ) ); ?>" />
577 </div>
578 </div>
579 <?php
580 /**
581 * Action: cpanel_api_form_bottom
582 *
583 * Fires at the bottom of cPanel API form.
584 *
585 * @since 4.1
586 */
587 do_action( 'cpanel_api_form_bottom' );
588 ?>
589 <div class="ui divider"></div>
590 <input type="submit" name="submit" id="submit" class="ui green big button" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
591 <div style="clear:both"></div>
592 </form>
593 </div>
594 </div>
595
596 <div class="ui tab segment" data-tab="plesk">
597 <h3 class="ui dividing header"><?php esc_html_e( 'Plesk (WP Toolkit)', 'mainwp' ); ?></h3>
598 <ul>
599 <li><?php esc_html_e( '1. Login to your Plesk Account', 'mainwp' ); ?></li>
600 <li><?php esc_html_e( '2. Do a search for "Keychain for API Secret Keys" & install it.', 'mainwp' ); ?></li>
601 <li><?php esc_html_e( '3. Click Open > Click Add Secret Key > Add a description > Click OK', 'mainwp' ); ?></li>
602 <li><?php esc_html_e( '4. Copy & Paste your API Access Token below', 'mainwp' ); ?></li>
603 </ul>
604 <div class="ui hidden divider"></div>
605 <div class="ui form">
606 <form method="POST" action="">
607 <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
608 <input type="hidden" name="wp_nonce_plesk" value="<?php echo esc_attr( wp_create_nonce( $_nonce_slug ) ); ?>" />
609 <?php
610 /**
611 * Action: plesk_api_form_top
612 *
613 * Fires at the top of Plesk API form.
614 *
615 * @since 4.1
616 */
617 do_action( 'plesk_api_form_top' );
618 ?>
619 <div class="ui grid field">
620 <label class="six wide column middle aligned"><?php esc_html_e( 'Enable Plesk (WP Toolkit) API', 'mainwp' ); ?></label>
621 <div class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, the Plesk API will be activated.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
622 <input type="checkbox" name="mainwp_enable_plesk_api" id="mainwp_enable_plesk_api" <?php echo ( ( 1 === (int) get_option( 'mainwp_enable_plesk_api', 0 ) ) ? 'checked="true"' : '' ); ?> />
623 </div>
624 </div>
625 <div class="ui grid field">
626 <label class="six wide column middle aligned"><?php esc_html_e( 'Plesk URL', 'mainwp' ); ?></label>
627 <div class="five wide column" data-tooltip="<?php esc_attr_e( 'eg.: https://epic-snyder.123-111-123-143.plesk.page:8443', 'mainwp' ); ?>">
628 <input type="text" name="mainwp_plesk_api_url" id="mainwp_plesk_api_url" value="<?php echo ( ( false === get_option( 'mainwp_plesk_api_url' ) ) ? '' : esc_attr( get_option( 'mainwp_plesk_api_url' ) ) ); ?>" />
629 </div>
630 </div>
631 <div class="ui grid field">
632 <label class="six wide column middle aligned"><?php esc_html_e( 'API Key', 'mainwp' ); ?></label>
633
634 <?php
635 $_api_key = Api_Backups_3rd_Party::get_plesk_api_key();
636 ?>
637 <div class="five wide column">
638 <input type="password" name="mainwp_plesk_api_key" id="mainwp_plesk_api_key" value="<?php echo esc_attr( $_api_key ); ?>" />
639 </div>
640 </div>
641 <?php
642 /**
643 * Action: plesk_api_form_bottom
644 *
645 * Fires at the bottom of Plesk API form.
646 *
647 * @since 4.1
648 */
649 do_action( 'plesk_api_form_bottom' );
650 ?>
651 <div class="ui divider"></div>
652 <input type="submit" name="submit" id="submit" class="ui green big button" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>"/>
653 <div style="clear:both"></div>
654 </form>
655 </div>
656 </div>
657
658 </div>
659 </div>
660 </div>
661 </div>
662 <?php
663 }
664
665 /**
666 * Method hook_mainwp_update_site().
667 *
668 * @param int $website_id Website ID.
669 *
670 * @return void
671 */
672 public function hook_mainwp_update_site( $website_id ) { //phpcs:ignore -- complex method.
673 /**
674 * 3rd-Party Backup API Provider Settings.
675 *
676 * Update Backup API Provider Settings ( Individual Child Site Edit Page ),
677 */
678
679 //phpcs:disable WordPress.Security.NonceVerification.Missing
680 if ( ! isset( $_POST['mainwp_managesites_edit_module_api_backups_provider'] ) ) {
681 return;
682 }
683
684 $api_backup_provider = isset( $_POST['mainwp_managesites_edit_module_api_backups_provider'] ) && ! empty( $_POST['mainwp_managesites_edit_module_api_backups_provider'] ) ? intval( $_POST['mainwp_managesites_edit_module_api_backups_provider'] ) : '';
685 $api_backup_provider_name = '';
686
687 if ( ! empty( $api_backup_provider ) ) {
688 if ( 1 === $api_backup_provider ) {
689 $api_backup_provider_name = 'DigitalOcean';
690 } elseif ( 2 === $api_backup_provider ) {
691 $api_backup_provider_name = 'Linode';
692 } elseif ( 3 === $api_backup_provider ) {
693 $api_backup_provider_name = 'Vultr';
694 } elseif ( 4 === $api_backup_provider ) {
695 $api_backup_provider_name = 'cPanel';
696 } elseif ( 5 === $api_backup_provider ) {
697 $api_backup_provider_name = 'Plesk';
698 }
699 }
700
701 // Store the 3rd Party Backup Provider.
702 Api_Backups_Helper::update_website_option( $website_id, 'mainwp_3rd_party_api', $api_backup_provider_name );
703
704 // Store the 3rd Party Backup Provider Instance ID.
705 $api_backup_instance_id = isset( $_POST['edit_site_module_api_backups_provider_instance_id'] ) ? sanitize_text_field( wp_unslash( $_POST['edit_site_module_api_backups_provider_instance_id'] ) ) : '';
706 Api_Backups_Helper::update_website_option( $website_id, 'mainwp_3rd_party_instance_id', $api_backup_instance_id );
707
708 // Store the cPanel Individual API URL.
709 $cpanel_api_url = isset( $_POST['cpanel_api_url'] ) ? wp_unslash( $_POST['cpanel_api_url'] ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
710 Api_Backups_Helper::update_website_option( $website_id, 'cpanel_api_url', $cpanel_api_url );
711
712 // Store cPanel Individual or Global toggle.
713 $mainwp_enable_wp_toolkit = isset( $_POST['mainwp_enable_wp_toolkit'] ) ? wp_unslash( $_POST['mainwp_enable_wp_toolkit'] ) : '0'; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
714 Api_Backups_Helper::update_website_option( $website_id, 'mainwp_enable_wp_toolkit', $mainwp_enable_wp_toolkit );
715
716 // Store cPanel Individual or Global toggle.
717 $enable_cpanel_individual = isset( $_POST['mainwp_enable_cpanel_individual'] ) ? wp_unslash( $_POST['mainwp_enable_cpanel_individual'] ) : '0';//phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
718 Api_Backups_Helper::update_website_option( $website_id, 'mainwp_enable_cpanel_individual', $enable_cpanel_individual );
719
720 // Store cPanel Individual Account Username.
721 $cpanel_account_username = isset( $_POST['mainwp_cpanel_account_username'] ) ? wp_unslash( $_POST['mainwp_cpanel_account_username'] ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
722 Api_Backups_Helper::update_website_option( $website_id, 'cpanel_account_username', $cpanel_account_username );
723
724 // Store cPanel Individual Account Password.
725 $cpanel_account_password = isset( $_POST['mainwp_cpanel_account_password'] ) ? wp_unslash( $_POST['mainwp_cpanel_account_password'] ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
726 Api_Backups_Utility::get_instance()->update_child_api_key( $website_id, 'cpanel', $cpanel_account_password );
727
728 // Store cPanel Individual Site Path.
729 $cpanel_site_path = isset( $_POST['cpanel_site_path'] ) ? wp_unslash( $_POST['cpanel_site_path'] ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
730 Api_Backups_Helper::update_website_option( $website_id, 'cpanel_site_path', $cpanel_site_path );
731
732 // Store Plesk Individual or Global toggle.
733 $enable_plesk_individual = isset( $_POST['mainwp_enable_plesk_individual'] ) ? wp_unslash( $_POST['mainwp_enable_plesk_individual'] ) : '0'; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
734 Api_Backups_Helper::update_website_option( $website_id, 'mainwp_enable_plesk_individual', $enable_plesk_individual );
735
736 // Store Plesk Individual API URL.
737 $plesk_api_url = isset( $_POST['plesk_api_url'] ) ? wp_unslash( $_POST['plesk_api_url'] ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
738 Api_Backups_Helper::update_website_option( $website_id, 'plesk_api_url', rtrim( $plesk_api_url, '/' ) );
739
740 // Store Plesk Individual Installation ID.
741 $plesk_installation_id = isset( $_POST['plesk_installation_id'] ) ? wp_unslash( $_POST['plesk_installation_id'] ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
742 Api_Backups_Helper::update_website_option( $website_id, 'mainwp_plesk_installation_id', $plesk_installation_id );
743
744 // Store Plesk Individual API Key.
745 $plesk_api_key = isset( $_POST['mainwp_plesk_api_key'] ) ? wp_unslash( $_POST['mainwp_plesk_api_key'] ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
746 Api_Backups_Utility::get_instance()->update_child_api_key( $website_id, 'plesk', $plesk_api_key );
747 //phpcs:enable
748 }
749
750 /**
751 * Method hook_render_mainwp_manage_sites_edit().
752 *
753 * @param mixed $website Website.
754 * @return mixed
755 */
756 public function hook_render_mainwp_manage_sites_edit( $website ) { //phpcs:ignore -- complex method.
757
758 if ( empty( $website ) ) {
759 return;
760 }
761
762 $mainwp_3rd_party_api = '';
763 $mainwp_3rd_party_instance_id = '';
764 $mainwp_3rd_party_cloudways_app_id = '';
765 $mainwp_3rd_party_cloudways_server_id = '';
766 $mainwp_3rd_party_gridpane_site_id = '';
767 $mainwp_cpanel_api_url = '';
768 $mainwp_cpanel_site_path = '';
769 $mainwp_cpanel_account_username = '';
770 $mainwp_plesk_api_url = '';
771
772 if ( is_object( $website ) && property_exists( $website, 'id' ) ) {
773 $opts = Api_Backups_Helper::get_website_options(
774 $website,
775 array(
776 'mainwp_3rd_party_api',
777 'mainwp_3rd_party_instance_id',
778 'mainwp_3rd_party_app_id',
779 'mainwp_enable_wp_toolkit',
780 'mainwp_enable_cpanel_individual',
781 'mainwp_enable_plesk_individual',
782 'cpanel_api_url',
783 'cpanel_site_path',
784 'cpanel_account_username',
785 'plesk_api_url',
786 'mainwp_plesk_installation_id',
787 )
788 );
789
790 if ( is_array( $opts ) ) {
791 $mainwp_3rd_party_api = isset( $opts['mainwp_3rd_party_api'] ) ? $opts['mainwp_3rd_party_api'] : '';
792 $mainwp_3rd_party_instance_id = isset( $opts['mainwp_3rd_party_instance_id'] ) ? $opts['mainwp_3rd_party_instance_id'] : '';
793 $mainwp_3rd_party_cloudways_app_id = isset( $opts['mainwp_3rd_party_app_id'] ) ? $opts['mainwp_3rd_party_app_id'] : '';
794 $mainwp_3rd_party_cloudways_server_id = isset( $opts['mainwp_3rd_party_instance_id'] ) ? $opts['mainwp_3rd_party_instance_id'] : '';
795 $mainwp_3rd_party_gridpane_site_id = isset( $opts['mainwp_3rd_party_instance_id'] ) ? $opts['mainwp_3rd_party_instance_id'] : '';
796 $mainwp_enable_wp_toolkit = isset( $opts['mainwp_enable_wp_toolkit'] ) ? $opts['mainwp_enable_wp_toolkit'] : '0';
797 $mainwp_enable_cpanel_individual = isset( $opts['mainwp_enable_cpanel_individual'] ) ? $opts['mainwp_enable_cpanel_individual'] : '0';
798 $mainwp_enable_plesk_individual = isset( $opts['mainwp_enable_plesk_individual'] ) ? $opts['mainwp_enable_plesk_individual'] : '0';
799 $mainwp_cpanel_api_url = isset( $opts['cpanel_api_url'] ) ? $opts['cpanel_api_url'] : '';
800 $mainwp_cpanel_site_path = isset( $opts['cpanel_site_path'] ) ? $opts['cpanel_site_path'] : '';
801 $mainwp_cpanel_account_username = isset( $opts['cpanel_account_username'] ) ? $opts['cpanel_account_username'] : '';
802 $mainwp_plesk_api_url = isset( $opts['plesk_api_url'] ) ? $opts['plesk_api_url'] : '';
803 $mainwp_plesk_installation_id = isset( $opts['mainwp_plesk_installation_id'] ) ? $opts['mainwp_plesk_installation_id'] : '';
804 }
805 }
806
807 ?>
808 <h3 class="ui dividing header">
809 <?php esc_html_e( 'Backup API Provider Settings', 'mainwp' ); ?>
810 <div class="sub header"><?php esc_html_e( 'Use the provided settings to set your Backup API provider. Sites hosted on Cloudways and Gridpane do not require these settings.', 'mainwp' ); ?></div>
811 <div class="sub header"><?php esc_html_e( 'Use these settings to select Provider and instance ID only if the site is hosted on DigitalOcean, Akamai (Linode), or Vultr hosting.', 'mainwp' ); ?></div>
812 <div class="sub header"><?php esc_html_e( 'Sites hosted on Cloudways and GridPane do not require these settings to be added manually. All the necessary info for the feature will be obtained automatically so you can leave these settings blank.', 'mainwp' ); ?></div>
813 </h3>
814 <?php if ( '' === $mainwp_3rd_party_api || 'cPanel' === $mainwp_3rd_party_api || 'Plesk' === $mainwp_3rd_party_api ) : ?>
815 <div class="ui grid field">
816 <label class="six wide column middle aligned"><?php esc_html_e( 'Choose a provider', 'mainwp' ); ?></label>
817 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Detected provider', 'mainwp' ); ?>" data-inverted="" data-position="top left">
818 <select class="ui dropdown" id="mainwp_managesites_edit_module_api_backups_provider" name="mainwp_managesites_edit_module_api_backups_provider">
819 <option <?php echo ( '' === $mainwp_3rd_party_api ) ? 'selected' : ''; ?> value="0"><?php esc_html_e( 'None', 'mainwp' ); ?></option>
820 <option <?php echo ( 'DigitalOcean' === $mainwp_3rd_party_api ) ? 'selected' : ''; ?> value="1"><?php esc_html_e( 'DigitalOcean', 'mainwp' ); ?></option>
821 <option <?php echo ( 'Linode' === $mainwp_3rd_party_api ) ? 'selected' : ''; ?> value="2"><?php esc_html_e( 'Akamai (Linode)', 'mainwp' ); ?></option>
822 <option <?php echo ( 'Vultr' === $mainwp_3rd_party_api ) ? 'selected' : ''; ?> value="3"><?php esc_html_e( 'Vultr', 'mainwp' ); ?></option>
823 <option <?php echo ( 'cPanel' === $mainwp_3rd_party_api ) ? 'selected' : ''; ?> value="4"><?php esc_html_e( 'cPanel (WP Toolkit)', 'mainwp' ); ?></option>
824 <option <?php echo ( 'Plesk' === $mainwp_3rd_party_api ) ? 'selected' : ''; ?> value="5"><?php esc_html_e( 'Plesk (WP Toolkit)', 'mainwp' ); ?></option>
825 </select>
826 </div>
827 </div>
828 <div class="mainwp_cpanel_menu_container" style="display:none;">
829 <div class="ui grid field">
830 <label class="six wide column middle aligned"><?php esc_html_e( 'Enable WP Toolkit API', 'mainwp' ); ?></label>
831 <div id="enable_wp_toolkit_check" class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, the WP Toolkit API will also be active.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
832 <input type="checkbox" name="mainwp_enable_wp_toolkit" id="mainwp_enable_wp_toolkit" <?php echo ( ( 'on' === $mainwp_enable_wp_toolkit ) ? 'checked="true"' : 'off' ); ?> />
833 </div>
834 </div>
835 <div class="ui grid field">
836 <label class="six wide column middle aligned"><?php esc_html_e( 'Overwrite cPanel Global Settings', 'mainwp' ); ?></label>
837 <div id="individual_settings_check" class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, the cPanel Individual Settings will be used.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
838 <input type="checkbox" name="mainwp_enable_cpanel_individual" id="mainwp_enable_cpanel_individual" <?php echo ( ( 'on' === $mainwp_enable_cpanel_individual ) ? 'checked="true"' : 'off' ); ?> />
839 </div>
840 </div>
841 <div class="mainwp_cpanel_individual_container" style="display:none;">
842 <div class="ui grid field">
843 <label class="six wide column middle aligned"><?php esc_html_e( 'cPanel URL', 'mainwp' ); ?></label>
844 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Enter the cPanel API URL. eg.: https://yoursite.com:2083', 'mainwp' ); ?>" data-inverted="" data-position="top left">
845 <div class="ui left labeled input">
846 <input type="text" id="cpanel_api_url" name="cpanel_api_url" value="<?php echo ( empty( $mainwp_cpanel_api_url ) ? '' : esc_attr( $mainwp_cpanel_api_url ) ); ?>" />
847 </div>
848 </div>
849 </div>
850 <div class="ui grid field">
851 <label class="six wide column middle aligned"><?php esc_html_e( 'Username', 'mainwp' ); ?></label>
852 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Enter the cPanel Account Username.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
853 <div class="ui left labeled input">
854 <input type="text" name="mainwp_cpanel_account_username" id="mainwp_cpanel_account_username" value="<?php echo ( empty( $mainwp_cpanel_account_username ) ? '' : esc_attr( $mainwp_cpanel_account_username ) ); ?>" />
855 </div>
856 </div>
857 </div>
858 <div class="ui grid field">
859 <label class="six wide column middle aligned"><?php esc_html_e( 'Password', 'mainwp' ); ?></label>
860 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Enter the cPanel Account Password.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
861 <div class="ui left labeled input">
862 <?php
863 $cpanel_account_password = Api_Backups_Utility::get_instance()->get_child_api_key( $website, 'cpanel' );
864 ?>
865 <input type="password" name="mainwp_cpanel_account_password" id="mainwp_cpanel_account_password" value="<?php echo esc_attr( $cpanel_account_password ); ?>" />
866 </div>
867 </div>
868 </div>
869 <div class="ui grid field">
870 <label class="six wide column middle aligned"><?php esc_html_e( 'Site Path', 'mainwp' ); ?></label>
871 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Enter the directory the site is installed. eg.: /public_html/child/', 'mainwp' ); ?>" data-inverted="" data-position="top left">
872 <div class="ui left labeled input">
873 <input type="text" id="cpanel_site_path" name="cpanel_site_path" value="<?php echo ( empty( $mainwp_cpanel_site_path ) ? '' : esc_attr( $mainwp_cpanel_site_path ) ); ?>" />
874 </div>
875 </div>
876 </div>
877 </div>
878 </div>
879 <div class="mainwp_plesk_menu_container" style="display:none;">
880 <div class="ui grid field">
881 <label class="six wide column middle aligned"><?php esc_html_e( 'Installation ID', 'mainwp' ); ?></label>
882 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Enter the Plesk Installation ID. eg.: "1"', 'mainwp' ); ?>" data-inverted="" data-position="top left">
883 <div class="ui left labeled input">
884 <input type="text" id="plesk_installation_id" name="plesk_installation_id" value="<?php echo ( empty( $mainwp_plesk_installation_id ) ? '' : esc_html( $mainwp_plesk_installation_id ) ); ?>" />
885 </div>
886 </div>
887 </div>
888 <div class="ui grid field">
889 <label class="six wide column middle aligned"><?php esc_html_e( 'Overwrite Global Settings', 'mainwp' ); ?></label>
890 <div id="individual_settings_check" class="ten wide column ui toggle checkbox" data-tooltip="<?php esc_attr_e( 'If enabled, the Plesk (WP Toolkit) Individual Settings will be used.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left">
891 <input type="checkbox" name="mainwp_enable_plesk_individual" id="mainwp_enable_plesk_individual" <?php echo ( ( 'on' === $mainwp_enable_plesk_individual ) ? 'checked="true"' : 'off' ); ?> />
892 </div>
893 </div>
894 <div class="mainwp_plesk_individual_container" style="display:none;">
895 <div class="ui grid field">
896 <label class="six wide column middle aligned"><?php esc_html_e( 'Plesk URL', 'mainwp' ); ?></label>
897 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'eg.: https://epic-snyder.123-111-123-143.plesk.page:8443', 'mainwp' ); ?>" data-inverted="" data-position="top left">
898 <div class="ui left labeled input">
899 <input type="text" id="plesk_api_url" name="plesk_api_url" value="<?php echo ( empty( $mainwp_plesk_api_url ) ? '' : esc_attr( $mainwp_plesk_api_url ) ); ?>" />
900 </div>
901 </div>
902 </div>
903 <div class="ui grid field">
904 <label class="six wide column middle aligned"><?php esc_html_e( 'API Key', 'mainwp' ); ?></label>
905 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Enter the Plesk API Key', 'mainwp' ); ?>" data-inverted="" data-position="top left">
906 <div class="ui left labeled input">
907 <?php
908 $plesk_api_key = Api_Backups_Utility::get_instance()->get_child_api_key( $website, 'plesk' );
909 ?>
910 <input type="password" name="mainwp_plesk_api_key" id="mainwp_plesk_api_key" value="<?php echo esc_attr( $plesk_api_key ); ?>" />
911 </div>
912 </div>
913 </div>
914 </div>
915 </div>
916
917 <div class="ui hidden divider"></div>
918 <?php elseif ( 'DigitalOcean' === $mainwp_3rd_party_api || 'Linode' === $mainwp_3rd_party_api || 'Vultr' === $mainwp_3rd_party_api ) : ?>
919 <div class="ui grid field">
920 <label class="six wide column middle aligned"><?php esc_html_e( 'Choose a provider', 'mainwp' ); ?></label>
921 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Detected provider', 'mainwp' ); ?>" data-inverted="" data-position="top left">
922 <select class="ui dropdown" id="mainwp_managesites_edit_module_api_backups_provider" name="mainwp_managesites_edit_module_api_backups_provider">
923 <option <?php echo ( '' === $mainwp_3rd_party_api ) ? 'selected' : ''; ?> value="0"><?php esc_html_e( 'None', 'mainwp' ); ?></option>
924 <option <?php echo ( 'DigitalOcean' === $mainwp_3rd_party_api ) ? 'selected' : ''; ?> value="1"><?php esc_html_e( 'DigitalOcean', 'mainwp' ); ?></option>
925 <option <?php echo ( 'Linode' === $mainwp_3rd_party_api ) ? 'selected' : ''; ?> value="2"><?php esc_html_e( 'Akamai (Linode)', 'mainwp' ); ?></option>
926 <option <?php echo ( 'Vultr' === $mainwp_3rd_party_api ) ? 'selected' : ''; ?> value="3"><?php esc_html_e( 'Vultr', 'mainwp' ); ?></option>
927 <option <?php echo ( 'cPanel' === $mainwp_3rd_party_api ) ? 'selected' : ''; ?> value="4"><?php esc_html_e( 'cPanel (WP Toolkit)', 'mainwp' ); ?></option>
928 <option <?php echo ( 'Plesk' === $mainwp_3rd_party_api ) ? 'selected' : ''; ?> value="5"><?php esc_html_e( 'Plesk (WP Toolkit)', 'mainwp' ); ?></option>
929 </select>
930 </div>
931 </div>
932 <?php $instance_id = $mainwp_3rd_party_instance_id; ?>
933 <div class="ui grid field">
934 <label class="six wide column middle aligned"><?php esc_html_e( 'Instance ID', 'mainwp' ); ?></label>
935 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Enter the Instance ID (Droplet ID). This information is available in your provider account.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
936 <div class="ui left labeled input">
937 <input type="text" id="edit_site_module_api_backups_provider_instance_id" name="edit_site_module_api_backups_provider_instance_id" value="<?php echo ( empty( $instance_id ) ? '' : esc_attr( $instance_id ) ); ?>" />
938 </div>
939 </div>
940 </div>
941 <?php elseif ( 'Cloudways' === $mainwp_3rd_party_api ) : ?>
942 <div class="ui grid field">
943 <label class="six wide column middle aligned"><?php esc_html_e( 'Choose a provider', 'mainwp' ); ?></label>
944 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Detected provider', 'mainwp' ); ?>" data-inverted="" data-position="top left">
945 <select class="ui disabled dropdown">
946 <option><?php esc_html_e( 'Cloudways', 'mainwp' ); ?></option>
947 </select>
948 </div>
949 </div>
950 <?php $app_id = $mainwp_3rd_party_cloudways_app_id; ?>
951 <?php $server_id = $mainwp_3rd_party_cloudways_server_id; ?>
952 <div class="ui grid field">
953 <label class="six wide column middle aligned"><?php esc_html_e( 'App ID', 'mainwp' ); ?></label>
954 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Detected Cloudways site ID.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
955 <div class="ui left labeled input">
956 <input type="text" disabled value="<?php echo esc_attr( $app_id ); ?>" />
957 </div>
958 </div>
959 </div>
960 <div class="ui grid field">
961 <label class="six wide column middle aligned"><?php esc_html_e( 'Instance ID', 'mainwp' ); ?></label>
962 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Detected Cloudways site ID.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
963 <div class="ui left labeled input">
964 <input type="text" disabled value="<?php echo esc_attr( $server_id ); ?>" />
965 </div>
966 </div>
967 </div>
968 <?php elseif ( 'GridPane' === $mainwp_3rd_party_api ) : ?>
969 <div class="ui grid field">
970 <label class="six wide column middle aligned"><?php esc_html_e( 'Choose a provider', 'mainwp' ); ?></label>
971 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Detected provider', 'mainwp' ); ?>" data-inverted="" data-position="top left">
972 <select class="ui disabled dropdown">
973 <option><?php esc_html_e( 'GridPane (Developer or higher)', 'mainwp' ); ?></option>
974 </select>
975 </div>
976 </div>
977 <?php $instance_id = $mainwp_3rd_party_gridpane_site_id; ?>
978 <div class="ui grid field">
979 <label class="six wide column middle aligned"><?php esc_html_e( 'Instance ID', 'mainwp' ); ?></label>
980 <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Detected GridPane site ID.', 'mainwp' ); ?>" data-inverted="" data-position="top left">
981 <div class="ui left labeled input">
982 <input type="text" disabled value="<?php echo esc_attr( $instance_id ); ?>" />
983 </div>
984 </div>
985 </div>
986 <?php endif; ?>
987 <script type="text/javascript">
988 jQuery( document ).ready( function() {
989
990 // Check if cPanel or Plesk is selected when page loads.
991 var dropdown_selection = jQuery("#mainwp_managesites_edit_module_api_backups_provider" ).val();
992 if ( dropdown_selection === '4' ) {
993 jQuery('.mainwp_cpanel_menu_container').show();
994 jQuery('.mainwp_plesk_menu_container').hide();
995 } else if ( dropdown_selection === '5' ) {
996 jQuery('.mainwp_plesk_menu_container').show();
997 jQuery('.mainwp_cpanel_menu_container').hide();
998 } else {
999 jQuery('.mainwp_cpanel_menu_container').hide();
1000 jQuery('.mainwp_plesk_menu_container').hide();
1001 }
1002
1003
1004 // Check if cPanel Individual Settings is :checked when page loads.
1005 if ( jQuery( "#mainwp_enable_cpanel_individual" ).is( ":checked" ) ) {
1006 jQuery('.mainwp_cpanel_individual_container').show();
1007 } else if ( jQuery( "#mainwp_enable_plesk_individual" ).is( ":checked" ) ) {
1008 jQuery('.mainwp_plesk_individual_container').show();
1009 } else {
1010 jQuery('.mainwp_cpanel_individual_container').hide();
1011 jQuery('.mainwp_plesk_individual_container').hide();
1012 }
1013
1014 // Check if cPanel is selected when using dropdown.
1015 jQuery( "#mainwp_managesites_edit_module_api_backups_provider" ).on( "change", function() {
1016
1017 var selected = jQuery(this).val();
1018
1019 if ( selected === '4') {
1020 jQuery( '.mainwp_cpanel_menu_container').show();
1021 jQuery( '.mainwp_plesk_menu_container').hide();
1022 } else if ( selected === '5' ){
1023 jQuery( '.mainwp_plesk_menu_container').show();
1024 jQuery( '.mainwp_cpanel_menu_container').hide();
1025 } else {
1026 jQuery( '.mainwp_cpanel_menu_container').hide();
1027 jQuery( '.mainwp_plesk_menu_container').hide();
1028 }
1029 } );
1030
1031 // Toggle cPanel Individual Settings on/off when clicked.
1032 jQuery( "#mainwp_enable_cpanel_individual" ).on( "change", function() {
1033
1034 jQuery('.mainwp_cpanel_individual_container').toggle();
1035
1036 } );
1037
1038 // Toggle Plesk Individual Settings on/off when clicked.
1039 jQuery( "#mainwp_enable_plesk_individual" ).on( "change", function() {
1040
1041 jQuery('.mainwp_plesk_individual_container').toggle();
1042 } );
1043 } );
1044 </script>
1045 <?php
1046 } // [ END: hook_render_mainwp_manage_sites_edit ]
1047 } // [ END: class Api_Backups_Settings ]
1048