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

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