is_plugin_installed = true; if ( version_compare( phpversion(), '5.3', '>=' ) ) { add_filter( 'mainwp_site_sync_others_data', array( $this, 'sync_others_data' ), 10, 2 ); } } } public function init() { if ( version_compare( phpversion(), '5.3', '<' ) ) { return; } if ( ! $this->is_plugin_installed ) { return; } add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) ); if ( 'hide' === get_option( 'mainwp_backupwordpress_hide_plugin' ) ) { add_filter( 'all_plugins', array( $this, 'all_plugins' ) ); add_action( 'admin_menu', array( $this, 'remove_menu' ) ); add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) ); add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) ); } } public function hide_update_notice( $slugs ) { $slugs[] = 'backupwordpress/backupwordpress.php'; return $slugs; } public function remove_update_nag( $value ) { if ( isset( $_POST['mainwpsignature'] ) ) { return $value; } if ( ! MainWP_Helper::is_screen_with_update() ) { return $value; } if ( isset( $value->response['backupwordpress/backupwordpress.php'] ) ) { unset( $value->response['backupwordpress/backupwordpress.php'] ); } return $value; } public function action() { $information = array(); if ( ! self::is_activated() ) { $information['error'] = 'NO_BACKUPWORDPRESS'; mainwp_child_helper()->write( $information ); } if ( isset( $_POST['mwp_action'] ) ) { switch ( $_POST['mwp_action'] ) { case 'set_showhide': $information = $this->set_showhide(); break; case 'delete_schedule': $information = $this->delete_schedule(); break; case 'cancel_schedule': $information = $this->hmbkp_request_cancel_backup(); break; case 'get_backup_status': $information = $this->get_backup_status(); break; case 'reload_backupslist': $information = $this->reload_backups(); break; case 'delete_backup': $information = $this->hmbkp_request_delete_backup(); break; case 'run_schedule': $information = $this->run_schedule(); break; case 'save_all_schedules': $information = $this->save_all_schedules(); break; case 'update_schedule': $information = $this->update_schedule(); break; case 'get_excluded': $information = $this->get_excluded(); break; case 'directory_browse': $information = $this->directory_browse(); break; case 'exclude_add_rule': $information = $this->hmbkp_add_exclude_rule(); break; case 'exclude_remove_rule': $information = $this->hmbkp_remove_exclude_rule(); break; case 'general_exclude_add_rule': $information = $this->general_exclude_add_rule(); break; } } mainwp_child_helper()->write( $information ); } public function check_schedule() { $schedule_id = ( isset( $_POST['schedule_id'] ) && ! empty( $_POST['schedule_id'] ) ) ? $_POST['schedule_id'] : ''; if ( empty( $schedule_id ) ) { $information = array( 'error' => 'Empty schedule id' ); mainwp_child_helper()->write( $information ); } else { $schedule_id = sanitize_text_field( rawurldecode( $schedule_id ) ); HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules(); if ( ! HM\BackUpWordPress\Schedules::get_instance()->get_schedule( $schedule_id ) ) { $information = array( 'result' => 'NOTFOUND' ); mainwp_child_helper()->write( $information ); } } return $schedule_id; } public function sync_others_data( $information, $data = array() ) { if ( isset( $data['syncBackUpWordPress'] ) && $data['syncBackUpWordPress'] ) { try { $information['syncBackUpWordPress'] = $this->get_sync_data(); } catch ( \Exception $e ) { // ok! } } return $information; } private function get_sync_data() { MainWP_Helper::check_classes_exists( 'HM\BackUpWordPress\Schedules' ); MainWP_Helper::check_methods( 'HM\BackUpWordPress\Schedules', array( 'get_instance', 'refresh_schedules', 'get_schedules' ) ); HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules(); $schedules = HM\BackUpWordPress\Schedules::get_instance()->get_schedules(); $backups_time = array(); if ( is_array( $schedules ) && count( $schedules ) ) { $check = current( $schedules ); MainWP_Helper::check_methods( $check, array( 'get_backups' ) ); foreach ( $schedules as $sche ) { $existing_backup = $sche->get_backups(); if ( ! empty( $existing_backup ) ) { $backups_time = array_merge( $backups_time, array_keys( $existing_backup ) ); } } } $lasttime_backup = 0; if ( ! empty( $backups_time ) ) { $lasttime_backup = max( $backups_time ); } $return = array( 'lasttime_backup' => $lasttime_backup ); return $return; } public function do_site_stats() { if ( has_action( 'mainwp_child_reports_log' ) ) { do_action( 'mainwp_child_reports_log', 'backupwordpress' ); } else { $this->do_reports_log( 'backupwordpress' ); } } public function do_reports_log( $ext = '' ) { if ( 'backupwordpress' !== $ext ) { return; } if ( ! $this->is_plugin_installed ) { return; } try { MainWP_Helper::check_classes_exists( 'HM\BackUpWordPress\Schedules' ); MainWP_Helper::check_methods( 'HM\BackUpWordPress\Schedules', array( 'get_instance', 'refresh_schedules', 'get_schedules' ) ); // Refresh the schedules from the database to make sure we have the latest changes. HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules(); $schedules = HM\BackUpWordPress\Schedules::get_instance()->get_schedules(); if ( is_array( $schedules ) && count( $schedules ) > 0 ) { $check = current( $schedules ); MainWP_Helper::check_methods( $check, array( 'get_backups', 'get_type' ) ); foreach ( $schedules as $schedule ) { foreach ( $schedule->get_backups() as $file ) { $backup_type = $schedule->get_type(); $message = 'BackupWordpres backup ' . $backup_type . ' finished'; $destination = 'N/A'; if ( file_exists( $file ) ) { $date = filemtime( $file ); if ( ! empty( $date ) ) { do_action( 'mainwp_reports_backupwordpress_backup', $destination, $message, 'finished', $backup_type, $date ); MainWP_Helper::update_lasttime_backup( 'backupwordpress', $date ); // to support backup before update feature. } } } } } } catch ( \Exception $e ) { // ok! } } public function set_showhide() { $hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : ''; MainWP_Helper::update_option( 'mainwp_backupwordpress_hide_plugin', $hide ); $information['result'] = 'SUCCESS'; return $information; } public function delete_schedule() { $schedule_id = $this->check_schedule(); $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) ); if ( $schedule ) { $schedule->cancel( true ); $information['result'] = 'SUCCESS'; } else { $information['result'] = 'NOTFOUND'; } return $information; } public function hmbkp_request_cancel_backup() { $schedule_id = $this->check_schedule(); $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) ); // Delete the running backup. if ( method_exists( $schedule, 'get_running_backup_filename' ) ) { if ( $schedule->get_running_backup_filename() && file_exists( trailingslashit( hmbkp_path() ) . $schedule->get_running_backup_filename() ) ) { unlink( trailingslashit( hmbkp_path() ) . $schedule->get_running_backup_filename() ); } if ( $schedule->get_schedule_running_path() && file_exists( $schedule->get_schedule_running_path() ) ) { unlink( $schedule->get_schedule_running_path() ); } } else { $status = $schedule->get_status(); // Delete the running backup. if ( $status->get_backup_filename() && file_exists( trailingslashit( HM\BackUpWordPress\Path::get_path() ) . $status->get_backup_filename() ) ) { unlink( trailingslashit( HM\BackUpWordPress\Path::get_path() ) . $status->get_backup_filename() ); } if ( file_exists( $status->get_status_filepath() ) ) { unlink( $status->get_status_filepath() ); } } HM\BackUpWordPress\Path::get_instance()->cleanup(); if ( null === $status ) { $information['scheduleStatus'] = $schedule->get_status(); } else { $information['scheduleStatus'] = $status->get_status(); } $information['result'] = 'SUCCESS'; return $information; } public function get_backup_status() { $schedule_id = $this->check_schedule(); $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) ); if ( method_exists( $schedule, 'get_running_backup_filename' ) ) { $information['scheduleStatus'] = $schedule->get_status(); } else { $status = $schedule->get_status(); $information['scheduleStatus'] = $status->get_status(); } $information['result'] = 'SUCCESS'; return $information; } public function run_schedule() { $schedule_id = $this->check_schedule(); if ( function_exists( 'hmbkp_run_schedule_async' ) ) { hmbkp_run_schedule_async( $schedule_id ); } elseif ( function_exists( '\HM\BackUpWordPress\run_schedule_async' ) ) { HM\BackUpWordPress\Path::get_instance()->cleanup(); // Fixes an issue on servers which only allow a single session per client. session_write_close(); $task = new \HM\Backdrop\Task( '\HM\BackUpWordPress\run_schedule_async', $schedule_id ); $task->schedule(); } else { return array( 'error' => __( 'Error while trying to trigger the schedule', 'mainwp-child' ) ); } return array( 'result' => 'SUCCESS' ); } public function reload_backups() { $scheduleIds = isset( $_POST['schedule_ids'] ) ? $_POST['schedule_ids'] : array(); HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules(); $all_schedules_ids = array(); $schedules = HM\BackUpWordPress\Schedules::get_instance()->get_schedules(); foreach ( $schedules as $sch ) { $all_schedules_ids[] = $sch->get_id(); } if ( empty( $all_schedules_ids ) ) { return array( 'error' => 'Schedules could not be found.' ); } foreach ( $all_schedules_ids as $schedule_id ) { if ( ! HM\BackUpWordPress\Schedules::get_instance()->get_schedule( $schedule_id ) ) { continue; } $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) ); $started_ago = method_exists( $schedule, 'get_schedule_running_start_time' ) ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time(); $out = array( 'b' => $this->get_backupslist_html( $schedule ), 'count' => count( $schedule->get_backups() ), 'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ), 'started_ago' => human_time_diff( $started_ago ), ); if ( method_exists( $schedule, 'get_running_backup_filename' ) ) { $out['scheduleStatus'] = $schedule->get_status(); } else { $status = $schedule->get_status(); $out['scheduleStatus'] = $status->get_status(); } $information['backups'][ $schedule_id ] = $out; } $send_back_schedules = array(); $schedules = HM\BackUpWordPress\Schedules::get_instance()->get_schedules(); foreach ( $schedules as $schedule ) { $sch_id = $schedule->get_id(); if ( ! in_array( $sch_id, $scheduleIds ) ) { $current_option = get_option( 'hmbkp_schedule_' . $sch_id ); if ( is_array( $current_option ) ) { unset( $current_option['excludes'] ); $started_ago = method_exists( $schedule, 'get_schedule_running_start_time' ) ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time(); $send_back_schedules[ $sch_id ] = array( 'options' => $current_option, 'b' => $this->get_backupslist_html( $schedule ), 'count' => count( $schedule->get_backups() ), 'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ), 'scheduleStatus' => $schedule->get_status(), 'started_ago' => human_time_diff( $started_ago ), ); if ( method_exists( $schedule, 'get_running_backup_filename' ) ) { $send_back_schedules['scheduleStatus'] = $schedule->get_status(); } else { $status = $schedule->get_status(); $send_back_schedules['scheduleStatus'] = $status->get_status(); } } } } if ( function_exists( 'HM\BackUpWordPress\Backup::get_home_path' ) ) { $backups_path = str_replace( HM\BackUpWordPress\Backup::get_home_path(), '', hmbkp_path() ); } else { $backups_path = str_replace( HM\BackUpWordPress\Path::get_home_path(), '', HM\BackUpWordPress\Path::get_path() ); } $information['backups_path'] = $backups_path; $information['send_back_schedules'] = $send_back_schedules; $information['result'] = 'SUCCESS'; return $information; } public function hmbkp_request_delete_backup() { if ( ! isset( $_POST['hmbkp_backuparchive'] ) || empty( $_POST['hmbkp_backuparchive'] ) ) { return array( 'error' => __( 'Invalid data. Please check and try again.', 'mainwp-child' ) ); } $schedule_id = $this->check_schedule(); $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) ); $deleted = $schedule->delete_backup( base64_decode( rawurldecode( $_POST['hmbkp_backuparchive'] ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons. if ( is_wp_error( $deleted ) ) { return array( 'error' => $deleted->get_error_message() ); } $ret = array( 'result' => 'SUCCESS', 'b' => $this->get_backupslist_html( $schedule ), 'count' => count( $schedule->get_backups() ), 'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ), ); if ( method_exists( $schedule, 'get_running_backup_filename' ) ) { $ret['scheduleStatus'] = $schedule->get_status(); } else { $status = $schedule->get_status(); $ret['scheduleStatus'] = $status->get_status(); } return $ret; } public function get_backupslist_html( $schedule ) { ob_start(); ?> get_backups() ) { $schedule->delete_old_backups(); foreach ( $schedule->get_backups() as $file ) { if ( ! file_exists( $file ) ) { continue; } $this->hmbkp_get_backup_row( $file, $schedule ); } } else { ?>
get_type() ) || $schedule->is_site_size_cached() ) { return sprintf( '(%s)', esc_attr( $schedule->get_formatted_site_size() ) ); } } else { $site_size = new HM\BackUpWordPress\Site_Size( $schedule->get_type(), $schedule->get_excludes() ); if ( ( 'database' === $schedule->get_type() ) || $site_size->is_site_size_cached() ) { return sprintf( '(%s)', esc_attr( $site_size->get_formatted_site_size() ) ); } } return sprintf( '(' . __( 'calculating the size of your backup…', 'mainwp-child' ) . ')' ); } public function hmbkp_get_backup_row( $file, HM\BackUpWordPress\Scheduled_Backup $schedule ) { $encoded_file = rawurlencode( base64_encode( $file ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons. $offset = get_option( 'gmt_offset' ) * 3600; ?> | | check_schedule(); $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( rawurldecode( $schedule_id ) ) ); $new_version = true; if ( method_exists( $schedule, 'get_running_backup_filename' ) ) { $new_version = false; $user_excludes = array_diff( $schedule->get_excludes(), $schedule->backup->default_excludes() ); $root_dir = $schedule->backup->get_root(); $is_size_calculated = $schedule->is_site_size_being_calculated(); } else { $excludes = $schedule->get_excludes(); $user_excludes = $excludes->get_user_excludes(); $root_dir = HM\BackUpWordPress\Path::get_root(); $is_size_calculated = HM\BackUpWordPress\Site_Size::is_site_size_being_calculated(); } ob_start(); ?>

VCS folders and other backup plugin folders.', 'mainwp-child' ); ?>

$exclude ) : ?>
isFile() ) { ?>
isDir() ) { ?>
get_default_excludes() ) ) || ( HM\BackUpWordPress\Path::get_path() === trailingslashit( HM\BackUpWordPress\Path::get_root() ) . untrailingslashit( $exclude ) ); } else { $is_default_rule = ( in_array( $exclude, $schedule->backup->default_excludes() ) ) || ( hmbkp_path() === untrailingslashit( $exclude ) ); } if ( $is_default_rule ) : ?>

