PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.9.0
Defender Security – Malware Scanner, Login Security & Firewall v5.9.0
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 / controller / class-hub-connector.php

class-hub-connector.php in Defender Security – Malware Scanner, Login Security & Firewall 5.9.0, at src/controller/class-hub-connector.php

153 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handles Hub Connector feature.
4 *
5 * @package WP_Defender\Controller
6 */
7
8 namespace WP_Defender\Controller;
9
10 use Calotes\Component\Response;
11 use WP_Defender\Controller;
12 use WP_Defender\Component\Hub_Connector as Hub_Connector_Component;
13 use WP_Defender\Traits\Defender_Dashboard_Client;
14
15 /**
16 * Handles Hub Connector feature.
17 */
18 class Hub_Connector extends Controller {
19 use Defender_Dashboard_Client;
20
21 public const TRANSIENT_KEY = 'wpdef_maybe_hub_connection_attempt';
22
23 /**
24 * Service for handling logic.
25 *
26 * @var Hub_Connector_Component
27 */
28 public $service;
29
30 /**
31 * Constructor for the Hub_Connector class.
32 *
33 * @param Hub_Connector_Component $service The service object.
34 */
35 public function __construct( Hub_Connector_Component $service ) {
36 $this->service = $service;
37 $this->register_routes();
38
39 add_action( 'admin_init', array( $this, 'maybe_hcm_connection_attempt' ) );
40 }
41
42 /**
43 * Maybe member is trying to connect via Hub Connection Module.
44 */
45 public function maybe_hcm_connection_attempt() {
46 $module_slug = defender_get_data_from_request( 'module_slug', 'g' );
47 $is_callback = defender_get_data_from_request( 'hub_connector_callback', 'g' );
48
49 if ( is_string( $module_slug ) && '' !== $module_slug && is_string( $is_callback ) && '' !== $is_callback ) {
50 set_site_transient(
51 self::TRANSIENT_KEY,
52 array(
53 'module_slug' => $module_slug,
54 ),
55 MINUTE_IN_SECONDS
56 );
57 }
58 }
59
60 /**
61 * Activate Dashboard plugin.
62 *
63 * @return Response
64 * @defender_route
65 */
66 public function activate_dashboard_plugin(): Response {
67 $plugin_path = 'wpmudev-updates/update-notifications.php';
68 $result = activate_plugin( $plugin_path );
69 if ( is_wp_error( $result ) ) {
70 return new Response(
71 false,
72 array(
73 'message' => $result->get_error_message(),
74 )
75 );
76 }
77
78 return new Response(
79 true,
80 array(
81 'message' => esc_html__( 'Dashboard plugin has been activated. You should be redirected to sign-in page shortly.', 'defender-security' ),
82 'redirect' => $this->service->get_url(),
83 )
84 );
85 }
86
87 /**
88 * Provides data for the frontend.
89 *
90 * @return array An array of data for the frontend.
91 */
92 public function data_frontend(): array {
93 return array_merge(
94 array(
95 'button_label' => $this->service->get_button_label(),
96 'is_dash_installed' => $this->is_dash_installed(),
97 'is_dash_activated' => $this->is_dash_activated(),
98 'is_hub_connected' => $this->is_site_connected_to_hub_via_hcm_or_dash(),
99 'hub_connector_url' => array(
100 'default' => $this->service->get_url(),
101 'global-ip' => $this->service->get_url( 'wdf-ip-lockout', 'global-ip' ),
102 'blocklist' => $this->service->get_url( 'wdf-ip-lockout', 'blocklist' ),
103 'onboard' => $this->service->get_url( 'wp-defender', 'onboard' ),
104 'dashboard' => $this->service->get_url( 'wp-defender', 'dashboard' ),
105 'setting' => $this->service->get_url( 'wdf-setting', 'general' ),
106 // Custom one if a trigger is the Summary section.
107 'summary-box' => $this->service->get_url( 'wdf-ip-lockout', 'summary-box' ),
108 // Custom one for Antibot notice shown on all Defender pages.
109 'antibot-notice' => $this->service->get_url( 'wdf-ip-lockout', '', 'def_antibot_survey_notice', 'hub_connector' ),
110 ),
111 ),
112 $this->dump_routes_and_nonces()
113 );
114 }
115
116 /**
117 * Export to array
118 *
119 * @return array
120 */
121 public function to_array() {
122 return array();
123 }
124
125 /**
126 * Import data
127 *
128 * @param array $data The data to import.
129 */
130 public function import_data( $data ) {}
131
132 /**
133 * Export strings
134 *
135 * @return array
136 */
137 public function export_strings() {
138 return array();
139 }
140
141 /**
142 * Removes settings.
143 */
144 public function remove_settings() {
145 }
146
147 /**
148 * Delete all the data & the cache.
149 */
150 public function remove_data() {
151 }
152 }
153