PluginProbe
Jetpack Protect / 4.4.0
Jetpack Protect v4.4.0
6.1.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.0-beta 1.3.0-beta2 1.4.0 1.4.0-beta 1.4.1 1.4.2 2.0.0 2.1.0 2.2.0 3.0.0 3.0.0-beta 3.0.1 3.0.2 All 35 releases
jetpack-protect / jetpack-protect.php

jetpack-protect.php in Jetpack Protect 4.4.0, at jetpack-protect.php

141 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Jetpack Protect
4 * Plugin URI: https://wordpress.org/plugins/jetpack-protect
5 * Description: Security tools that keep your site safe and sound, from posts to plugins.
6 * Version: 4.4.0
7 * Author: Automattic - Jetpack Security team
8 * Author URI: https://jetpack.com/protect/
9 * License: GPLv2 or later
10 * Text Domain: jetpack-protect
11 *
12 * @package automattic/jetpack-protect
13 */
14
15 /*
16 This program is free software; you can redistribute it and/or
17 modify it under the terms of the GNU General Public License
18 as published by the Free Software Foundation; either version 2
19 of the License, or (at your option) any later version.
20
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 */
30
31 if ( ! defined( 'ABSPATH' ) ) {
32 exit( 0 );
33 }
34
35 define( 'JETPACK_PROTECT_VERSION', '4.4.0' );
36 define( 'JETPACK_PROTECT_DIR', plugin_dir_path( __FILE__ ) );
37 define( 'JETPACK_PROTECT_ROOT_FILE', __FILE__ );
38 define( 'JETPACK_PROTECT_ROOT_FILE_RELATIVE_PATH', plugin_basename( __FILE__ ) );
39 define( 'JETPACK_PROTECT_SLUG', 'jetpack-protect' );
40 define( 'JETPACK_PROTECT_NAME', 'Jetpack Protect' );
41 define( 'JETPACK_PROTECT_URI', 'https://jetpack.com/jetpack-protect' );
42 define( 'JETPACK_PROTECT_FOLDER', dirname( plugin_basename( __FILE__ ) ) );
43 define( 'JETPACK_PROTECT_BASE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
44
45 // Jetpack Autoloader.
46 $jetpack_autoloader = JETPACK_PROTECT_DIR . 'vendor/autoload_packages.php';
47 if ( is_readable( $jetpack_autoloader ) ) {
48 require_once $jetpack_autoloader;
49 if ( method_exists( \Automattic\Jetpack\Assets::class, 'alias_textdomains_from_file' ) ) {
50 \Automattic\Jetpack\Assets::alias_textdomains_from_file( JETPACK_PROTECT_DIR . 'jetpack_vendor/i18n-map.php' );
51 }
52 } else { // Something very unexpected. Error out gently with an admin_notice and exit loading.
53 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
54 error_log( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
55 __( 'Error loading autoloader file for Jetpack Protect plugin', 'jetpack-protect' )
56 );
57 }
58
59 // Add a red bubble notification to My Jetpack if the installation is bad.
60 add_filter(
61 'my_jetpack_red_bubble_notification_slugs',
62 function ( $slugs ) {
63 $slugs['jetpack-protect-plugin-bad-installation'] = array(
64 'data' => array(
65 'plugin' => 'Jetpack Protect',
66 ),
67 );
68
69 return $slugs;
70 }
71 );
72
73 add_action(
74 'admin_notices',
75 function () {
76 if ( get_current_screen()->id !== 'plugins' ) {
77 return;
78 }
79
80 $message = sprintf(
81 wp_kses(
82 /* translators: Placeholder is a link to a support document. */
83 __( 'Your installation of Jetpack Protect is incomplete. If you installed Jetpack Protect from GitHub, please refer to <a href="%1$s" target="_blank" rel="noopener noreferrer">this document</a> to set up your development environment. Jetpack Protect must have Composer dependencies installed and built via the build command.', 'jetpack-protect' ),
84 array(
85 'a' => array(
86 'href' => array(),
87 'target' => array(),
88 'rel' => array(),
89 ),
90 )
91 ),
92 'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md#building-your-project'
93 );
94 wp_admin_notice(
95 $message,
96 array(
97 'type' => 'error',
98 'dismissible' => true,
99 )
100 );
101 }
102 );
103
104 return;
105 }
106
107 // Redirect to plugin page when the plugin is activated.
108 add_action( 'activated_plugin', 'jetpack_protect_plugin_activation' );
109
110 /**
111 * Redirects to plugin page when the plugin is activated
112 *
113 * @param string $plugin Path to the plugin file relative to the plugins directory.
114 */
115 function jetpack_protect_plugin_activation( $plugin ) {
116 if (
117 JETPACK_PROTECT_ROOT_FILE_RELATIVE_PATH === $plugin &&
118 ( new \Automattic\Jetpack\Paths() )->is_current_request_activating_plugin_from_plugins_screen( JETPACK_PROTECT_ROOT_FILE_RELATIVE_PATH )
119 ) {
120 wp_safe_redirect( esc_url( admin_url( 'admin.php?page=jetpack-protect' ) ) );
121 exit( 0 );
122 }
123 }
124
125 // Add "Settings" link to plugins page.
126 add_filter(
127 'plugin_action_links_' . JETPACK_PROTECT_FOLDER . '/jetpack-protect.php',
128 function ( $actions ) {
129 $settings_link = '<a href="' . esc_url( admin_url( 'admin.php?page=jetpack-protect' ) ) . '">' . __( 'Dashboard', 'jetpack-protect' ) . '</a>';
130 array_unshift( $actions, $settings_link );
131
132 return $actions;
133 }
134 );
135
136 register_activation_hook( __FILE__, array( 'Jetpack_Protect', 'plugin_activation' ) );
137 register_deactivation_hook( __FILE__, array( 'Jetpack_Protect', 'plugin_deactivation' ) );
138
139 // Main plugin class.
140 new Jetpack_Protect();
141