get_excludes_for_regex() ); if ( function_exists( 'HM\BackUpWordPress\list_directory_by_total_filesize' ) ) { $files = HM\BackUpWordPress\list_directory_by_total_filesize( $directory, $excludes ); } } else { $files = $schedule->list_directory_by_total_filesize( $directory ); $exclude_string = $schedule->backup->exclude_string( 'regex' ); } if ( $files ) { ?> $file ) { $is_excluded = false; $is_unreadable = false; // Check if the file is excluded. if ( $new_version ) { if ( $exclude_string && preg_match( '(' . $exclude_string . ')', str_ireplace( trailingslashit( $root_dir ), '', wp_normalize_path( $file->getPathname() ) ) ) ) { $is_excluded = true; } } else { if ( $exclude_string && preg_match( '(' . $exclude_string . ')', str_ireplace( trailingslashit( $root_dir ), '', HM\BackUpWordPress\Backup::conform_dir( $file->getPathname() ) ) ) ) { $is_excluded = true; } } // Skip unreadable files. if ( ! realpath( $file->getPathname() ) || ! $file->isReadable() ) { $is_unreadable = true; } ?>
/ / filesize( $root ); } else { $size = $schedule->filesize( $root, true ); } if ( false !== $size ) { $size = size_format( $size ); if ( ! $size ) { $size = '0 B'; } ?>
isFile() ) { ?>
isDir() ) { ?>
getBasename() ); ?> isFile() ) { ?> getBasename() ); ?> isDir() ) { ?> getBasename() ); ?> getBasename() ); ?> isFile() ) { ?> getBasename() ); ?> isDir() ) { ?> getBasename() ); ?> isDir() && $is_size_calculated ) : ?> filesize( $file ); } else { $size = $schedule->filesize( $file ); } if ( false !== $size ) { $size = size_format( $size ); if ( ! $size ) { $size = '0 B'; } ?> isDir() ) { ?> -- getPerms() ), - 4 ) ); ?> isLink() ) : ?> isDir() ) : esc_html_e( 'Folder', 'mainwp-child' ); else : esc_html_e( 'File', 'mainwp-child' ); endif; ?> getPathname(); // Excluded directories need to be trailingslashed. if ( $file->isDir() ) { $exclude_path = trailingslashit( wp_normalize_path( $file->getPathname() ) ); } ?>

