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

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