PluginProbe
Jetpack VaultPress Backup / 3.0
Jetpack VaultPress Backup v3.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 3.0, at jetpack-backup.php

188 lines 6.1 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 VaultPress 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: 3.0
8 * Author: Automattic - Jetpack Backup team
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 use Automattic\Jetpack\Backup\V0005\Jetpack_Backup as My_Jetpack_Backup;
33 use Automattic\Jetpack\My_Jetpack\Initializer as My_Jetpack_Initializer;
34
35 if ( ! defined( 'ABSPATH' ) ) {
36 exit;
37 }
38
39 // Constant definitions.
40 define( 'JETPACK_BACKUP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
41 define( 'JETPACK_BACKUP_PLUGIN_ROOT_FILE_RELATIVE_PATH', plugin_basename( __FILE__ ) );
42 define( 'JETPACK_BACKUP_REQUIRED_JETPACK_VERSION', '10.0' );
43 define( 'JETPACK_BACKUP_PLUGIN_FOLDER', dirname( plugin_basename( __FILE__ ) ) );
44
45 /**
46 * Checks if Jetpack is installed and if yes, require version 10+
47 * Can be extended to check for various system requirements, such as WP or PHP version.
48 *
49 * @return bool|WP_Error True if system requirements are met, WP_Error if not.
50 */
51 function jetpack_backup_requirements_check() {
52 require_once ABSPATH . '/wp-admin/includes/plugin.php'; // to get is_plugin_active() early.
53
54 if ( ! is_plugin_active( 'jetpack/jetpack.php' ) ) {
55 return true;
56 }
57
58 $jetpack_plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/jetpack/jetpack.php', false, false );
59
60 if ( version_compare( $jetpack_plugin_data['Version'], JETPACK_BACKUP_REQUIRED_JETPACK_VERSION, '<' ) ) {
61 return new WP_Error(
62 'incompatible_jetpack_version',
63 __( 'The Jetpack VaultPress Backup plugin requires version 10 or higher of the Jetpack plugin. Please update your Jetpack plugin to continue.', 'jetpack-backup' )
64 );
65 }
66 return true;
67 }
68
69 $jetpack_backup_meets_requirements = jetpack_backup_requirements_check();
70 if ( is_wp_error( $jetpack_backup_meets_requirements ) ) {
71 add_action(
72 'admin_notices',
73 function () use ( $jetpack_backup_meets_requirements ) {
74 ?>
75 <div class="notice notice-error is-dismissible">
76 <p>
77 <?php
78 echo esc_html( $jetpack_backup_meets_requirements->get_error_message() );
79 ?>
80 </p>
81 </div>
82 <?php
83 }
84 );
85
86 return;
87 }
88
89 // Jetpack Autoloader.
90 $jetpack_autoloader = JETPACK_BACKUP_PLUGIN_DIR . 'vendor/autoload_packages.php';
91 if ( is_readable( $jetpack_autoloader ) ) {
92 require_once $jetpack_autoloader;
93 if ( method_exists( \Automattic\Jetpack\Assets::class, 'alias_textdomains_from_file' ) ) {
94 \Automattic\Jetpack\Assets::alias_textdomains_from_file( JETPACK_BACKUP_PLUGIN_DIR . 'jetpack_vendor/i18n-map.php' );
95 }
96 } else { // Something very unexpected. Error out gently with an admin_notice and exit loading.
97 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
98 error_log( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
99 __( 'Error loading autoloader file for Jetpack VaultPress Backup plugin', 'jetpack-backup' )
100 );
101 }
102
103 // Add a red bubble notification to My Jetpack if the installation is bad.
104 add_filter(
105 'my_jetpack_red_bubble_notification_slugs',
106 function ( $slugs ) {
107 $slugs['jetpack-vaultpress-backup-plugin-bad-installation'] = array(
108 'data' => array(
109 'plugin' => 'Jetpack VaultPress Backup',
110 ),
111 );
112
113 return $slugs;
114 }
115 );
116
117 add_action(
118 'admin_notices',
119 function () {
120 if ( get_current_screen()->id !== 'plugins' ) {
121 return;
122 }
123 $message = sprintf(
124 wp_kses(
125 /* translators: Placeholder is a link to a support document. */
126 __( 'Your installation of Jetpack VaultPress Backup is incomplete. If you installed Jetpack VaultPress 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 VaultPress Backup must have Composer dependencies installed and built via the build command.', 'jetpack-backup' ),
127 array(
128 'a' => array(
129 'href' => array(),
130 'target' => array(),
131 'rel' => array(),
132 ),
133 )
134 ),
135 'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md#building-your-project'
136 );
137 wp_admin_notice(
138 $message,
139 array(
140 'type' => 'error',
141 'dismissible' => true,
142 )
143 );
144 }
145 );
146
147 return;
148 }
149
150 // Redirect to plugin page when the plugin is activated.
151 add_action( 'activated_plugin', 'jetpack_backup_plugin_activation' );
152
153 /**
154 * Redirects to plugin page when the plugin is activated
155 *
156 * @access public
157 * @static
158 *
159 * @param string $plugin Path to the plugin file relative to the plugins directory.
160 */
161 function jetpack_backup_plugin_activation( $plugin ) {
162 if (
163 JETPACK_BACKUP_PLUGIN_ROOT_FILE_RELATIVE_PATH === $plugin &&
164 ( new \Automattic\Jetpack\Paths() )->is_current_request_activating_plugin_from_plugins_screen( JETPACK_BACKUP_PLUGIN_ROOT_FILE_RELATIVE_PATH )
165 ) {
166 wp_safe_redirect( esc_url( admin_url( 'admin.php?page=jetpack-backup' ) ) );
167 exit;
168 }
169 }
170
171 // Add "Settings" link to plugins page.
172 add_filter(
173 'plugin_action_links_' . JETPACK_BACKUP_PLUGIN_FOLDER . '/jetpack-backup.php',
174 function ( $actions ) {
175 $settings_link = '<a href="' . esc_url( admin_url( 'admin.php?page=jetpack-backup' ) ) . '">' . __( 'Settings', 'jetpack-backup' ) . '</a>';
176 array_unshift( $actions, $settings_link );
177
178 return $actions;
179 }
180 );
181
182 register_deactivation_hook( __FILE__, array( 'Automattic\\Jetpack\\Backup\\V0005\\Jetpack_Backup', 'plugin_deactivation' ) );
183
184 // Main plugin class.
185 My_Jetpack_Backup::initialize();
186 // My Jetpack.
187 My_Jetpack_Initializer::init();
188