get_excluded( $browse_dir ); $out['e'] = $return['e']; $out['current_browse_dir'] = $browse_dir; return $out; } public function hmbkp_add_exclude_rule() { if ( ! isset( $_POST['exclude_pathname'] ) || empty( $_POST['exclude_pathname'] ) ) { return array( 'error' => __( 'Empty exclude directory path.', 'mainwp-child' ) ); } $schedule_id = $this->check_schedule(); $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $schedule_id ) ); $exclude_rule = rawurldecode( $_POST['exclude_pathname'] ); $schedule->set_excludes( $exclude_rule, true ); $schedule->save(); $current_path = rawurldecode( $_POST['browse_dir'] ); if ( empty( $current_path ) ) { $current_path = null; } $return = $this->get_excluded( $current_path ); $out['e'] = $return['e']; $out['current_browse_dir'] = $_POST['browse_dir']; return $out; } public function hmbkp_remove_exclude_rule() { if ( ! isset( $_POST['remove_rule'] ) || empty( $_POST['remove_rule'] ) ) { return array( 'error' => __( 'Empty exclude directory path.', 'mainwp-child' ) ); } $schedule_id = $this->check_schedule(); $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $schedule_id ) ); $excludes = $schedule->get_excludes(); $exclude_rule_to_remove = stripslashes( sanitize_text_field( $_POST['remove_rule'] ) ); if ( method_exists( $excludes, 'get_user_excludes' ) ) { $schedule->set_excludes( array_diff( $excludes->get_user_excludes(), (array) $exclude_rule_to_remove ) ); } else { $schedule->set_excludes( array_diff( $excludes, $exclude_rule_to_remove ) ); } $schedule->save(); $current_path = rawurldecode( $_POST['browse_dir'] ); if ( empty( $current_path ) ) { $current_path = null; } $return = $this->get_excluded( $current_path ); $out['e'] = $return['e']; $out['current_browse_dir'] = $_POST['browse_dir']; return $out; } public function general_exclude_add_rule() { $sch_id = $this->check_schedule(); $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $sch_id ) ); $exclude_paths = rawurldecode( $_POST['exclude_paths'] ); $exclude_paths = explode( "\n", $exclude_paths ); if ( is_array( $exclude_paths ) && count( $exclude_paths ) > 0 ) { foreach ( $exclude_paths as $excl_rule ) { $excl_rule = trim( $excl_rule ); $excl_rule = trim( $excl_rule, '/' ); if ( empty( $excl_rule ) ) { continue; } $exclude_rule = ABSPATH . $excl_rule; $path = realpath( $exclude_rule ); if ( false !== $path ) { $schedule->set_excludes( $exclude_rule, true ); $schedule->save(); } } } $un_exclude_paths = rawurldecode( $_POST['un_exclude_paths'] ); $un_exclude_paths = explode( "\n", $un_exclude_paths ); if ( is_array( $un_exclude_paths ) && count( get_user_excludes ) > 0 ) { foreach ( $un_exclude_paths as $exclude_rule_to_remove ) { $exclude_rule_to_remove = trim( $exclude_rule_to_remove ); $exclude_rule_to_remove = trim( $exclude_rule_to_remove, '/' ); if ( empty( $exclude_rule_to_remove ) ) { continue; } $excludes = $schedule->get_excludes(); if ( method_exists( $excludes, 'get_user_excludes' ) ) { $schedule->set_excludes( array_diff( $excludes->get_user_excludes(), (array) $exclude_rule_to_remove ) ); } else { $schedule->set_excludes( array_diff( $excludes, $exclude_rule_to_remove ) ); } $schedule->save(); } } return array( 'result' => 'SUCCESS' ); } public function update_schedule() { $sch_id = isset( $_POST['schedule_id'] ) ? $_POST['schedule_id'] : 0; $sch_id = sanitize_text_field( rawurldecode( $sch_id ) ); $options = isset( $_POST['options'] ) ? maybe_unserialize( base64_decode( $_POST['options'] ) ) : false; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons. if ( ! is_array( $options ) || empty( $options ) || empty( $sch_id ) ) { return array( 'error' => __( 'Schedule data', 'mainwp-child' ) ); } $filter_opts = array( 'type', 'email', 'reoccurrence', 'max_backups', 'schedule_start_time', ); $out = array(); if ( is_array( $options ) ) { $old_options = get_option( 'hmbkp_schedule_' . $sch_id ); if ( is_array( $old_options ) ) { foreach ( $old_options as $key => $val ) { if ( ! in_array( $key, $filter_opts ) ) { $options[ $key ] = $old_options[ $key ]; } } } update_option( 'hmbkp_schedule_' . $sch_id, $options ); delete_transient( 'hmbkp_schedules' ); $out['result'] = 'SUCCESS'; } else { $out['result'] = 'NOTCHANGE'; } $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $sch_id ) ); if ( ! empty( $options['reoccurrence'] ) && ! empty( $options['schedule_start_time'] ) ) { // Calculate the start time depending on the recurrence. $start_time = $options['schedule_start_time']; if ( $start_time ) { $schedule->set_schedule_start_time( $start_time ); } } if ( ! empty( $options['reoccurrence'] ) ) { $schedule->set_reoccurrence( $options['reoccurrence'] ); } $out['next_occurrence'] = $schedule->get_next_occurrence( false ); return $out; } public function save_all_schedules() { $schedules = isset( $_POST['all_schedules'] ) ? maybe_unserialize( base64_decode( $_POST['all_schedules'] ) ) : false; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for benign reasons. if ( ! is_array( $schedules ) || empty( $schedules ) ) { return array( 'error' => __( 'Schedule data', 'mainwp-child' ) ); } $out = array(); foreach ( $schedules as $sch_id => $sch ) { if ( empty( $sch_id ) || ! isset( $sch['options'] ) || ! is_array( $sch['options'] ) ) { continue; } $options = $sch['options']; $filter_opts = array( 'type', 'email', 'reoccurrence', 'max_backups', 'schedule_start_time', ); if ( is_array( $options ) ) { $old_options = get_option( 'hmbkp_schedule_' . $sch_id ); if ( is_array( $old_options ) ) { foreach ( $old_options as $key => $val ) { if ( ! in_array( $key, $filter_opts ) ) { $options[ $key ] = $old_options[ $key ]; } } } update_option( 'hmbkp_schedule_' . $sch_id, $options ); } $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $sch_id ) ); if ( ! empty( $options['reoccurrence'] ) && ! empty( $options['schedule_start_time'] ) ) { // Calculate the start time depending on the recurrence. $start_time = $options['schedule_start_time']; if ( $start_time ) { $schedule->set_schedule_start_time( $start_time ); } } if ( ! empty( $options['reoccurrence'] ) ) { $schedule->set_reoccurrence( $options['reoccurrence'] ); } $out['result'] = 'SUCCESS'; } delete_transient( 'hmbkp_schedules' ); return $out; } public static function is_activated() { if ( ! defined( 'HMBKP_PLUGIN_PATH' ) || ! class_exists( 'HM\BackUpWordPress\Plugin' ) ) { return false; } return true; } public function all_plugins( $plugins ) { foreach ( $plugins as $key => $value ) { $plugin_slug = basename( $key, '.php' ); if ( 'backupwordpress' === $plugin_slug ) { unset( $plugins[ $key ] ); } } return $plugins; } public function remove_menu() { global $submenu; if ( isset( $submenu['tools.php'] ) ) { foreach ( $submenu['tools.php'] as $index => $item ) { if ( 'backupwordpress' === $item[2] ) { unset( $submenu['tools.php'][ $index ] ); break; } } } $pos = stripos( $_SERVER['REQUEST_URI'], 'tools.php?page=backupwordpress' ); if ( false !== $pos ) { wp_safe_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' ); exit(); } } }