PluginProbe
Jetpack Protect / trunk
Jetpack Protect vtrunk
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 trunk, at jetpack-protect.php

140 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: 6.1.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, see <https://www.gnu.org/licenses/>.
28 */
29
30 if ( ! defined( 'ABSPATH' ) ) {
31 exit( 0 );
32 }
33
34 define( 'JETPACK_PROTECT_VERSION', '6.1.0' );
35 define( 'JETPACK_PROTECT_DIR', plugin_dir_path( __FILE__ ) );
36 define( 'JETPACK_PROTECT_ROOT_FILE', __FILE__ );
37 define( 'JETPACK_PROTECT_ROOT_FILE_RELATIVE_PATH', plugin_basename( __FILE__ ) );
38 define( 'JETPACK_PROTECT_SLUG', 'jetpack-protect' );
39 define( 'JETPACK_PROTECT_NAME', 'Jetpack Protect' );
40 define( 'JETPACK_PROTECT_URI', 'https://jetpack.com/jetpack-protect' );
41 define( 'JETPACK_PROTECT_FOLDER', dirname( plugin_basename( __FILE__ ) ) );
42 define( 'JETPACK_PROTECT_BASE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
43
44 // Jetpack Autoloader.
45 $jetpack_autoloader = JETPACK_PROTECT_DIR . 'vendor/autoload_packages.php';
46 if ( is_readable( $jetpack_autoloader ) ) {
47 require_once $jetpack_autoloader;
48 if ( method_exists( \Automattic\Jetpack\Assets::class, 'alias_textdomains_from_file' ) ) {
49 \Automattic\Jetpack\Assets::alias_textdomains_from_file( JETPACK_PROTECT_DIR . 'jetpack_vendor/i18n-map.php' );
50 }
51 } else { // Something very unexpected. Error out gently with an admin_notice and exit loading.
52 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
53 error_log( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
54 __( 'Error loading autoloader file for Jetpack Protect plugin', 'jetpack-protect' )
55 );
56 }
57
58 // Add a red bubble notification to My Jetpack if the installation is bad.
59 add_filter(
60 'my_jetpack_red_bubble_notification_slugs',
61 function ( $slugs ) {
62 $slugs['jetpack-protect-plugin-bad-installation'] = array(
63 'data' => array(
64 'plugin' => 'Jetpack Protect',
65 ),
66 );
67
68 return $slugs;
69 }
70 );
71
72 add_action(
73 'admin_notices',
74 function () {
75 if ( get_current_screen()->id !== 'plugins' ) {
76 return;
77 }
78
79 $message = sprintf(
80 wp_kses(
81 /* translators: Placeholder is a link to a support document. */
82 __( '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' ),
83 array(
84 'a' => array(
85 'href' => array(),
86 'target' => array(),
87 'rel' => array(),
88 ),
89 )
90 ),
91 'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md#building-your-project'
92 );
93 wp_admin_notice(
94 $message,
95 array(
96 'type' => 'error',
97 'dismissible' => true,
98 )
99 );
100 }
101 );
102
103 return;
104 }
105
106 // Redirect to plugin page when the plugin is activated.
107 add_action( 'activated_plugin', 'jetpack_protect_plugin_activation' );
108
109 /**
110 * Redirects to plugin page when the plugin is activated
111 *
112 * @param string $plugin Path to the plugin file relative to the plugins directory.
113 */
114 function jetpack_protect_plugin_activation( $plugin ) {
115 if (
116 JETPACK_PROTECT_ROOT_FILE_RELATIVE_PATH === $plugin &&
117 ( new \Automattic\Jetpack\Paths() )->is_current_request_activating_plugin_from_plugins_screen( JETPACK_PROTECT_ROOT_FILE_RELATIVE_PATH )
118 ) {
119 wp_safe_redirect( esc_url( admin_url( 'admin.php?page=jetpack-protect' ) ) );
120 exit( 0 );
121 }
122 }
123
124 // Add "Settings" link to plugins page.
125 add_filter(
126 'plugin_action_links_' . JETPACK_PROTECT_FOLDER . '/jetpack-protect.php',
127 function ( $actions ) {
128 $settings_link = '<a href="' . esc_url( admin_url( 'admin.php?page=jetpack-protect' ) ) . '">' . __( 'Dashboard', 'jetpack-protect' ) . '</a>';
129 array_unshift( $actions, $settings_link );
130
131 return $actions;
132 }
133 );
134
135 register_activation_hook( __FILE__, array( 'Jetpack_Protect', 'plugin_activation' ) );
136 register_deactivation_hook( __FILE__, array( 'Jetpack_Protect', 'plugin_deactivation' ) );
137
138 // Main plugin class.
139 new Jetpack_Protect();
140