PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 All 508 releases
← All changes | 3rd-party/jetpack-backup.php +107 -0 16.2-beta → 16.3 View file →
@@ -1,0 +1,107 @@
1 +<?php
2 +/**
3 + * Compatibility functions for the Jetpack Backup plugin.
4 + * https://wordpress.org/plugins/jetpack-backup/
5 + *
6 + * @since 10.4
7 + *
8 + * @package automattic/jetpack
9 + */
10 +
11 +namespace Automattic\Jetpack\Jetpack_Backup;
12 +
13 +use Automattic\Jetpack\Plugins_Installer;
14 +
15 +if ( ! defined( 'ABSPATH' ) ) {
16 + exit( 0 );
17 +}
18 +
19 +const PLUGIN_SLUG = 'jetpack-backup';
20 +const PLUGIN_FILE = 'jetpack-backup/jetpack-backup.php';
21 +
22 +if ( isset( $_GET['jetpack-backup-install-error'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
23 + add_action( 'admin_notices', __NAMESPACE__ . '\error_notice' );
24 +}
25 +
26 +if ( isset( $_GET['jetpack-backup-action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
27 + add_action( 'admin_init', __NAMESPACE__ . '\try_install' );
28 +}
29 +
30 +/**
31 + * Verify the intent to install Jetpack Backup, and kick off installation.
32 + *
33 + * This works in tandem with a JITM set up in the JITM package.
34 + *
35 + * @return never
36 + */
37 +function try_install() {
38 + check_admin_referer( 'jetpack-backup-install' );
39 +
40 + $result = false;
41 + // If the plugin install fails, redirect to plugin install page pre-populated with jetpack-backup search term.
42 + $redirect_on_error = admin_url( 'plugin-install.php?s=jetpack-backup&tab=search&type=term' );
43 +
44 + // Attempt to install and activate the plugin.
45 + if ( current_user_can( 'activate_plugins' ) ) {
46 + switch ( $_GET['jetpack-backup-action'] ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated -- Function only hooked if set.
47 + case 'install':
48 + $result = install_and_activate();
49 + break;
50 + case 'activate':
51 + $result = activate();
52 + break;
53 + }
54 + }
55 +
56 + if ( $result ) {
57 + /** This action is already documented in _inc/lib/class.core-rest-api-endpoints.php */
58 + do_action( 'jetpack_activated_plugin', PLUGIN_FILE, 'jitm' );
59 + $redirect = admin_url( 'admin.php?page=jetpack-backup' );
60 + } else {
61 + $redirect = add_query_arg( 'jetpack-backup-install-error', true, $redirect_on_error );
62 + }
63 +
64 + wp_safe_redirect( $redirect );
65 +
66 + exit( 0 );
67 +}
68 +
69 +/**
70 + * Install and activate the Jetpack Backup plugin.
71 + *
72 + * @return bool result of installation
73 + */
74 +function install_and_activate() {
75 + $result = Plugins_Installer::install_and_activate_plugin( PLUGIN_SLUG );
76 +
77 + if ( is_wp_error( $result ) ) {
78 + return false;
79 + } else {
80 + return true;
81 + }
82 +}
83 +
84 +/**
85 + * Activate the Jetpack Backup plugin.
86 + *
87 + * @return bool result of activation
88 + */
89 +function activate() {
90 + $result = activate_plugin( PLUGIN_FILE );
91 +
92 + // Activate_plugin() returns null on success.
93 + return $result === null;
94 +}
95 +
96 +/**
97 + * Notify the user that the installation of Jetpack Backup failed.
98 + */
99 +function error_notice() {
100 + wp_admin_notice(
101 + esc_html__( 'There was an error installing Jetpack Backup. Please try again.', 'jetpack' ),
102 + array(
103 + 'type' => 'error',
104 + 'dismissible' => true,
105 + )
106 + );
107 +}