PluginProbe
Jetpack VaultPress Backup / 1.5
Jetpack VaultPress Backup v1.5
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.5, at jetpack-backup.php

171 lines 5.6 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: 1.5
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 use Automattic\Jetpack\My_Jetpack\Initializer as My_Jetpack_Initializer;
33
34 if ( ! defined( 'ABSPATH' ) ) {
35 exit;
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 requiremens, 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_action(
103 'admin_notices',
104 function () {
105 ?>
106 <div class="notice notice-error is-dismissible">
107 <p>
108 <?php
109 printf(
110 wp_kses(
111 /* translators: Placeholder is a link to a support document. */
112 __( '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' ),
113 array(
114 'a' => array(
115 'href' => array(),
116 'target' => array(),
117 'rel' => array(),
118 ),
119 )
120 ),
121 'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md#building-your-project'
122 );
123 ?>
124 </p>
125 </div>
126 <?php
127 }
128 );
129
130 return;
131 }
132
133 // Redirect to plugin page when the plugin is activated.
134 add_action( 'activated_plugin', 'jetpack_backup_plugin_activation' );
135
136 /**
137 * Redirects to plugin page when the plugin is activated
138 *
139 * @access public
140 * @static
141 *
142 * @param string $plugin Path to the plugin file relative to the plugins directory.
143 */
144 function jetpack_backup_plugin_activation( $plugin ) {
145 if (
146 JETPACK_BACKUP_PLUGIN_ROOT_FILE_RELATIVE_PATH === $plugin &&
147 \Automattic\Jetpack\Plugins_Installer::is_current_request_activating_plugin_from_plugins_screen( JETPACK_BACKUP_PLUGIN_ROOT_FILE_RELATIVE_PATH )
148 ) {
149 wp_safe_redirect( esc_url( admin_url( 'admin.php?page=jetpack-backup' ) ) );
150 exit;
151 }
152 }
153
154 // Add "Settings" link to plugins page.
155 add_filter(
156 'plugin_action_links_' . JETPACK_BACKUP_PLUGIN_FOLDER . '/jetpack-backup.php',
157 function ( $actions ) {
158 $settings_link = '<a href="' . esc_url( admin_url( 'admin.php?page=jetpack-backup' ) ) . '">' . __( 'Settings', 'jetpack-backup' ) . '</a>';
159 array_unshift( $actions, $settings_link );
160
161 return $actions;
162 }
163 );
164
165 register_deactivation_hook( __FILE__, array( 'Jetpack_Backup', 'plugin_deactivation' ) );
166
167 // Main plugin class.
168 Jetpack_Backup::initialize();
169 // My Jetpack.
170 My_Jetpack_Initializer::init();
171