PluginProbe
Jetpack VaultPress Backup / 1.2.0
Jetpack VaultPress Backup v1.2.0
3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7.1 3.8 3.9 trunk 0.2.0 1.0.0 1.0.1 1.1.0 1.2.0 1.3.0 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5 1.6 1.7 All 37 releases
jetpack-backup / jetpack-backup.php

jetpack-backup.php in Jetpack VaultPress Backup 1.2.0, at jetpack-backup.php

143 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 *
4 * Plugin Name: Jetpack Backup
5 * Plugin URI: https://jetpack.com/jetpack-backup
6 * Description: Easily restore or download a backup of your site from a specific moment in time.
7 * Version: 1.2
8 * Author: Automattic
9 * Author URI: https://jetpack.com/
10 * License: GPLv2 or later
11 * Text Domain: jetpack-backup
12 *
13 * @package automattic/jetpack-backup-plugin
14 */
15
16 /*
17 This program is free software; you can redistribute it and/or
18 modify it under the terms of the GNU General Public License
19 as published by the Free Software Foundation; either version 2
20 of the License, or (at your option) any later version.
21
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
26
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 */
31
32 if ( ! defined( 'ABSPATH' ) ) {
33 exit;
34 }
35
36 // Constant definitions.
37 define( 'JETPACK_BACKUP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
38 define( 'JETPACK_BACKUP_PLUGIN_ROOT_FILE', __FILE__ );
39 define( 'JETPACK_BACKUP_PLUGIN_ROOT_FILE_RELATIVE_PATH', plugin_basename( __FILE__ ) );
40 define( 'JETPACK_BACKUP_PLUGIN_SLUG', 'jetpack-backup' );
41 define( 'JETPACK_BACKUP_PLUGIN_NAME', 'Jetpack Backup' );
42 define( 'JETPACK_BACKUP_PLUGIN_URI', 'https://jetpack.com/jetpack-backup' );
43 define( 'JETPACK_BACKUP_REQUIRED_JETPACK_VERSION', '10.0' );
44 define( 'JETPACK_BACKUP_PLUGIN_FOLDER', dirname( plugin_basename( __FILE__ ) ) );
45 define( 'JETPACK_BACKUP_PROMOTED_PRODUCT', 'jetpack_backup_t1_yearly' );
46 define( 'JETPACK_BACKUP_DB_VERSION', '2' );
47
48 /**
49 * Checks if Jetpack is installed and if yes, require version 10+
50 * Can be extended to check for various system requiremens, such as WP or PHP version.
51 *
52 * @return bool|WP_Error True if system requirements are met, WP_Error if not.
53 */
54 function jetpack_backup_requirements_check() {
55 require_once ABSPATH . '/wp-admin/includes/plugin.php'; // to get is_plugin_active() early.
56
57 if ( ! is_plugin_active( 'jetpack/jetpack.php' ) ) {
58 return true;
59 }
60
61 $jetpack_plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/jetpack/jetpack.php', false, false );
62
63 if ( version_compare( $jetpack_plugin_data['Version'], JETPACK_BACKUP_REQUIRED_JETPACK_VERSION, '<' ) ) {
64 return new WP_Error(
65 'incompatible_jetpack_version',
66 __( 'The Jetpack Backup plugin requires version 10 or higher of the Jetpack plugin. Please update your Jetpack plugin to continue.', 'jetpack-backup' )
67 );
68 }
69 return true;
70 }
71
72 $jetpack_backup_meets_requirements = jetpack_backup_requirements_check();
73 if ( is_wp_error( $jetpack_backup_meets_requirements ) ) {
74 add_action(
75 'admin_notices',
76 function () use ( $jetpack_backup_meets_requirements ) {
77 ?>
78 <div class="notice notice-error is-dismissible">
79 <p>
80 <?php
81 echo esc_html( $jetpack_backup_meets_requirements->get_error_message() );
82 ?>
83 </p>
84 </div>
85 <?php
86 }
87 );
88
89 return;
90 }
91
92 // Jetpack Autoloader.
93 $jetpack_autoloader = JETPACK_BACKUP_PLUGIN_DIR . 'vendor/autoload_packages.php';
94 if ( is_readable( $jetpack_autoloader ) ) {
95 require_once $jetpack_autoloader;
96 if ( method_exists( \Automattic\Jetpack\Assets::class, 'alias_textdomains_from_file' ) ) {
97 \Automattic\Jetpack\Assets::alias_textdomains_from_file( JETPACK_BACKUP_PLUGIN_DIR . 'jetpack_vendor/i18n-map.php' );
98 }
99 } else { // Something very unexpected. Error out gently with an admin_notice and exit loading.
100 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
101 error_log( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
102 __( 'Error loading autoloader file for Jetpack Backup plugin', 'jetpack-backup' )
103 );
104 }
105
106 add_action(
107 'admin_notices',
108 function () {
109 ?>
110 <div class="notice notice-error is-dismissible">
111 <p>
112 <?php
113 printf(
114 wp_kses(
115 /* translators: Placeholder is a link to a support document. */
116 __( 'Your installation of Jetpack Backup is incomplete. If you installed Jetpack Backup from GitHub, please refer to <a href="%1$s" target="_blank" rel="noopener noreferrer">this document</a> to set up your development environment. Jetpack Backup must have Composer dependencies installed and built via the build command.', 'jetpack-backup' ),
117 array(
118 'a' => array(
119 'href' => array(),
120 'target' => array(),
121 'rel' => array(),
122 ),
123 )
124 ),
125 'https://github.com/Automattic/jetpack/blob/master/docs/development-environment.md#building-your-project'
126 );
127 ?>
128 </p>
129 </div>
130 <?php
131 }
132 );
133
134 return;
135 }
136
137 // Redirect to plugin page when the plugin is activated.
138 add_action( 'activated_plugin', array( 'Jetpack_Backup', 'plugin_activation' ) );
139
140 register_deactivation_hook( __FILE__, array( 'Jetpack_Backup', 'plugin_deactivation' ) );
141 // Main plugin class.
142 new Jetpack_Backup();
143