registry = $registry; $this->wc_admin = new AdminController( $registry ); $this->edd_admin = new EddAdminController( $registry ); } /** * Render the integrations page. * * @since 1.1.0 * * @return void */ public function render(): void { $this->render_page(); } /** * Handle the AJAX save_integration_settings request. * * Dispatches to the appropriate save routine based on the `type` parameter: * - `enabled`: toggles an integration on or off. * - `comments`: saves WP Comments-specific settings. * - `woocommerce`: saves WooCommerce Reviews + Registration settings via AdminController. * - `memberpress`: saves MemberPress paid-signup gating opt-in. * - `forms`: saves per-form protection toggles for a form provider. * * @since 1.1.0 * @since 1.2.0 Added `woocommerce` type dispatched to the WooCommerce AdminController. * @since 1.4.1 Added `memberpress` type. * @since 1.5.0 Added `edd` type dispatched to the EDD AdminController. * * @return void */ public function ajax_save_settings(): void { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh, Generic.Metrics.CyclomaticComplexity.MaxExceeded // Verify nonce. check_ajax_referer( 'activelayer_integration_settings', 'nonce' ); // Check capability. if ( ! current_user_can( 'manage_activelayer' ) ) { wp_send_json_error( [ 'message' => esc_html__( 'Permission denied.', 'activelayer-anti-spam-spam-protection-for-forms-comments' ) ], 403 ); return; } // Sanitize type and slug from POST. $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : ''; $slug = isset( $_POST['slug'] ) ? sanitize_text_field( wp_unslash( $_POST['slug'] ) ) : ''; switch ( $type ) { case 'enabled': $this->handle_enabled_toggle( $slug ); break; case 'comments': $this->handle_comments_settings( $slug ); break; case 'woocommerce': $this->wc_admin->handle_settings_save( $slug ); break; case 'edd': $this->edd_admin->handle_settings_save( $slug ); break; case 'memberpress': $this->handle_memberpress_settings( $slug ); break; case 'forms': $this->handle_forms_settings( $slug ); break; default: wp_send_json_error( [ 'message' => esc_html__( 'Invalid type.', 'activelayer-anti-spam-spam-protection-for-forms-comments' ) ], 400 ); return; } } /** * Render the integrations admin page HTML. * * Lists all registered integrations with enable toggles, status badges, * and inline expand/collapse settings panels. * * @since 1.1.0 * * @return void */ private function render_page(): void { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh $integrations_status = $this->registry->get_status(); $integrations = $integrations_status['integrations'] ?? []; $has_api_key = SettingsHelper::has_api_key(); // Filter and sort integrations for display. $display_integrations = $this->filter_installed_integrations( $integrations ); // Add WPForms promotion row when plugin is not installed. if ( ! isset( $display_integrations['wpforms'] ) && current_user_can( 'install_plugins' ) ) { $display_integrations['wpforms_promo'] = [ 'name' => 'WPForms', 'slug' => 'wpforms_promo', 'plugin_active' => false, 'enabled' => false, 'is_promo' => true, ]; } $display_integrations = $this->sort_integrations_for_display( $display_integrations ); ?>