| @@ -12,9 +12,8 @@ | ||
| 12 | 12 | use Calotes\Component\Request; |
| 13 | 13 | use Calotes\Component\Response; |
| 14 | 14 | use WP_Defender\Component\Session_Protection as Service; |
| 15 | 15 | use WP_Defender\Model\Setting\Session_Protection as Settings; |
| 16 | -use WP_Defender\Component\Breadcrumbs; | |
| 17 | 16 | |
| 18 | 17 | /** |
| 19 | 18 | * Handle session protection module. |
| 20 | 19 | */ |
| @@ -40,9 +39,8 @@ | ||
| 40 | 39 | */ |
| 41 | 40 | public function __construct() { |
| 42 | 41 | $this->model = wd_di()->get( Settings::class ); |
| 43 | 42 | $this->service = wd_di()->get( Service::class ); |
| 44 | - add_filter( 'wp_defender_advanced_tools_data', array( $this, 'script_data' ) ); | |
| 45 | 43 | $this->register_routes(); |
| 46 | 44 | if ( $this->model->enabled ) { |
| 47 | 45 | add_action( 'init', array( $this->service, 'handle_session_timeout' ) ); |
| 48 | 46 | add_action( 'wp_enqueue_scripts', array( $this->service, 'enqueue_idle_scripts' ) ); |
| @@ -61,34 +59,18 @@ | ||
| 61 | 59 | } |
| 62 | 60 | } |
| 63 | 61 | |
| 64 | 62 | /** |
| 65 | - * Provide data to the frontend via localized script. | |
| 66 | - * | |
| 67 | - * @param array $data Data collection is ready to passed. | |
| 68 | - * | |
| 69 | - * @return array Modified data array with added this controller data. | |
| 70 | - */ | |
| 71 | - public function script_data( array $data ): array { | |
| 72 | - $data['session_protection'] = $this->data_frontend(); | |
| 73 | - | |
| 74 | - return $data; | |
| 75 | - } | |
| 76 | - | |
| 77 | - /** | |
| 78 | 63 | * All the variables that we will show on frontend, both in the main page, or dashboard widget. |
| 79 | 64 | * |
| 80 | 65 | * @return array |
| 81 | 66 | */ |
| 82 | 67 | public function data_frontend(): array { |
| 83 | - $is_visited = wd_di()->get( Breadcrumbs::class )->get_meta_key(); | |
| 84 | - | |
| 85 | 68 | return array_merge( |
| 86 | 69 | array( |
| 87 | - 'model' => $this->model->export(), | |
| 88 | - 'properties' => $this->service::session_lock_properties(), | |
| 89 | - 'show_feature_dot' => wd_di()->get( \WP_Defender\Behavior\WPMUDEV::class )->is_pro() && ! $is_visited, | |
| 90 | - 'roles' => $this->get_all_editable_roles(), | |
| 70 | + 'model' => $this->model->export(), | |
| 71 | + 'properties' => $this->service::session_lock_properties(), | |
| 72 | + 'roles' => $this->get_all_editable_roles(), | |
| 91 | 73 | ), |
| 92 | 74 | $this->dump_routes_and_nonces() |
| 93 | 75 | ); |
| 94 | 76 | } |
| @@ -110,12 +92,12 @@ | ||
| 110 | 92 | // Changes for Hub. |
| 111 | 93 | \WP_Defender\Component\Config\Config_Hub_Helper::set_clear_active_flag(); |
| 112 | 94 | |
| 113 | 95 | // Maybe track if any settings have changed except user roles. |
| 114 | - if ( $this->maybe_track() && ! empty( $prev_data ) && | |
| 96 | + if ( $this->maybe_track() && array() !== $prev_data && | |
| 115 | 97 | ( |
| 116 | 98 | ( $this->model->enabled !== $prev_data['enabled'] ) |
| 117 | - || ! empty( array_diff( $this->model->lock_properties, $prev_data['lock_properties'] ) ) | |
| 99 | + || array() !== array_diff( $this->model->lock_properties, $prev_data['lock_properties'] ) | |
| 118 | 100 | || $this->model->idle_timeout !== $prev_data['idle_timeout'] |
| 119 | 101 | ) |
| 120 | 102 | ) { |
| 121 | 103 | $data = array( |
| @@ -164,10 +146,8 @@ | ||
| 164 | 146 | /** |
| 165 | 147 | * Import the data of other source into this, it can be when HUB trigger the import, or user apply a preset. |
| 166 | 148 | * |
| 167 | 149 | * @param array $data Data from other source. |
| 168 | - * | |
| 169 | - * @return null|void | |
| 170 | 150 | */ |
| 171 | 151 | public function import_data( array $data ) { |
| 172 | 152 | $this->model->import( $data ); |
| 173 | 153 | if ( $this->model->validate() ) { |
| @@ -172,16 +152,13 @@ | ||
| 172 | 152 | $this->model->import( $data ); |
| 173 | 153 | if ( $this->model->validate() ) { |
| 174 | 154 | $this->model->save(); |
| 175 | 155 | $this->service->update_last_activity(); |
| 176 | - return; | |
| 177 | 156 | } |
| 178 | 157 | } |
| 179 | 158 | |
| 180 | 159 | /** |
| 181 | 160 | * Remove all settings, configs generated in this container runtime. |
| 182 | - * | |
| 183 | - * @return mixed | |
| 184 | 161 | */ |
| 185 | 162 | public function remove_settings() { |
| 186 | 163 | } |
| 187 | 164 | |
| @@ -188,9 +165,8 @@ | ||
| 188 | 165 | /** |
| 189 | 166 | * Remove all data. |
| 190 | 167 | */ |
| 191 | 168 | public function remove_data() { |
| 192 | - wd_di()->get( Breadcrumbs::class )->delete_meta_key(); | |
| 193 | 169 | delete_site_transient( Service::LOGOUT_MSG_TRANSIENT_KEY ); |
| 194 | 170 | } |
| 195 | 171 | |
| 196 | 172 | /** |
| @@ -201,15 +177,6 @@ | ||
| 201 | 177 | public function export_strings() { |
| 202 | 178 | return array( |
| 203 | 179 | $this->model->is_active() ? esc_html__( 'Active', 'defender-security' ) : esc_html__( 'Inactive', 'defender-security' ), |
| 204 | 180 | ); |
| 205 | - } | |
| 206 | - | |
| 207 | - /** | |
| 208 | - * Provides data for the dashboard widget. | |
| 209 | - * | |
| 210 | - * @return array An array of dashboard widget data. | |
| 211 | - */ | |
| 212 | - public function dashboard_widget(): array { | |
| 213 | - return array( 'model' => $this->model->export() ); | |
| 214 | 181 | } |
| 215 | 182 | } |