PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.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
← All changes | src/controller/class-two-factor.php +35 -43 5.8.0 → 6.3.0 View file →
@@ -99,15 +99,8 @@
99 99 /**
100 100 * Initializes the model and service, registers routes, and sets up scheduled events if the model is active.
101 101 */
102 102 public function __construct() {
103 - $this->register_page(
104 - esc_html__( '2FA', 'defender-security' ),
105 - $this->slug,
106 - array( $this, 'main_view' ),
107 - $this->parent_slug
108 - );
109 - add_action( 'defender_enqueue_assets', array( $this, 'enqueue_assets' ) );
110 103 $this->register_routes();
111 104 $this->service = wd_di()->get( Two_Fa_Component::class );
112 105 $this->model = wd_di()->get( Two_Fa::class );
113 106 $this->password_protection_service = wd_di()->get( Password_Protection_Service::class );
@@ -118,9 +111,9 @@
118 111 if ( $this->model->is_active() ) {
119 112 require_once ABSPATH . 'wp-admin/includes/plugin.php';
120 113 $is_jetpack_sso = $this->service->is_jetpack_sso();
121 114 $is_tml = $this->service->is_tml();
122 - add_action( 'admin_init', array( $this->service, 'get_providers' ) );
115 + add_action( 'admin_init', array( $this, 'load_providers' ) );
123 116 add_action( 'pre_get_users', array( $this, 'filter_users_by_2fa' ) );
124 117 add_action( 'show_user_profile', array( $this, 'show_user_profile' ) );
125 118 add_action( 'profile_update', array( $this, 'profile_update' ) );
126 119
@@ -180,8 +173,17 @@
180 173 }
181 174 }
182 175
183 176 /**
177 + * Loads the available service providers.
178 + *
179 + * @return void
180 + */
181 + public function load_providers(): void {
182 + $this->service->get_providers();
183 + }
184 +
185 + /**
184 186 * Checks if WooCommerce integration is enabled.
185 187 *
186 188 * @return bool Whether WooCommerce integration is enabled.
187 189 */
@@ -336,8 +338,9 @@
336 338 } elseif ( $this->password_protection_service->is_force_reset( $user ) ) {
337 339 $this->password_protection_service->do_force_reset( $user, $password );
338 340 } else {
339 341 $user_id = $user->ID;
342 + // For the Webauthn method, the check occurs inside Webauthn_Controller::verify_response().
340 343 // Set active user.
341 344 wp_set_current_user( $user_id, $user->user_login );
342 345 // Todo: add code for 'rememberme'-option.
343 346 wp_set_auth_cookie( $user_id, true );
@@ -462,14 +465,15 @@
462 465 $params['error'] = null;
463 466 }
464 467
465 468 $this->attach_behavior( WPMUDEV::class, WPMUDEV::class );
466 - $custom_graphic = '';
467 - $custom_graphic_type = '';
468 - $custom_graphic_url = trim( $this->model->custom_graphic_url );
469 - $custom_graphic_link = trim( $this->model->custom_graphic_link );
470 - if ( $this->is_pro() && $this->model->custom_graphic ) {
471 - $custom_graphic_type = $this->model->custom_graphic_type;
469 + $params['custom_graphic'] = '';
470 + $params['custom_graphic_type'] = $this->model->custom_graphic_type;
471 + $custom_graphic = '';
472 + $custom_graphic_type = $this->model->custom_graphic_type;
473 + $custom_graphic_url = trim( $this->model->custom_graphic_url );
474 + $custom_graphic_link = trim( $this->model->custom_graphic_link );
475 + if ( $this->model->custom_graphic ) {
472 476 if ( Two_Fa::CUSTOM_GRAPHIC_TYPE_UPLOAD === $custom_graphic_type && '' !== $custom_graphic_url ) {
473 477 $custom_graphic = $custom_graphic_url;
474 478 } elseif ( Two_Fa::CUSTOM_GRAPHIC_TYPE_LINK === $custom_graphic_type && '' !== $custom_graphic_link ) {
475 479 $custom_graphic = $custom_graphic_link;
@@ -837,8 +841,9 @@
837 841 plugins_url( 'assets/js/webauthn.js', WP_DEFENDER_FILE ),
838 842 array(
839 843 'jquery',
840 844 'wpdef_webauthn_common_script',
845 + 'wp-i18n',
841 846 ),
842 847 DEFENDER_VERSION,
843 848 true
844 849 );
@@ -894,13 +899,24 @@
894 899 * @return Response
895 900 * @defender_route
896 901 */
897 902 public function save_settings( Request $request ): Response {
898 - $model = $this->model;
899 - $data = $request->get_data();
903 + $model = $this->model;
904 + $data = $request->get_data();
905 + $old_detect_woo = $model->detect_woo;
906 +
900 907 $model->import( $data );
901 908 if ( $model->validate() ) {
902 909 $model->save();
910 +
911 + if ( $old_detect_woo !== $model->detect_woo ) {
912 + if ( $model->detect_woo ) {
913 + $this->wp_defender_2fa_endpoint();
914 + }
915 +
916 + flush_rewrite_rules();
917 + }
918 +
903 919 Config_Hub_Helper::set_clear_active_flag();
904 920
905 921 return new Response(
906 922 true,
@@ -920,23 +936,8 @@
920 936 );
921 937 }
922 938
923 939 /**
924 - * Enqueues scripts and styles for this page.
925 - * Only enqueues assets if the page is active.
926 - */
927 - public function enqueue_assets() {
928 - if ( ! $this->is_page_active() ) {
929 - return;
930 - }
931 - wp_enqueue_script( 'clipboard' );
932 - wp_enqueue_media();
933 - wp_localize_script( 'def-2fa', 'two_fa', $this->data_frontend() );
934 - wp_enqueue_script( 'def-2fa' );
935 - $this->enqueue_main_assets();
936 - }
937 -
938 - /**
939 940 * Send test email, use in settings screen.
940 941 *
941 942 * @param Request $request Request object.
942 943 *
@@ -1037,15 +1038,8 @@
1037 1038 );
1038 1039 }
1039 1040
1040 1041 /**
1041 - * Renders the main view.
1042 - */
1043 - public function main_view(): void {
1044 - $this->render( 'main' );
1045 - }
1046 -
1047 - /**
1048 1042 * Removes settings for all submodules.
1049 1043 */
1050 1044 public function remove_settings(): void {
1051 1045 ( new Two_Fa() )->delete();
@@ -1133,8 +1127,9 @@
1133 1127 public function data_frontend(): array {
1134 1128 return array_merge(
1135 1129 array(
1136 1130 'model' => $this->model->export(),
1131 + 'defaults' => $this->model->get_default_values(),
1137 1132 'all_roles' => $this->get_all_editable_roles(),
1138 1133 'count' => $this->service->count_users_with_enabled_2fa(),
1139 1134 'notices' => $this->compatibility_notices,
1140 1135 'count_checked_roles' => count( $this->model->user_roles ),
@@ -1182,17 +1177,15 @@
1182 1177 );
1183 1178 }
1184 1179
1185 1180 /**
1186 - * Generates configuration strings based on the provided configuration and
1187 - * whether the product is a pro version.
1181 + * Generates configuration strings based on the provided configuration.
1188 1182 *
1189 1183 * @param array $config Configuration data.
1190 - * @param bool $is_pro Indicates if the product is a pro version.
1191 1184 *
1192 1185 * @return array Returns an array of configuration strings.
1193 1186 */
1194 - public function config_strings( array $config, bool $is_pro ): array {
1187 + public function config_strings( array $config ): array {
1195 1188 return array(
1196 1189 $config['enabled'] ? esc_html__( 'Active', 'defender-security' ) : esc_html__( 'Inactive', 'defender-security' ),
1197 1190 );
1198 1191 }
@@ -1360,9 +1353,8 @@
1360 1353 * @return void
1361 1354 */
1362 1355 public function wp_defender_2fa_endpoint(): void {
1363 1356 add_rewrite_endpoint( $this->slug, EP_PERMALINK | EP_PAGES );
1364 - flush_rewrite_rules();
1365 1357 }
1366 1358
1367 1359 /**
1368 1360 * 2. dds the slug of the current instance to the given array of query variables.