PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 3.0.1
Defender Security – Malware Scanner, Login Security & Firewall v3.0.1
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / src / class-admin.php

class-admin.php in Defender Security – Malware Scanner, Login Security & Firewall 3.0.1, at src/class-admin.php

361 lines 12.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WP_Defender;
4
5 use WP_Defender\Behavior\WPMUDEV;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 die();
9 }
10
11 /**
12 * Class Admin
13 *
14 * @since 2.4
15 */
16 class Admin {
17
18 /**
19 * @var bool
20 */
21 public $is_pro;
22
23 /**
24 * Init admin actions.
25 */
26 public function init() {
27 $this->is_pro = ( new WPMUDEV() )->is_pro();
28 $is_def_page = defender_current_page();
29 // Display plugin links.
30 add_filter( 'network_admin_plugin_action_links_' . DEFENDER_PLUGIN_BASENAME, array( $this, 'settings_link' ) );
31 add_filter( 'plugin_action_links_' . DEFENDER_PLUGIN_BASENAME, array( $this, 'settings_link' ) );
32 add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 3 );
33 // Only for wordpress.org members.
34 if ( ! $this->is_pro ) {
35 // Add plugin upgrade notification.
36 add_action( 'in_plugin_update_message-' . DEFENDER_PLUGIN_BASENAME, array( $this, 'show_upgrade_notice' ), 10, 2 );
37 if ( $is_def_page && ! is_multisite() ) {
38 add_action( 'admin_notices', array( $this, 'show_rating_notice' ) );
39 } elseif ( $is_def_page && is_multisite() && is_main_site() ) {
40 add_action( 'network_admin_notices', array( $this, 'show_rating_notice' ) );
41 }
42 add_action( 'wp_ajax_defender_dismiss_notification', array( $this, 'dismiss_notice' ) );
43 add_action( 'admin_init', array( $this, 'register_free_modules' ), 20 );
44 } else {
45 // For Pro version.
46 add_action(
47 'load-plugins.php',
48 function () {
49 add_action( 'after_plugin_row_' . DEFENDER_PLUGIN_BASENAME, array(
50 $this,
51 'show_upgrade_notice'
52 ), 10, 2 );
53 },
54 22
55 );
56 }
57 }
58
59 /**
60 * Return URL link.
61 *
62 * @param string $link_for Accepts: 'docs', 'plugin', 'rate', 'support', 'roadmap'.
63 * @param string $campaign Utm campaign tag to be used in link. Default: ''.
64 * @param string $adv_path Advanced path. Default: ''.
65 *
66 * @return string
67 */
68 public function get_link( $link_for, $campaign = '', $adv_path = '' ) {
69 $domain = 'https://wpmudev.com';
70 $wp_org = 'https://wordpress.org';
71 $utm_tags = "?utm_source=defender&utm_medium=plugin&utm_campaign={$campaign}";
72 switch ( $link_for ) {
73 case 'docs':
74 $link = "{$domain}/docs/wpmu-dev-plugins/defender/{$utm_tags}";
75 break;
76 case 'plugin':
77 $link = "{$domain}/project/wp-defender/{$utm_tags}";
78 break;
79 case 'rate':
80 $link = "{$wp_org}/support/plugin/defender-security/reviews/#new-post";
81 break;
82 case 'support':
83 $link = $this->is_pro ? "{$domain}/get-support/" : "{$wp_org}/support/plugin/defender-security/";
84 break;
85 case 'roadmap':
86 $link = "{$domain}/roadmap/";
87 break;
88 case 'pro_link':
89 $link = "{$domain}/$adv_path";
90 break;
91 default:
92 $link = '';
93 break;
94 }
95
96 return $link;
97 }
98
99
100 /**
101 * Adds a settings link on plugin page.
102 *
103 * @param array $links Current links.
104 *
105 * @return array
106 */
107 public function settings_link( $links ) {
108 $action_links = [];
109 $wpmu_dev = new WPMUDEV();
110 // Settings link.
111 $action_links['dashboard'] = '<a href="' . network_admin_url( 'admin.php?page=wdf-setting' ) . '" aria-label="' . esc_attr( __( 'Go to Defender Settings', 'wpdef' ) ) . '">' . esc_html__( 'Settings', 'wpdef' ) . '</a>';
112 // Documentation link.
113 $action_links['docs'] = '<a target="_blank" href="' . $this->get_link('docs', 'defender_pluginlist_docs') . '" aria-label="' . esc_attr(__('Docs', 'wpdef')) . '">' . esc_html__('Docs', 'wpdef') . '</a>';
114 if ( ! $wpmu_dev->is_member() ) {
115 if ( WP_DEFENDER_PRO_PATH !== DEFENDER_PLUGIN_BASENAME ) {
116 $action_links['upgrade'] = '<a style="color: #8D00B1;" target="_blank" href="' . $this->get_link( 'plugin', 'defender_pluginlist_upgrade' ) . '" aria-label="' . esc_attr( __( 'Upgrade to Defender Pro', 'wpdef' ) ) . '">' . esc_html__( 'Upgrade', 'wpdef' ) . '</a>';
117 } else {
118 $action_links['renew'] = '<a style="color: #8D00B1;" target="_blank" href="' . $this->get_link( 'plugin', 'defender_pluginlist_renew' ) . '" aria-label="' . esc_attr( __( 'Renew Your Membership', 'wpdef' ) ) . '">' . esc_html__( 'Renew Membership', 'wpdef' ) . '</a>';
119 }
120 }
121
122 return array_merge( $action_links, $links );
123 }
124
125 /**
126 * Show row meta on the plugin screen.
127 *
128 * @param mixed $links Plugin Row Meta.
129 * @param mixed $file Plugin Base file.
130 * @param array $plugin_data Plugin data.
131 *
132 * @return array
133 */
134 public function plugin_row_meta( $links, $file, $plugin_data ) {
135 $row_meta = [];
136 if ( ! defined( 'DEFENDER_PLUGIN_BASENAME' ) || DEFENDER_PLUGIN_BASENAME !== $file ) {
137 return $links;
138 }
139
140 // Change AuthorURI link.
141 if ( isset( $links[1] ) ) {
142 $author_uri = $this->is_pro ? 'https://wpmudev.com/' : 'https://profiles.wordpress.org/wpmudev/';
143 $author_uri = sprintf(
144 '<a href="%s" target="_blank">%s</a>',
145 $author_uri,
146 __( 'WPMU DEV' )
147 );
148 $links[1] = sprintf( /* translators: ... */ __( 'By %s' ), $author_uri );
149 }
150
151 if ( ! $this->is_pro ) {
152 // Change AuthorURI link.
153 if ( isset( $links[2] ) && false === strpos( $links[2], 'target="_blank"' ) ) {
154 if ( ! isset( $plugin_data['slug'] ) && $plugin_data['Name'] ) {
155 $links[2] = sprintf(
156 '<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>',
157 esc_url(
158 network_admin_url(
159 'plugin-install.php?tab=plugin-information&plugin=defender-security' .
160 '&TB_iframe=true&width=600&height=550'
161 )
162 ),
163 /* translators: %s: Plugin name. */
164 esc_attr( sprintf( __( 'More information about %s' ), $plugin_data['Name'] ) ),
165 esc_attr( $plugin_data['Name'] ),
166 __( 'View details' )
167 );
168 } else {
169 $links[2] = str_replace( 'href=', 'target="_blank" href=', $links[2] );
170 }
171 }
172 $row_meta['rate'] = '<a href="' . esc_url( $this->get_link( 'rate' ) ) . '" aria-label="' . esc_attr__( 'Rate Defender', 'wpdef' ) . '" target="_blank">' . esc_html__( 'Rate Defender', 'wpdef' ) . '</a>';
173 $row_meta['support'] = '<a href="' . esc_url( $this->get_link( 'support' ) ) . '" aria-label="' . esc_attr__( 'Support', 'wpdef' ) . '" target="_blank">' . esc_html__( 'Support', 'wpdef' ) . '</a>';
174 } else {
175 // Change 'Visit plugins' link to 'View details'.
176 if ( isset( $links[2] ) && false !== strpos( $links[2], 'project/wp-defender' ) ) {
177 $links[2] = sprintf(
178 '<a href="%s" target="_blank">%s</a>',
179 esc_url( $this->get_link( 'pro_link', '', 'project/wp-defender/' ) ),
180 __( 'View details' )
181 );
182 }
183 $row_meta['support'] = '<a href="' . esc_url( $this->get_link( 'support' ) ) . '" aria-label="' . esc_attr__( 'Premium Support', 'wpdef' ) . '" target="_blank">' . esc_html__( 'Premium Support', 'wpdef' ) . '</a>';
184 }
185 $row_meta['roadmap'] = '<a href="' . esc_url( $this->get_link( 'roadmap' ) ) . '" aria-label="' . esc_attr__( 'Roadmap', 'wpdef' ) . '" target="_blank">' . esc_html__( 'Roadmap', 'wpdef' ) . '</a>';
186
187 return array_merge( $links, $row_meta );
188 }
189
190 /**
191 * Dismiss notice.
192 */
193 public function dismiss_notice() {
194 if ( ! current_user_can( 'manage_options' ) || ! check_ajax_referer( 'defender_dismiss_notification' ) ) {
195 wp_send_json_error(
196 array(
197 'message' => __( 'Invalid request, you are not allowed to do that action.', 'wpdef' ),
198 )
199 );
200 }
201
202 $notification_name = ! empty( $_POST['prop'] ) ? sanitize_text_field( $_POST['prop'] ) : false;
203 if ( false === $notification_name ) {
204 wp_send_json_error(
205 array(
206 'message' => __( 'Invalid request, allowed data not provided.', 'wpdef' ),
207 )
208 );
209 }
210 update_site_option( $notification_name, true );
211
212 wp_send_json_success();
213 }
214
215 /**
216 * Register sub-modules.
217 */
218 public function register_free_modules() {
219 if (
220 ! file_exists( defender_path( 'extra/free-dashboard/module.php' ) )
221 || ! file_exists( defender_path( 'extra/recommended-plugins-notice/notice.php' ) )
222 ) {
223 return;
224 }
225 /* @noinspection PhpIncludeInspection */
226 require_once( defender_path( 'extra/free-dashboard/module.php' ) );
227 /* @noinspection PhpIncludeInspection */
228 require_once( defender_path( 'extra/recommended-plugins-notice/notice.php' ) );
229
230 // Register the current plugin.
231 do_action(
232 'wdev_register_plugin',
233 /* 1 Plugin ID */ DEFENDER_PLUGIN_BASENAME,
234 /* 2 Plugin Title */ 'Defender',
235 /* 3 https://wordpress.org */ '/plugins/defender-security/',
236 /* 4 Email Button CTA */ __( 'Get Fast!', 'wpdef' )
237 /* 5 Mailchimp List id for the plugin - No */
238 );
239
240 // Recommended plugin notice.
241 do_action(
242 'wpmudev-recommended-plugins-register-notice',
243 DEFENDER_PLUGIN_BASENAME, // Plugin basename
244 'Defender', // Plugin Name
245 array(
246 'toplevel_page_wp-defender',
247 'toplevel_page_wp-defender-network',
248 ),
249 array( 'after', '.sui-wrap .sui-header' )
250 );
251 }
252
253 /**
254 * Show the rating notice.
255 */
256 public function show_rating_notice() {
257 // @since 2.6.1
258 if ( get_site_option( 'defender_rating_success', apply_filters( 'wd_display_rating', false ) ) ) {
259 return;
260 }
261
262 $install_date = get_site_option( 'defender_free_install_date', false );
263 // @since 2.6.1
264 $days_later_dismiss = get_site_option( 'defender_days_rating_later_dismiss',
265 apply_filters( 'wd_dismiss_rating', false )
266 );
267
268 if (
269 $install_date && ! $days_later_dismiss
270 && current_time( 'timestamp' ) > strtotime( '+7 days', $install_date )
271 ) { ?>
272 <div id="defender-free-usage-notice"
273 class="defender-rating-notice notice notice-info"
274 data-nonce="<?php echo esc_attr( wp_create_nonce( 'defender_dismiss_notification' ) ); ?>">
275
276 <p style="color: #72777C; line-height: 22px;"><?php esc_html_e( 'We\'ve spent countless hours developing Defender and making it free for you to use. We would really appreciate it if you dropped us a quick rating!', 'wpdef' ); ?></p>
277
278 <p>
279 <button type="button" class="button button-primary button-large"
280 data-prop="defender_rating_success"><?php esc_html_e( 'Rate Defender', 'wpdef' ); ?></button>
281 <a href="#" class="dismiss"
282 style="margin-left: 11px; color: #555; line-height: 16px; font-weight: 500; text-decoration: none;"
283 data-prop="defender_days_rating_later_dismiss"><?php esc_html_e( 'Maybe later', 'wpdef' ); ?></a>
284 </p>
285 </div>
286 <?php
287 }
288 ?>
289
290 <script type="text/javascript">
291 jQuery('.defender-rating-notice a, .defender-rating-notice button').on('click', function (e) {
292 e.preventDefault();
293
294 var $notice = jQuery(e.currentTarget).closest('.defender-rating-notice'),
295 prop = jQuery(this).data('prop'),
296 ajaxUrl = '<?php echo admin_url( 'admin-ajax.php' ); ?>';
297
298 if ('defender_rating_success' === prop) {
299 window.open('https://wordpress.org/support/plugin/defender-security/reviews/#new-post', '_blank');
300 }
301
302 jQuery.post(
303 ajaxUrl,
304 {
305 action: 'defender_dismiss_notification',
306 prop: prop,
307 _ajax_nonce: $notice.data('nonce')
308 }
309 ).always(function () {
310 $notice.hide();
311 });
312 });
313 </script>
314
315 <?php
316 }
317
318 /**
319 * Show plugin update notice.
320 *
321 * @param string $plugin_file
322 * @param array $response
323 *
324 * @since 2.8.3
325 */
326 public function show_upgrade_notice( $plugin_file, $response ) {
327 if ( version_compare( PHP_VERSION, '7.2', '>=' ) ) {
328 return;
329 }
330 $plugin_data = (object) $response;
331 // Preparing for the next major plugin v3.0.0 and subsequent versions.
332 if ( isset( $plugin_data->new_version )
333 && '3' === substr( trim( $plugin_data->new_version ), 0, 1 )
334 && version_compare( DEFENDER_VERSION, '3', '<' )
335 ){
336 // Major plugin version or subsequent versions.
337 $new_version = ( '3' === $plugin_data->new_version ) ? '3.0.0' : $plugin_data->new_version;
338 // Collect notice.
339 $notice = '<p>' . esc_html__( 'There is a new version of Defender available - Deprecating PHP version 7.1. and lower.', 'wpdef' ) . '</p>';
340 $notice .= '<span style="display: inherit;background: #D63638;color: #FFFFFF;margin-top: 12px;padding: 10px 12px;border-radius: 2px;">';
341 $notice .= '<strong>';
342 $notice .= esc_html__( 'Important Upgrade Notice:', 'wpdef' );
343 $notice .= '</strong> ';
344 $notice .= sprintf(
345 /* translators: %s: Version number. */
346 esc_html__( 'The upcoming version %s is compatible only with PHP 7.2.0 and higher. Please make sure to upgrade your PHP version.', 'wpdef' ),
347 $new_version
348 );
349 $notice .= '</span>';
350
351 echo "<script type='text/javascript'>
352 (function ($) {
353 $(document).ready(function () {
354 $( '.wp-list-table tr[data-plugin=\"" . esc_attr( $plugin_data->plugin ) . "\"] .notice-warning' ).html( '" . addslashes( $notice ) . "' ).css('padding-bottom', '10px');
355 });
356 })(jQuery);
357 </script>";
358 }
359 }
360 }
361