← All changes
|
modules/api-backups/classes/class-api-backups-utility.php
+33
-4
6.0.11
→
6.2.2
View file →
| @@ -7,8 +7,9 @@ | ||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | namespace MainWP\Dashboard\Module\ApiBackups; |
| 10 | 10 | |
| 11 | +use MainWP\Dashboard\MainWP_Credential_Render; | |
| 11 | 12 | use MainWP\Dashboard\MainWP_DB; |
| 12 | 13 | use MainWP\Dashboard\MainWP_Logger; |
| 13 | 14 | use MainWP\Dashboard\MainWP_System_Utility; |
| 14 | 15 | |
| @@ -581,10 +582,11 @@ | ||
| 581 | 582 | * Encrypt data. |
| 582 | 583 | * |
| 583 | 584 | * @param string $name name data. |
| 584 | 585 | * @param string $def_val default data. |
| 586 | + * @param string $opt_name Option name. | |
| 585 | 587 | */ |
| 586 | - public function get_api_key( $name, $def_val = '' ) { | |
| 588 | + public function get_api_key( $name, $def_val = '', $opt_name = '' ) { | |
| 587 | 589 | |
| 588 | 590 | $names = array( |
| 589 | 591 | 'vultr', |
| 590 | 592 | 'gridpane', |
| @@ -599,9 +601,14 @@ | ||
| 599 | 601 | if ( ! in_array( $name, $names ) ) { |
| 600 | 602 | return $def_val; |
| 601 | 603 | } |
| 602 | 604 | |
| 603 | - $encrypted = get_option( 'mainwp_api_backups_' . $name . '_api_key' ); | |
| 605 | + if ( ! empty( $opt_name ) ) { | |
| 606 | + $encrypted = get_option( 'mainwp_api_backups_' . $name . '_' . (string) $opt_name ); | |
| 607 | + } else { | |
| 608 | + $encrypted = get_option( 'mainwp_api_backups_' . $name . '_api_key' ); | |
| 609 | + } | |
| 610 | + | |
| 604 | 611 | if ( is_array( $encrypted ) && ! empty( $encrypted['file_key'] ) ) { |
| 605 | 612 | $key = $this->decrypt_api_keys( $encrypted ); |
| 606 | 613 | if ( ! empty( $key ) && is_string( $key ) ) { |
| 607 | 614 | return $key; |
| @@ -616,10 +623,11 @@ | ||
| 616 | 623 | * Encrypt data. |
| 617 | 624 | * |
| 618 | 625 | * @param string $name name data. |
| 619 | 626 | * @param string $value value data. |
| 627 | + * @param string $opt_name Option name. | |
| 620 | 628 | */ |
| 621 | - public function update_api_key( $name, $value ) { | |
| 629 | + public function update_api_key( $name, $value, $opt_name = '' ) { | |
| 622 | 630 | |
| 623 | 631 | $names = array( |
| 624 | 632 | 'vultr', |
| 625 | 633 | 'gridpane', |
| @@ -634,9 +642,22 @@ | ||
| 634 | 642 | if ( ! in_array( $name, $names ) ) { |
| 635 | 643 | return false; |
| 636 | 644 | } |
| 637 | 645 | |
| 638 | - $opt_name = 'mainwp_api_backups_' . $name . '_api_key'; | |
| 646 | + // MWP-1543: settings forms render the sentinel ('••••••••') in the | |
| 647 | + // password input when a value is already stored. A submission that | |
| 648 | + // returns the sentinel unchanged means "leave existing value alone"; | |
| 649 | + // short-circuit before delete_option / encrypt so no overwrite happens. | |
| 650 | + if ( MainWP_Credential_Render::is_sentinel( $value ) ) { | |
| 651 | + return true; | |
| 652 | + } | |
| 653 | + | |
| 654 | + if ( ! empty( $opt_name ) ) { | |
| 655 | + $opt_name = 'mainwp_api_backups_' . $name . '_' . (string) $opt_name; | |
| 656 | + } else { | |
| 657 | + $opt_name = 'mainwp_api_backups_' . $name . '_api_key'; | |
| 658 | + } | |
| 659 | + | |
| 639 | 660 | $current = get_option( $opt_name ); |
| 640 | 661 | $key_file = ''; |
| 641 | 662 | |
| 642 | 663 | if ( is_array( $current ) && ! empty( $current['file_key'] ) ) { |
| @@ -726,8 +747,16 @@ | ||
| 726 | 747 | ); |
| 727 | 748 | |
| 728 | 749 | if ( ! in_array( $name, $names ) ) { |
| 729 | 750 | return false; |
| 751 | + } | |
| 752 | + | |
| 753 | + // MWP-1543: same sentinel short-circuit as update_api_key(); the | |
| 754 | + // per-site Edit Site form renders the sentinel placeholder when a | |
| 755 | + // value already exists, and an unchanged submission must not | |
| 756 | + // overwrite the encrypted option with the sentinel string. | |
| 757 | + if ( MainWP_Credential_Render::is_sentinel( $value ) ) { | |
| 758 | + return true; | |
| 730 | 759 | } |
| 731 | 760 | |
| 732 | 761 | $opt_name = 'mainwp_api_backups_' . $name . '_api_key'; |
| 733 | 762 | $opt_encoded = Api_Backups_Helper::get_website_options( $website_id, array( $opt_name ) ); |