[ $this, 'setup_protection' ], 'is_completed' => [ $this, 'is_protection_completed' ], ], ]; } /** * Render protection setup wizard step. * * Forminator wizard serializes `
'; return [ 'html' => $html, 'redirect' => false, 'has_errors' => false, 'is_close' => ( $is_submit && empty( $error_message ) ), 'buttons' => $buttons, 'notification' => $notification, ]; } /** * Persist the wizard "Activate" submission and return the success notification. * * @since 1.3.0 * * @param int $form_id Form (module) identifier. * * @return array Notification payload for the wizard. */ private function handle_activate_submit( int $form_id ): array { $this->addon_settings['connected'] = true; $this->save_module_settings_values(); $admin_settings = new AdminSettings(); $admin_settings->save_form_protection( $form_id, true ); return [ 'type' => 'success', 'text' => '' . esc_html__( 'ActiveLayer', 'activelayer-anti-spam-spam-protection-for-forms-comments' ) . ' ' . esc_html__( 'spam protection is now active for this form.', 'activelayer-anti-spam-spam-protection-for-forms-comments' ), ]; } /** * Resolve the wizard connection state, falling back to the backend default. * * Prevents the wizard UI from showing "Activate" while the backend already protects. * * @since 1.3.0 * * @param int $form_id Form (module) identifier. * * @return bool */ private function resolve_is_connected( int $form_id ): bool { if ( is_array( $this->addon_settings ) && array_key_exists( 'connected', $this->addon_settings ) ) { return ! empty( $this->addon_settings['connected'] ); } $admin_settings = new AdminSettings(); $form_settings = $admin_settings->get_form_settings( $form_id ); return ! empty( $form_settings['enabled'] ); } /** * Check if protection is completed (connected). * * @since 1.1.0 * @since 1.3.0 Falls back to backend opt-out default via resolve_is_connected() when no wizard state stored. * * @param array $submitted_data Submitted data. * * @return bool */ public function is_protection_completed( $submitted_data = [] ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found $this->addon_settings = $this->get_settings_values(); return $this->resolve_is_connected( (int) $this->module_id ); } /** * Disconnect form from ActiveLayer (disable protection). * * Called by Forminator when user clicks "Deactivate". * * @since 1.1.0 * * @param array $submitted_data Submitted data. */ public function disconnect_module( $submitted_data = [] ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found $form_id = (int) $this->module_id; // Clear Forminator's internal addon settings. $this->addon_settings = []; $this->save_module_settings_values(); // Mirror to ActiveLayer option. $admin_settings = new AdminSettings(); $admin_settings->save_form_protection( $form_id, false ); } }