PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.0.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.0.1
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.1, at modules/api-backups/classes/class-api-backups-settings.php

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