← All changes
|
modules/api-backups/classes/class-api-backups-settings.php
+47
-15
6.0.12
→
6.2.1
View file →
| @@ -9,8 +9,9 @@ | ||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | namespace MainWP\Dashboard\Module\ApiBackups; |
| 12 | 12 | |
| 13 | +use MainWP\Dashboard\MainWP_Credential_Render; | |
| 13 | 14 | use MainWP\Dashboard\MainWP_UI; |
| 14 | 15 | use MainWP\Dashboard\MainWP_Settings_Indicator; |
| 15 | 16 | use MainWP\Dashboard\MainWP_Settings; |
| 16 | 17 | |
| @@ -201,9 +202,11 @@ | ||
| 201 | 202 | ?> |
| 202 | 203 | <?php if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce_cloudways'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce_cloudways'] ), 'cloudways_api_form_general' ) ) : ?> |
| 203 | 204 | <?php Api_Backups_Utility::update_option( 'mainwp_enable_cloudways_api', ( ! isset( $_POST['mainwp_enable_cloudways_api'] ) ? 0 : 1 ) ); ?> |
| 204 | 205 | <?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'] ) : '' ) ); ?> |
| 206 | + <?php Api_Backups_Utility::update_option( 'mainwp_show_legacy_cloudways_credentials', ! empty( $_POST['mainwp_show_legacy_cloudways_credentials'] ) ? 1 : 0 ); ?> | |
| 205 | 207 | <?php Api_Backups_Utility::get_instance()->update_api_key( 'cloudways', ( isset( $_POST['mainwp_cloudways_api_key'] ) ? wp_unslash( $_POST['mainwp_cloudways_api_key'] ) : '' ) ); ?> |
| 208 | + <?php Api_Backups_Utility::get_instance()->update_api_key( 'cloudways', ( isset( $_POST['mainwp_cloudways_access_token'] ) ? wp_unslash( $_POST['mainwp_cloudways_access_token'] ) : '' ), 'access_token' ); ?> | |
| 206 | 209 | <div class="ui green message"><i class="close icon"></i><?php esc_html_e( 'API credentials have been successfully saved.', 'mainwp' ); ?></div> |
| 207 | 210 | <?php |
| 208 | 211 | Api_Backups_3rd_Party::cloudways_action_update_ids(); |
| 209 | 212 | $saved_settings = true; |
| @@ -346,10 +349,41 @@ | ||
| 346 | 349 | <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"> |
| 347 | 350 | <input type="checkbox" class="settings-field-value-change-handler" name="mainwp_enable_cloudways_api" id="mainwp_enable_cloudways_api" <?php echo 1 === (int) get_option( 'mainwp_enable_cloudways_api', 0 ) ? 'checked="true"' : ''; ?> /> |
| 348 | 351 | </div> |
| 349 | 352 | </div> |
| 353 | + <?php | |
| 354 | + $cld_access_token = Api_Backups_3rd_Party::get_cloudways_access_token(); | |
| 355 | + ?> | |
| 350 | 356 | <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-cloudways-settings"> |
| 351 | 357 | <label class="six wide column middle aligned"> |
| 358 | + <?php | |
| 359 | + MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', $cld_access_token ); | |
| 360 | + esc_html_e( 'Access Token', 'mainwp' ); | |
| 361 | + ?> | |
| 362 | + </label> | |
| 363 | + <div class="five wide column"> | |
| 364 | + <input type="password" class="settings-field-value-change-handler" name="mainwp_cloudways_access_token" id="mainwp_cloudways_access_token" value="<?php echo esc_attr( MainWP_Credential_Render::value_for_input( ! empty( $cld_access_token ) ) ); ?>" autocomplete="new-password" /> | |
| 365 | + </div> | |
| 366 | + </div> | |
| 367 | + <?php | |
| 368 | + $_api_key = Api_Backups_3rd_Party::get_cloudways_api_key(); | |
| 369 | + $show_legacy_cloudways_creds = get_option( 'mainwp_show_legacy_cloudways_credentials' ); | |
| 370 | + if ( false === $show_legacy_cloudways_creds && ! empty( $_api_key ) ) { | |
| 371 | + $show_legacy_cloudways_creds = 1; | |
| 372 | + Api_Backups_Utility::update_option( 'mainwp_show_legacy_cloudways_credentials', $show_legacy_cloudways_creds ); | |
| 373 | + } | |
| 374 | + ?> | |
| 375 | + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-cloudways-settings"> | |
| 376 | + <label class="six wide column middle aligned"> | |
| 377 | + <?php MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', get_option( 'mainwp_show_legacy_cloudways_credentials', 0 ) ); ?> | |
| 378 | + <?php esc_html_e( 'Show Legacy API Credentials', 'mainwp' ); ?></label> | |
| 379 | + <div class="ten wide column ui toggle checkbox mainwp-checkbox-showhide-elements" hide-parent="hide-legacy-cloudways" data-tooltip="<?php esc_attr_e( 'If enabled, the legacy Cloudways API will be visible.', 'mainwp' ); ?>" data-inverted="" data-position="bottom left"> | |
| 380 | + <input type="checkbox" class="settings-field-value-change-handler" name="mainwp_show_legacy_cloudways_credentials" id="mainwp_show_legacy_cloudways_credentials" <?php echo 1 === (int) $show_legacy_cloudways_creds ? 'checked="true"' : ''; ?> /> | |
| 381 | + </div> | |
| 382 | + </div> | |
| 383 | + | |
| 384 | + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-cloudways-settings" hide-element="hide-legacy-cloudways" <?php echo $show_legacy_cloudways_creds ? '' : 'style="display:none;"'; ?> > | |
| 385 | + <label class="six wide column middle aligned"> | |
| 352 | 386 | <?php |
| 353 | 387 | MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', get_option( 'mainwp_cloudways_api_account_email' ) ); |
| 354 | 388 | esc_html_e( 'Account Email', 'mainwp' ); |
| 355 | 389 | ?> |
| @@ -357,12 +391,9 @@ | ||
| 357 | 391 | <div class="five wide column"> |
| 358 | 392 | <input type="text" class="settings-field-value-change-handler" 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' ) ); ?>" /> |
| 359 | 393 | </div> |
| 360 | 394 | </div> |
| 361 | - <?php | |
| 362 | - $_api_key = Api_Backups_3rd_Party::get_cloudways_api_key(); | |
| 363 | - ?> | |
| 364 | - <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-cloudways-settings"> | |
| 395 | + <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-cloudways-settings" hide-element="hide-legacy-cloudways" <?php echo $show_legacy_cloudways_creds ? '' : 'style="display:none;"'; ?>> | |
| 365 | 396 | <label class="six wide column middle aligned"> |
| 366 | 397 | <?php |
| 367 | 398 | MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', $_api_key ); |
| 368 | 399 | esc_html_e( 'API Key', 'mainwp' ); |
| @@ -368,9 +399,9 @@ | ||
| 368 | 399 | esc_html_e( 'API Key', 'mainwp' ); |
| 369 | 400 | ?> |
| 370 | 401 | </label> |
| 371 | 402 | <div class="five wide column"> |
| 372 | - <input type="password" class="settings-field-value-change-handler" name="mainwp_cloudways_api_key" id="mainwp_cloudways_api_key" value="<?php echo esc_attr( $_api_key ); ?>" /> | |
| 403 | + <input type="password" class="settings-field-value-change-handler" name="mainwp_cloudways_api_key" id="mainwp_cloudways_api_key" value="<?php echo esc_attr( MainWP_Credential_Render::value_for_input( ! empty( $_api_key ) ) ); ?>" autocomplete="new-password" /> | |
| 373 | 404 | </div> |
| 374 | 405 | </div> |
| 375 | 406 | <?php |
| 376 | 407 | /** |
| @@ -435,9 +466,9 @@ | ||
| 435 | 466 | esc_html_e( 'Personal Access Token', 'mainwp' ); |
| 436 | 467 | ?> |
| 437 | 468 | </label> |
| 438 | 469 | <div class="five wide column"> |
| 439 | - <input type="password" class="settings-field-value-change-handler" name="mainwp_gridpane_api_key" id="mainwp_gridpane_api_key" value="<?php echo esc_attr( $_api_key ); ?>" /> | |
| 470 | + <input type="password" class="settings-field-value-change-handler" name="mainwp_gridpane_api_key" id="mainwp_gridpane_api_key" value="<?php echo esc_attr( MainWP_Credential_Render::value_for_input( ! empty( $_api_key ) ) ); ?>" autocomplete="new-password" /> | |
| 440 | 471 | </div> |
| 441 | 472 | </div> |
| 442 | 473 | <?php |
| 443 | 474 | /** |
| @@ -503,9 +534,9 @@ | ||
| 503 | 534 | esc_html_e( 'API Key', 'mainwp' ); |
| 504 | 535 | ?> |
| 505 | 536 | </label> |
| 506 | 537 | <div class="five wide column"> |
| 507 | - <input type="password" class="settings-field-value-change-handler" name="mainwp_vultr_api_key" id="mainwp_vultr_api_key" value="<?php echo esc_attr( $_api_key ); ?>" /> | |
| 538 | + <input type="password" class="settings-field-value-change-handler" name="mainwp_vultr_api_key" id="mainwp_vultr_api_key" value="<?php echo esc_attr( MainWP_Credential_Render::value_for_input( ! empty( $_api_key ) ) ); ?>" autocomplete="new-password" /> | |
| 508 | 539 | </div> |
| 509 | 540 | </div> |
| 510 | 541 | <?php |
| 511 | 542 | /** |
| @@ -572,9 +603,9 @@ | ||
| 572 | 603 | esc_html_e( 'API Key', 'mainwp' ); |
| 573 | 604 | ?> |
| 574 | 605 | </label> |
| 575 | 606 | <div class="five wide column"> |
| 576 | - <input type="password" class="settings-field-value-change-handler" name="mainwp_linode_api_key" id="mainwp_linode_api_key" value="<?php echo esc_attr( $_api_key ); ?>" /> | |
| 607 | + <input type="password" class="settings-field-value-change-handler" name="mainwp_linode_api_key" id="mainwp_linode_api_key" value="<?php echo esc_attr( MainWP_Credential_Render::value_for_input( ! empty( $_api_key ) ) ); ?>" autocomplete="new-password" /> | |
| 577 | 608 | </div> |
| 578 | 609 | </div> |
| 579 | 610 | <?php |
| 580 | 611 | /** |
| @@ -641,9 +672,9 @@ | ||
| 641 | 672 | esc_html_e( 'API Key', 'mainwp' ); |
| 642 | 673 | ?> |
| 643 | 674 | </label> |
| 644 | 675 | <div class="five wide column"> |
| 645 | - <input type="password" class="settings-field-value-change-handler" name="mainwp_digitalocean_api_key" id="mainwp_digitalocean_api_key" value="<?php echo esc_attr( $_api_key ); ?>" /> | |
| 676 | + <input type="password" class="settings-field-value-change-handler" name="mainwp_digitalocean_api_key" id="mainwp_digitalocean_api_key" value="<?php echo esc_attr( MainWP_Credential_Render::value_for_input( ! empty( $_api_key ) ) ); ?>" autocomplete="new-password" /> | |
| 646 | 677 | </div> |
| 647 | 678 | </div> |
| 648 | 679 | <?php |
| 649 | 680 | /** |
| @@ -730,9 +761,9 @@ | ||
| 730 | 761 | esc_html_e( 'Password', 'mainwp' ); |
| 731 | 762 | ?> |
| 732 | 763 | </label> |
| 733 | 764 | <div class="five wide column"> |
| 734 | - <input type="password" class="settings-field-value-change-handler" name="mainwp_cpanel_account_password" id="mainwp_cpanel_account_password" value="<?php echo esc_attr( $_api_key ); ?>" /> | |
| 765 | + <input type="password" class="settings-field-value-change-handler" name="mainwp_cpanel_account_password" id="mainwp_cpanel_account_password" value="<?php echo esc_attr( MainWP_Credential_Render::value_for_input( ! empty( $_api_key ) ) ); ?>" autocomplete="new-password" /><!-- NOSONAR --> | |
| 735 | 766 | </div> |
| 736 | 767 | </div> |
| 737 | 768 | <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-cpanel-settings"> |
| 738 | 769 | <label class="six wide column middle aligned"> |
| @@ -819,9 +850,9 @@ | ||
| 819 | 850 | esc_html_e( 'API Key', 'mainwp' ); |
| 820 | 851 | ?> |
| 821 | 852 | </label> |
| 822 | 853 | <div class="five wide column"> |
| 823 | - <input type="password" class="settings-field-value-change-handler" name="mainwp_plesk_api_key" id="mainwp_plesk_api_key" value="<?php echo esc_attr( $_api_key ); ?>" /> | |
| 854 | + <input type="password" class="settings-field-value-change-handler" name="mainwp_plesk_api_key" id="mainwp_plesk_api_key" value="<?php echo esc_attr( MainWP_Credential_Render::value_for_input( ! empty( $_api_key ) ) ); ?>" autocomplete="new-password" /> | |
| 824 | 855 | </div> |
| 825 | 856 | </div> |
| 826 | 857 | <?php |
| 827 | 858 | /** |
| @@ -908,9 +939,9 @@ | ||
| 908 | 939 | esc_html_e( 'API Key', 'mainwp' ); |
| 909 | 940 | ?> |
| 910 | 941 | </label> |
| 911 | 942 | <div class="five wide column"> |
| 912 | - <input type="password" name="mainwp_kinsta_api_key" id="mainwp_kinsta_api_key" value="<?php echo esc_attr( $_api_key ); ?>" /> | |
| 943 | + <input type="password" name="mainwp_kinsta_api_key" id="mainwp_kinsta_api_key" value="<?php echo esc_attr( MainWP_Credential_Render::value_for_input( ! empty( $_api_key ) ) ); ?>" autocomplete="new-password" /> | |
| 913 | 944 | </div> |
| 914 | 945 | </div> |
| 915 | 946 | |
| 916 | 947 | <?php |
| @@ -1192,9 +1223,9 @@ | ||
| 1192 | 1223 | <div class="ui grid field"> |
| 1193 | 1224 | <label class="six wide column middle aligned"><?php esc_html_e( 'Password', 'mainwp' ); ?></label> |
| 1194 | 1225 | <div class="ui six wide column" data-tooltip="<?php esc_attr_e( 'Enter the cPanel Account Password.', 'mainwp' ); ?>" data-inverted="" data-position="top left"> |
| 1195 | 1226 | <div class="ui left labeled input"> |
| 1196 | - <input type="password" name="mainwp_cpanel_account_password" id="mainwp_cpanel_account_password" value="<?php echo esc_attr( $cpanel_account_password ); ?>" /> | |
| 1227 | + <input type="password" name="mainwp_cpanel_account_password" id="mainwp_cpanel_account_password" value="<?php echo esc_attr( MainWP_Credential_Render::value_for_input( ! empty( $cpanel_account_password ) ) ); ?>" autocomplete="new-password" /> <?php // phpcs:ignore WordPress.Security.NonceVerification.Missing -- No action performed, just rendering a password field. ?><!-- NOSONAR --> | |
| 1197 | 1228 | </div> |
| 1198 | 1229 | </div> |
| 1199 | 1230 | </div> |
| 1200 | 1231 | <div class="ui grid field"> |
| @@ -1238,9 +1269,10 @@ | ||
| 1238 | 1269 | <div class="ui left labeled input"> |
| 1239 | 1270 | <?php |
| 1240 | 1271 | $plesk_api_key = Api_Backups_Utility::get_instance()->get_child_api_key( $website, 'plesk' ); |
| 1241 | 1272 | ?> |
| 1242 | - <input type="password" name="mainwp_plesk_api_key" id="mainwp_plesk_api_key" value="<?php echo esc_attr( $plesk_api_key ); ?>" /> | |
| 1273 | + <?php // NOSONAR -- no duplicate id, it in 2 different screens. ?> | |
| 1274 | + <input type="password" name="mainwp_plesk_api_key" id="mainwp_plesk_api_key" value="<?php echo esc_attr( MainWP_Credential_Render::value_for_input( ! empty( $plesk_api_key ) ) ); ?>" autocomplete="new-password" /> <?php // phpcs:ignore WordPress.Security.NonceVerification.Missing -- NOSONAR - No action performed, just rendering a password field. ?> | |
| 1243 | 1275 | </div> |
| 1244 | 1276 | </div> |
| 1245 | 1277 | </div> |
| 1246 | 1278 | </div> |
| @@ -1284,9 +1316,9 @@ | ||
| 1284 | 1316 | <div class="ui left labeled input"> |
| 1285 | 1317 | <?php |
| 1286 | 1318 | $kinsta_api_key = Api_Backups_Utility::get_instance()->get_child_api_key( $website, 'kinsta' ); |
| 1287 | 1319 | ?> |
| 1288 | - <input type="password" name="mainwp_kinsta_api_key" id="mainwp_kinsta_api_key" value="<?php echo esc_attr( $kinsta_api_key ); ?>" /> | |
| 1320 | + <input type="password" name="mainwp_kinsta_api_key" id="mainwp_kinsta_api_key" value="<?php echo esc_attr( MainWP_Credential_Render::value_for_input( ! empty( $kinsta_api_key ) ) ); ?>" autocomplete="new-password" /> <?php // phpcs:ignore WordPress.Security.NonceVerification.Missing -- no action performed, just rendering a password field. ?><!-- NOSONAR --> | |
| 1289 | 1321 | </div> |
| 1290 | 1322 | </div> |
| 1291 | 1323 | </div> |
| 1292 | 1324 | </div> |