_description = esc_html__( 'AI-powered spam protection for your forms.', 'activelayer-anti-spam-spam-protection-for-forms-comments' ); } /** * Get addon icon URL. * * @since 1.1.0 * * @return string */ public function get_icon() { return plugin_dir_url( ACTIVELAYER_PLUGIN_FILE ) . 'assets/images/logo-icon.png'; } /** * Get retina icon URL. * * @since 1.1.0 * * @return string */ public function get_icon_x2() { return $this->get_icon(); } /** * Get addon banner URL. * * @since 1.1.0 * * @return string */ public function get_image() { return plugin_dir_url( ACTIVELAYER_PLUGIN_FILE ) . 'assets/images/logo-icon.png'; } /** * Get retina banner URL. * * @since 1.1.0 * * @return string */ public function get_image_x2() { return $this->get_image(); } /** * Global settings wizard. * * Shows connection status based on whether API key is configured. * * @since 1.1.0 * * @return array */ public function settings_wizards() { return [ [ 'callback' => [ $this, 'setup_connect' ], 'is_completed' => [ $this, 'is_connected' ], ], ]; } /** * Setup connect wizard step. * * @since 1.1.0 * * @param array $submitted_data Submitted data. * @param int $form_id Form ID. * * @return array */ public function setup_connect( $submitted_data, $form_id = 0 ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found $is_connected = $this->is_connected(); $is_submit = ! empty( $submitted_data ); $has_errors = false; $buttons = []; $notification = []; if ( $is_submit && ! empty( $submitted_data['connect'] ) ) { if ( ! $is_connected ) { $has_errors = true; } else { if ( ! forminator_addon_is_active( $this->_slug ) ) { Forminator_Integration_Loader::get_instance()->activate_addon( $this->_slug ); } $notification = [ 'type' => 'success', 'text' => '' . esc_html( $this->get_title() ) . ' ' . esc_html__( 'is connected successfully.', 'activelayer-anti-spam-spam-protection-for-forms-comments' ), ]; } } if ( $is_connected ) { $connect_html = '
' . '

' . esc_html__( 'ActiveLayer is connected', 'activelayer-anti-spam-spam-protection-for-forms-comments' ) . '

' . '

' . esc_html__( 'AI spam protection is ready. Enable it per form in the Integrations tab.', 'activelayer-anti-spam-spam-protection-for-forms-comments' ) . '

' . '
'; $buttons['next']['markup'] = '
' . '' . Forminator_Integration::get_button_markup( esc_html__( 'Activate', 'activelayer-anti-spam-spam-protection-for-forms-comments' ), 'sui-button-primary forminator-addon-finish' ) . '
'; } else { $settings_url = admin_url( 'admin.php?page=activelayer-settings' ); $connect_html = '
' . '

' . esc_html__( 'Connect ActiveLayer', 'activelayer-anti-spam-spam-protection-for-forms-comments' ) . '

' . '

' . sprintf( /* translators: %1$s opening a tag, %2$s closing a tag. */ esc_html__( 'Please configure your API key in %1$sActiveLayer Settings%2$s first.', 'activelayer-anti-spam-spam-protection-for-forms-comments' ), '', '' ) . '

' . '
'; } return [ 'html' => $connect_html, 'redirect' => false, 'has_errors' => $has_errors, 'buttons' => $buttons, 'notification' => $notification, ]; } /** * Check if addon is globally connected (API key configured). * * @since 1.1.0 * * @return bool */ public function is_connected() { return SettingsHelper::has_api_key(); } /** * Check if addon is authorized. * * @since 1.1.0 * * @return bool */ public function is_authorized() { return $this->is_connected(); } /** * Check if addon is connected to a specific form. * * @since 1.1.0 * * @param int $module_id Form ID. * @param string $module_slug Module type. * @param bool $check_lead Check lead connection. * * @return bool */ public function is_module_connected( $module_id, $module_slug = 'form', $check_lead = false ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed if ( ! $this->is_connected() ) { return false; } $settings = $this->get_activelayer_form_settings( (int) $module_id ); return ! empty( $settings['enabled'] ); } /** * Get ActiveLayer form settings via our AdminSettings. * * @since 1.1.0 * @since 1.3.0 Delegate to AdminSettings so Forminator-native UI reflects the opt-out default. * * @param int $form_id Form ID. * * @return array */ private function get_activelayer_form_settings( int $form_id ): array { return ( new AdminSettings() )->get_form_settings( $form_id ); } }