PluginProbe
WP Database Backup – Unlimited Database & Files Backup by Backup for WP / 7.10
WP Database Backup – Unlimited Database & Files Backup by Backup for WP v7.10
7.13 7.12 trunk 1.1 2.1.1 5.9 6.0 6.1 6.10 6.11 6.12 6.12.1 6.2 6.3 6.4 6.5 6.5.1 6.6 6.7 6.8 6.9 7.0 7.0.1 7.1 7.10 All 34 releases
wp-database-backup / wp-database-backup.php

wp-database-backup.php in WP Database Backup – Unlimited Database & Files Backup by Backup for WP 7.10, at wp-database-backup.php

230 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: WP Database Backup - Unlimited Database & Files Backup by Backup for WP
4 * Plugin URI: https://wordpress.org/plugins/wp-database-backup
5 * Description: This plugin helps you to create/restore Unlimited WordPress Database & Files backup.
6 * Version: 7.10
7 * Author: Backup for WP
8 * Author URI: https://backupforwp.com/
9 * Text Domain: wpdbbkp
10 * Domain Path: /lang
11 *
12 * This plugin helps you to create Database Backup easily.
13 *
14 * License: GPL v2
15 *
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 */
29
30 if ( ! defined( 'ABSPATH' ) ) {
31 exit; // Exit if accessed directly.
32 }
33
34 if ( ! class_exists( 'WPDatabaseBackup' ) ) :
35
36 /**
37 * Main WPDatabaseBackup Class.
38 *
39 * @class WPDatabaseBackup
40 *
41 * @version 7.10
42 */
43 final class WPDatabaseBackup {
44
45 /**
46 * Plugin version
47 *
48 * @var string
49 */
50 public $version = '7.10';
51
52 /**
53 * Plugin instance
54 *
55 * @var object
56 */
57 protected static $instance = null;
58
59 /**
60 * Create Instance.
61 */
62 public static function instance() {
63 if ( is_null( self::$instance ) ) {
64 self::$instance = new self();
65 }
66
67 return self::$instance;
68 }
69
70 /**
71 * Clone.
72 */
73 public function __clone() {
74 _doing_it_wrong( __FUNCTION__, 'Cheatin&#8217; huh?', '1.0' );
75 }
76
77 /**
78 * Construct.
79 */
80 public function __construct() {
81 // Define constants.
82 $this->define_constants();
83 register_activation_hook( __FILE__, array( $this, 'installation' ) );
84 $this->installation(2);
85 // Include required files.
86 $this->includes();
87 }
88
89 /**
90 * Define Constants.
91 */
92 private function define_constants() {
93 if ( ! defined( 'WPDB_PLUGIN_URL' ) ) {
94 define( 'WPDB_PLUGIN_URL', WP_CONTENT_URL . '/plugins/wp-database-backup' );
95 }
96 define( 'WPDB_PLUGIN_FILE', __FILE__ );
97 define('WP_BACKUP_PLUGIN_FILE',__FILE__ );
98 define( 'WPDB_PATH', plugin_dir_path( __FILE__ ) );
99 define( 'WPDB_ROOTPATH', str_replace( '\\', '/', ABSPATH ) );
100 define( 'WPDB_VERSION', $this->version );
101 define( 'WPDBPLUGIN_VERSION', WPDB_VERSION );
102 $wp_all_backup_backups_dir=get_option('wp_db_backup_backups_dir');
103 if(!empty($wp_all_backup_backups_dir)){
104 define( 'WPDB_BACKUPS_DIR',$wp_all_backup_backups_dir);
105 }else{
106 define( 'WPDB_BACKUPS_DIR','db-backup');
107 }
108 }
109
110 /**
111 * Include Requred files and lib.
112 */
113 private function includes()
114 {
115 // Ensure WPDB_PATH is defined - if not, define it now
116 if ( ! defined( 'WPDB_PATH' ) ) {
117 define( 'WPDB_PATH', plugin_dir_path( __FILE__ ) );
118 }
119
120 // Use plugin_dir_path directly to ensure we always have a valid absolute path
121 // This prevents issues if WPDB_PATH constant is empty or not set correctly
122 $plugin_path = plugin_dir_path( __FILE__ );
123
124 $admin_path = $plugin_path . 'includes/admin/';
125 $includes_path = $plugin_path . 'includes/';
126
127 if ( file_exists( $admin_path . 'mb-helper-functions.php' ) ) {
128 include_once $admin_path . 'mb-helper-functions.php';
129 }
130 if ( file_exists( $admin_path . 'class-wpdb-admin.php' ) ) {
131 include_once $admin_path . 'class-wpdb-admin.php';
132 }
133 if ( file_exists( $admin_path . 'Destination/wp-backup-destination-upload-action.php' ) ) {
134 include_once $admin_path . 'Destination/wp-backup-destination-upload-action.php';
135 }
136 if ( file_exists( $includes_path . 'class-wpdbbackuplog.php' ) ) {
137 include_once $includes_path . 'class-wpdbbackuplog.php';
138 }
139 if ( file_exists( $admin_path . 'filter.php' ) ) {
140 include_once $admin_path . 'filter.php';
141 }
142 if ( file_exists( $admin_path . 'class-wpdbbkp-newsletter.php' ) ) {
143 include_once $admin_path . 'class-wpdbbkp-newsletter.php';
144 }
145 if ( file_exists( $includes_path . 'features.php' ) ) {
146 include_once $includes_path . 'features.php';
147 }
148 $wp_db_incremental_backup = get_option('wp_db_incremental_backup');
149 $wpdb_clouddrive_cd = get_option('wpdb_clouddrive_token', false);
150 $wp_db_backup_destination_bb = get_option('wp_db_backup_destination_bb', false);
151 if (($wp_db_incremental_backup == 1 && $wp_db_backup_destination_bb ==1 )|| ($wpdb_clouddrive_cd && !empty($wpdb_clouddrive_cd))) {
152 if ( file_exists( $admin_path . 'cron-create-full-backup-incremental.php' ) ) {
153 include_once $admin_path . 'cron-create-full-backup-incremental.php';
154 }
155 } else {
156 if ( file_exists( $admin_path . 'cron-create-full-backup.php' ) ) {
157 include_once $admin_path . 'cron-create-full-backup.php';
158 }
159 }
160 if ( file_exists( $includes_path . 'class-wpdbfullbackuplog.php' ) ) {
161 include_once $includes_path . 'class-wpdbfullbackuplog.php';
162 }
163
164 }
165 /**
166 * Installation setting at time of activation.
167 */
168 public function installation($flag=1) {
169 add_option( 'wp_db_backup_destination_SFTP', 0 , '' , false );
170 add_option( 'wp_db_backup_destination_FTP', 0 , '' , false );
171 add_option( 'wp_db_backup_destination_Email',0 , '' , false );
172 add_option( 'wp_db_backup_destination_s3', 0 , '' , false );
173 add_option( 'wp_db_remove_local_backup', 0 , '' , false );
174 add_option( 'wp_db_remove_on_uninstall', 0 , '' , false );
175 add_option('wp_db_backup_backup_type','complete', '' , false );
176 add_option('wp_db_backup_exclude_dir',"wp-content/backupwordpress-728d36f682-backups|.git|db-backup", '' , false );
177 add_option('wp_db_backup_backups_dir','db-backup', '' , false );
178 add_option('bb_last_backup_timestamp',0, '' , false );
179 add_option('wp_db_backup_sftp_details',null, '' , false );
180
181 if($flag!=2){
182 add_option( 'wpdbbkp_activation_redirect', true, '' , false );
183 }
184
185 $this->create_processed_files_table();
186 }
187
188 /**
189 * Logger.
190 */
191 public function logger() {
192 _deprecated_function( 'Wpekaplugin->logger', '1.0', 'new WPDB_Logger()' );
193 return new WPDB_Logger();
194 }
195
196 public function create_processed_files_table() {
197 global $wpdb;
198 $table_name = $wpdb->prefix . 'wpdbbkp_processed_files';
199 $charset_collate = $wpdb->get_charset_collate();
200
201 // Check if the table already exists
202 //phpcs:ignore -- Reason: Direct SQL execution is required here.
203 if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
204 //phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange
205 $sql = "CREATE TABLE $table_name (
206 id mediumint(9) NOT NULL AUTO_INCREMENT,
207 file_path text NOT NULL,
208 processed_at TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
209 status ENUM('added', 'updated', 'deleted') DEFAULT 'added' NOT NULL,
210 PRIMARY KEY (id),
211 UNIQUE (file_path(250))
212 ) $charset_collate;";
213
214 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
215 dbDelta($sql);
216 }
217 }
218 }
219
220 endif;
221
222 /**
223 * Returns the main instance of WP to prevent the need to use globals.
224 */
225 function wpdb() {
226 return WPDatabaseBackup::instance();
227 }
228
229 // Global for backwards compatibility.
230 $GLOBALS['wpdbplugin'] = wpdb();