PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.0.7
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.0.7
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-utility.php

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

763 lines 25.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class Api_Backups_Utility
4 *
5 * @package MainWP\Dashboard
6 * @version 5.0
7 */
8
9 namespace MainWP\Dashboard\Module\ApiBackups;
10
11 use MainWP\Dashboard\MainWP_DB;
12 use MainWP\Dashboard\MainWP_Logger;
13 use MainWP\Dashboard\MainWP_System_Utility;
14
15 // Exit if accessed directly.
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit;
18 }
19
20
21 /**
22 * Class Api_Backups_Utility
23 */
24 class Api_Backups_Utility { //phpcs:ignore -- NOSONAR - multi methods.
25
26 /**
27 * Instance value.
28 *
29 * @var static Default null
30 */
31 public static $instance = null;
32
33 /**
34 * Get Instance
35 *
36 * Creates public static instance.
37 *
38 * @static
39 *
40 * @return Api_Backups_Utility
41 */
42 public static function get_instance() {
43 if ( null === static::$instance ) {
44 static::$instance = new self();
45 }
46 return static::$instance;
47 }
48
49 /**
50 * Method __construct.
51 */
52 public function __construct() {
53 // contructor.
54 }
55
56 /**
57 * Method count_child_sites().
58 */
59 public function count_child_sites() {
60 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_wp_for_current_user() );
61
62 if ( ! empty( $websites ) ) {
63 $sites_count = MainWP_DB::num_rows( $websites );
64 }
65 // Free result set.
66 Api_Backups_Helper::free_result( $websites );
67
68 return $sites_count;
69 }
70
71 /**
72 * Get timestamp.
73 *
74 * @param int $timestamp Holds Timestamp.
75 *
76 * @return float|int Return GMT offset.
77 */
78 public static function get_timestamp( $timestamp = false ) {
79 if ( empty( $timestamp ) ) {
80 $timestamp = time();
81 }
82 $gmtOffset = get_option( 'gmt_offset' );
83
84 return $gmtOffset ? ( $gmtOffset * HOUR_IN_SECONDS ) + $timestamp : $timestamp;
85 }
86
87 /**
88 * Format timestamp.
89 *
90 * @param int $timestamp Holds Timestamp.
91 * @param bool $gmt Whether to set as General mountain time. Default: FALSE.
92 *
93 * @return string Return Timestamp.
94 */
95 public static function format_timestamp( $timestamp, $gmt = false ) {
96 return date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $timestamp, $gmt );
97 }
98
99 /**
100 * Format datestamp.
101 *
102 * @param int $timestamp Holds Timestamp.
103 * @param bool $gmt Whether to set as General mountain time. Default: FALSE.
104 *
105 * @return string Return Timestamp.
106 */
107 public static function format_datestamp( $timestamp, $gmt = false ) {
108 return date_i18n( get_option( 'date_format' ), $timestamp, $gmt );
109 }
110
111 /**
112 * Method map_fields()
113 *
114 * Map Site.
115 *
116 * @param mixed $website Website to map.
117 * @param mixed $keys Keys to map.
118 * @param bool $object_output Output format array|object.
119 *
120 * @return object $outputSite Mapped site.
121 */
122 public static function map_fields( &$website, $keys, $object_output = false ) { //phpcs:ignore -- NOSONAR - complex.
123 $outputSite = array();
124 if ( ! empty( $website ) ) {
125 if ( is_object( $website ) ) {
126 foreach ( $keys as $key ) {
127 if ( property_exists( $website, $key ) ) {
128 $outputSite[ $key ] = $website->$key;
129 }
130 }
131 } elseif ( is_array( $website ) ) {
132 foreach ( $keys as $key ) {
133 $outputSite[ $key ] = $website[ $key ];
134 }
135 }
136 }
137
138 if ( $object_output ) {
139 return (object) $outputSite;
140 } else {
141 return $outputSite;
142 }
143 }
144
145 /**
146 * Method array_sort()
147 *
148 * Sort given array by given flags.
149 *
150 * @param mixed $arr Array to sort.
151 * @param mixed $key Array key.
152 * @param string $sort_flag Flags to sort by. Default = SORT_STRING.
153 */
154 public static function array_sort( &$arr, $key, $sort_flag = SORT_STRING ) {
155 $sorter = array();
156 $ret = array();
157 reset( $arr );
158 foreach ( $arr as $ii => $val ) {
159 $sorter[ $ii ] = $val[ $key ];
160 }
161 asort( $sorter, $sort_flag );
162 foreach ( $sorter as $ii => $val ) {
163 $ret[ $ii ] = $arr[ $ii ];
164 }
165 $arr = $ret;
166 }
167
168 /**
169 * Debugging log info.
170 *
171 * Sets logging for debugging purpose
172 *
173 * @param string $message Log info message.
174 */
175 public static function log_info( $message ) {
176 static::log_debug( $message, 2 );
177 }
178
179 /**
180 * Debugging log.
181 *
182 * Sets logging for debugging purpose.
183 *
184 * @param string $message Log debug message.
185 * @param int $log_color Log color.
186 */
187 public static function log_debug( $message, $log_color = 3 ) {
188 if ( is_array( $message ) || is_object( $message ) ) {
189 $message = print_r( $message, true ); //phpcs:ignore
190 } elseif ( ! is_string( $message ) ) {
191 $message = 'undefined';
192 }
193
194 if ( ! in_array( $log_color, array( 0, 1, 2, 3 ) ) ) {
195 $log_color = 3;
196 }
197 do_action( 'mainwp_log_action', 'API Backups :: ' . $message, MainWP_Logger::API_BACKUPS_LOG_PRIORITY, $log_color );
198 }
199
200 /**
201 *
202 * Method save_lasttime_backup().
203 *
204 * @param int $site_id site id.
205 * @param int $available_backups Available backups.
206 * @param string $backup_api API backups provider.
207 *
208 * @return mixed
209 */
210 public static function save_lasttime_backup( $site_id, $available_backups, $backup_api ) { //phpcs:ignore -- NOSONAR - complex method.
211
212 static::log_debug( 'save backup time :: [available backups=' . ( is_string( $available_backups ) ? $available_backups : 'is not string' ) . ']' );
213
214 if ( empty( $available_backups ) ) {
215 return;
216 }
217
218 if ( is_string( $available_backups ) ) {
219 $available_backups = json_decode( $available_backups );
220 }
221
222 $primaryBackup = MainWP_System_Utility::get_primary_backup();
223
224 $website = Api_Backups_Helper::get_website_by_id( $site_id );
225
226 $backup_method = '';
227 if ( is_array( $website ) && isset( $website['primary_backup_method'] ) ) {
228 if ( '' === $website['primary_backup_method'] || 'global' === $website['primary_backup_method'] ) {
229 $backup_method = $primaryBackup;
230 } else {
231 $backup_method = $website['primary_backup_method'];
232 }
233 }
234
235 if ( 'module-api-backups' !== $backup_method ) {
236 return;
237 }
238
239 $lasttime_backup = 0;
240 if ( 'plesk' === $backup_api ) {
241 $available_backups = is_object( $available_backups ) && ! empty( $available_backups->value ) ? $available_backups->value : array();
242 if ( is_array( $available_backups ) ) {
243 foreach ( $available_backups as $backup ) {
244 if ( is_object( $backup ) && ! empty( $backup->value->createdAt->value ) ) {
245 $backup_time = strtotime( $backup->value->createdAt->value );
246 if ( $backup_time > $lasttime_backup ) {
247 $lasttime_backup = $backup_time;
248 }
249 }
250 }
251 }
252 } elseif ( 'kinsta' === $backup_api ) {
253 $available_backups = is_array( $available_backups ) && ! empty( $available_backups ) ? $available_backups : array();
254 if ( is_array( $available_backups ) ) {
255 foreach ( $available_backups as $backup ) {
256 if ( is_object( $backup ) && ! empty( $backup->created_at ) ) {
257 $milliseconds = $backup->created_at;
258 $epoch = $milliseconds / 1000;
259 $backup_time = strtotime( $epoch );
260 if ( $backup_time > $lasttime_backup ) {
261 $lasttime_backup = $backup_time;
262 }
263 }
264 }
265 }
266 } elseif ( 'cpanel_auto' === $backup_api ) {
267 if ( is_object( $available_backups ) && isset( $available_backups->data ) ) {
268 $available_backups_automatic_list = $available_backups->data;
269 } else {
270 $available_backups_automatic_list = array();
271 }
272
273 if ( is_array( $available_backups_automatic_list ) ) {
274 foreach ( $available_backups_automatic_list as $backup ) {
275 if ( is_object( $backup ) && ! empty( $backup->backupID ) ) {
276 $backup_time = strtotime( $backup->backupID );
277 if ( $backup_time > $lasttime_backup ) {
278 $lasttime_backup = $backup_time;
279 }
280 }
281 }
282 }
283 } elseif ( 'cpanel_manual' === $backup_api ) {
284 $available_backups_manual_list = $available_backups;
285 if ( is_array( $available_backups_manual_list ) ) {
286 foreach ( $available_backups_manual_list as $backup ) {
287 if ( is_object( $backup ) && ! empty( $backup->timestamp ) ) {
288 $backup_time = $backup->timestamp;
289 if ( $backup_time > $lasttime_backup ) {
290 $lasttime_backup = $backup_time;
291 }
292 }
293 }
294 }
295 } elseif ( 'cpanel_wp_toolkit' === $backup_api ) {
296 $available_backups_manual_list = $available_backups;
297 if ( is_array( $available_backups_manual_list ) ) {
298 foreach ( $available_backups_manual_list as $backup ) {
299 if ( is_object( $backup ) && ! empty( $backup->value->createdAt->value ) ) {
300 $backup_time = strtotime( $backup->value->createdAt->value );
301 if ( $backup_time > $lasttime_backup ) {
302 $lasttime_backup = $backup_time;
303 }
304 }
305 }
306 }
307 } elseif ( 'gridpane' === $backup_api ) {
308 if ( isset( $available_backups->automatic ) ) {
309 $available_backups_automatic_list = explode( ',', $available_backups->automatic );
310 } else {
311 $available_backups_automatic_list = array();
312 }
313 if ( isset( $available_backups->manual ) ) {
314 $available_backups_manual_list = explode( ',', $available_backups->manual );
315 } else {
316 $available_backups_manual_list = array();
317 }
318 // to do check date created: $api_response->backups->local.
319
320 if ( is_array( $available_backups_automatic_list ) ) {
321 foreach ( $available_backups_automatic_list as $backup_name ) {
322 $backup_time = substr( $backup_name, 0, 16 ); // get date time string in name.
323 $backup_time = strtotime( $backup_time );
324 if ( $backup_time > $lasttime_backup ) {
325 $lasttime_backup = $backup_time;
326 }
327 }
328 }
329
330 if ( is_array( $available_backups_manual_list ) ) {
331 foreach ( $available_backups_manual_list as $backup_name ) {
332 $backup_time = substr( $backup_name, 0, 16 ); // get date time string in name.
333 $backup_time = strtotime( $backup_time );
334 if ( $backup_time > $lasttime_backup ) {
335 $lasttime_backup = $backup_time;
336 }
337 }
338 }
339 } elseif ( 'cloudways' === $backup_api ) {
340 if ( isset( $available_backups->application_backup_exists ) && true === $available_backups->application_backup_exists ) {
341 $available_backups = $available_backups->backup_dates;
342 } else {
343 $available_backups = array();
344 }
345
346 if ( is_array( $available_backups ) ) {
347 foreach ( $available_backups as $backup ) {
348 $backup_time = strtotime( $backup );
349 if ( $backup_time > $lasttime_backup ) {
350 $lasttime_backup = $backup_time;
351 }
352 }
353 }
354 } elseif ( 'vultr' === $backup_api ) {
355 if ( isset( $available_backups->snapshots ) ) {
356 $available_snapshots_list = $available_backups->snapshots;
357 } else {
358 $available_snapshots_list = array();
359 }
360 if ( isset( $available_backups->backups ) ) {
361 $available_backups_list = $available_backups->backups;
362 } else {
363 $available_backups_list = array();
364 }
365 if ( is_array( $available_snapshots_list ) ) {
366 foreach ( $available_snapshots_list as $backup ) {
367 if ( is_object( $backup ) && ! empty( $backup->date_created ) ) {
368 $backup_time = strtotime( $backup->date_created );
369 if ( $backup_time > $lasttime_backup ) {
370 $lasttime_backup = $backup_time;
371 }
372 }
373 }
374 }
375 if ( is_array( $available_backups_list ) ) {
376 foreach ( $available_backups_list as $backup ) {
377 if ( is_object( $backup ) && ! empty( $backup->date_created ) ) {
378 $backup_time = strtotime( $backup->date_created );
379 if ( $backup_time > $lasttime_backup ) {
380 $lasttime_backup = $backup_time;
381 }
382 }
383 }
384 }
385 } elseif ( 'linode' === $backup_api ) {
386 // Automatic Backups.
387 if ( isset( $available_backups->automatic ) ) {
388 $available_backups_automatic_list = $available_backups->automatic;
389 } else {
390 $available_backups_automatic_list = array();
391 }
392 // Manual Backups.
393 if ( isset( $available_backups->snapshot ) ) {
394 $available_backups_snapshot_list = $available_backups->snapshot;
395 } else {
396 $available_backups_snapshot_list = array();
397 }
398 if ( is_array( $available_backups_automatic_list ) ) {
399 foreach ( $available_backups_automatic_list as $backup ) {
400 if ( is_object( $backup ) && ! empty( $backup->created ) ) {
401 $backup_time = strtotime( $backup->created );
402 if ( $backup_time > $lasttime_backup ) {
403 $lasttime_backup = $backup_time;
404 }
405 }
406 }
407 }
408 if ( is_array( $available_backups_snapshot_list ) ) {
409 foreach ( $available_backups_snapshot_list as $backup ) {
410 if ( is_object( $backup ) && ! empty( $backup->created ) ) {
411 $backup_time = strtotime( $backup->created );
412 if ( $backup_time > $lasttime_backup ) {
413 $lasttime_backup = $backup_time;
414 }
415 }
416 }
417 }
418 } elseif ( 'digitalocean' === $backup_api ) {
419 if ( isset( $available_backups->snapshots ) ) {
420 $available_backups = $available_backups->snapshots;
421 }
422 if ( is_array( $available_backups ) ) {
423 foreach ( $available_backups as $backup ) {
424 if ( is_object( $backup ) && ! empty( $backup->created_at ) ) {
425 $backup_time = strtotime( $backup->created_at );
426 if ( $backup_time > $lasttime_backup ) {
427 $lasttime_backup = $backup_time;
428 }
429 }
430 }
431 }
432 }
433
434 if ( empty( $lasttime_backup ) ) {
435 return;
436 }
437 $lastBackup = MainWP_DB::instance()->get_website_option( $site_id, 'primary_lasttime_backup' );
438
439 if ( ! empty( $lastBackup ) && $lastBackup > $lasttime_backup ) {
440 return;
441 }
442 static::log_debug( 'save backup time :: [site-id=' . $site_id . '] :: [backup time=' . gmdate( 'Y-m-d H:i:s', $lasttime_backup ) . '] :: [api-backups=' . $backup_api . ']' );
443 $site = new \stdClass();
444 $site->id = $site_id;
445 MainWP_DB::instance()->update_website_option( $site, 'primary_lasttime_backup', $lasttime_backup );
446 }
447
448 /**
449 * Show Info Messages
450 *
451 * Check whenther or not to show the MainWP Message.
452 *
453 * @param string $notice_id Notice ID.
454 *
455 * @return bool False if hidden, true to show.
456 */
457 public static function show_mainwp_message( $notice_id ) {
458 $status = get_user_option( 'mainwp_notice_saved_status' );
459 if ( ! is_array( $status ) ) {
460 $status = array();
461 }
462 if ( isset( $status[ $notice_id ] ) ) {
463 return false;
464 }
465 return true;
466 }
467
468
469 /**
470 * Method human_filesize()
471 *
472 * Convert to human readable file size format,
473 * (B|kB|MB|GB|TB|PB|EB|ZB|YB).
474 *
475 * @param mixed $bytes File in bytes.
476 * @param integer $decimals Number of decimals to output.
477 *
478 * @return string Human readable file size.
479 */
480 public static function human_filesize( $bytes, $decimals = 2 ) {
481 $size = array( 'B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' );
482 $factor = floor( ( strlen( $bytes ) - 1 ) / 3 );
483
484 return sprintf( "%.{$decimals}f", $bytes / pow( 1024, $factor ) ) . @$size[ $factor ]; //phpcs:ignore
485 }
486
487
488 /**
489 * Get Color Code
490 *
491 * Returns CSS class to use correct color for the element.
492 *
493 * @param int $value value.
494 *
495 * @return string CSS class.
496 */
497 public static function color_code( $value ) {
498 $color = '';
499 if ( 5 < $value ) {
500 $color = 'red';
501 } elseif ( 0 < $value && 5 >= $value ) {
502 $color = 'yellow';
503 } else {
504 $color = 'green';
505 }
506 return $color;
507 }
508
509 /**
510 * Method update_option()
511 *
512 * Update option.
513 *
514 * @param mixed $option_name Option name.
515 * @param mixed $option_value Option value.
516 *
517 * @return (boolean) False if value was not updated and true if value was updated.
518 */
519 public static function update_option( $option_name, $option_value ) {
520 $success = add_option( $option_name, $option_value, '', 'no' );
521
522 if ( ! $success ) {
523 $success = update_option( $option_name, $option_value );
524 }
525
526 return $success;
527 }
528
529
530 /**
531 * Method encrypt_api_keys
532 *
533 * @param string $data data.
534 * @param int $siteid site id.
535 * @param string $file_key file key.
536 * @param string $service_name service name.
537 *
538 * Encrypt data.
539 */
540 public function encrypt_api_keys( $data, $siteid = false, $file_key = false, $service_name = '' ) {
541 if ( is_string( $data ) ) {
542
543 $prefix = 'apibackups_';
544
545 if ( ! empty( $siteid ) ) {
546 $prefix = $prefix . intval( $siteid ) . '_';
547 }
548
549 if ( ! empty( $service_name ) && is_string( $service_name ) ) {
550 $prefix = $prefix . $service_name . '_';
551 }
552
553 $result = apply_filters( 'mainwp_encrypt_key_value', false, $data, $prefix, $file_key );
554
555 if ( is_array( $result ) && ! empty( $result['encrypted_val'] ) ) {
556 return $result;
557 }
558 }
559 return $data;
560 }
561
562 /**
563 * Method decrypt_api_keys
564 *
565 * @param mixed $encrypted_data encrypted data.
566 * @param string $def_val default data.
567 */
568 public function decrypt_api_keys( $encrypted_data, $def_val = '' ) {
569 if ( ! empty( $encrypted_data ) && is_array( $encrypted_data ) && ! empty( $encrypted_data['encrypted_val'] ) ) { // old format.
570 $result = apply_filters( 'mainwp_decrypt_key_value', false, $encrypted_data, $def_val );
571 if ( ! empty( $result ) && is_string( $result ) ) {
572 return $result;
573 }
574 }
575 return $def_val;
576 }
577
578 /**
579 * Method get_compatible_site_api_key
580 *
581 * Encrypt data.
582 *
583 * @param string $name name data.
584 * @param string $def_val default data.
585 */
586 public function get_api_key( $name, $def_val = '' ) {
587
588 $names = array(
589 'vultr',
590 'gridpane',
591 'linode',
592 'digitalocean',
593 'cloudways',
594 'cpanel',
595 'plesk',
596 'kinsta',
597 );
598
599 if ( ! in_array( $name, $names ) ) {
600 return $def_val;
601 }
602
603 $encrypted = get_option( 'mainwp_api_backups_' . $name . '_api_key' );
604 if ( is_array( $encrypted ) && ! empty( $encrypted['file_key'] ) ) {
605 $key = $this->decrypt_api_keys( $encrypted );
606 if ( ! empty( $key ) && is_string( $key ) ) {
607 return $key;
608 }
609 }
610 return $def_val;
611 }
612
613 /**
614 * Method update_compatible_site_api_key
615 *
616 * Encrypt data.
617 *
618 * @param string $name name data.
619 * @param string $value value data.
620 */
621 public function update_api_key( $name, $value ) {
622
623 $names = array(
624 'vultr',
625 'gridpane',
626 'linode',
627 'digitalocean',
628 'cloudways',
629 'cpanel',
630 'plesk',
631 'kinsta',
632 );
633
634 if ( ! in_array( $name, $names ) ) {
635 return false;
636 }
637
638 $opt_name = 'mainwp_api_backups_' . $name . '_api_key';
639 $current = get_option( $opt_name );
640 $key_file = '';
641
642 if ( is_array( $current ) && ! empty( $current['file_key'] ) ) {
643 $key_file = $current['file_key'];
644 }
645
646 if ( empty( $value ) ) {
647 delete_option( $opt_name );
648 if ( ! empty( $key_file ) ) {
649 do_action( 'mainwp_delete_key_file', $key_file );
650 }
651 return true;
652 }
653
654 $encrypted = $this->encrypt_api_keys( $value, false, $key_file, $name );
655 if ( is_array( $encrypted ) && ! empty( $encrypted['file_key'] ) ) {
656 return update_option( $opt_name, $encrypted );
657 }
658
659 return false;
660 }
661
662 /**
663 * Method get child site key.
664 *
665 * Encrypt data.
666 *
667 * @param int $website_id name data.
668 * @param string $name name data.
669 * @param string $def_val default data.
670 */
671 public function get_child_api_key( $website_id, $name, $def_val = '' ) {
672
673 $names = array(
674 'vultr',
675 'gridpane',
676 'linode',
677 'digitalocean',
678 'cloudways',
679 'cpanel',
680 'plesk',
681 'kinsta',
682 );
683
684 if ( ! in_array( $name, $names ) ) {
685 return $def_val;
686 }
687
688 $opt_name = 'mainwp_api_backups_' . $name . '_api_key';
689 $opt_encoded = Api_Backups_Helper::get_website_options( $website_id, array( $opt_name ) );
690 if ( array_key_exists( $opt_name, $opt_encoded ) ) {
691 $encrypted = json_decode( $opt_encoded[ $opt_name ], true );
692 } else {
693 $encrypted = '';
694 }
695
696 if ( is_array( $encrypted ) && ! empty( $encrypted['file_key'] ) ) {
697 $key = $this->decrypt_api_keys( $encrypted );
698
699 if ( ! empty( $key ) && is_string( $key ) ) {
700 return $key;
701 }
702 }
703 return $def_val;
704 }
705
706 /**
707 * Method update child api key.
708 *
709 * Encrypt data.
710 *
711 * @param int $website_id name data.
712 * @param string $name name data.
713 * @param string $value value data.
714 */
715 public function update_child_api_key( $website_id, $name, $value ) {
716
717 $names = array(
718 'vultr',
719 'gridpane',
720 'linode',
721 'digitalocean',
722 'cloudways',
723 'cpanel',
724 'plesk',
725 'kinsta',
726 );
727
728 if ( ! in_array( $name, $names ) ) {
729 return false;
730 }
731
732 $opt_name = 'mainwp_api_backups_' . $name . '_api_key';
733 $opt_encoded = Api_Backups_Helper::get_website_options( $website_id, array( $opt_name ) );
734 if ( array_key_exists( $opt_name, $opt_encoded ) ) {
735 $current = json_decode( $opt_encoded[ $opt_name ], true );
736 } else {
737 $current = '';
738 }
739 $key_file = '';
740 if ( is_array( $current ) && ! empty( $current['file_key'] ) ) {
741 $key_file = $current['file_key'];
742 }
743
744 // If post $value is empty, delete option.
745 if ( empty( $value ) ) {
746 // Delete the site serviceapi key.
747 Api_Backups_Helper::update_website_option( $website_id, $opt_name, '' );
748 if ( ! empty( $key_file ) ) {
749 do_action( 'mainwp_delete_key_file', $key_file );
750 }
751 return true;
752 }
753
754 $encrypted = wp_json_encode( $this->encrypt_api_keys( $value, $website_id, $key_file, $name ) );
755
756 if ( ! empty( $encrypted ) ) {
757 return Api_Backups_Helper::update_website_option( $website_id, $opt_name, $encrypted );
758 }
759
760 return false;
761 }
762 }
763