PluginProbe
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification / 5.6.3
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification v5.6.3
5.6.2 5.6.3 5.6.1 5.6.0 5.5.0 5.4.0 5.3.2 5.3.1 5.1.6 5.1.5 trunk 2.1.5 2.11 2.12 2.13 2.15 3.0.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.51 3.0.60 3.0.61 3.0.62 All 38 releases
double-opt-in / src / Providers / IntegrationServiceProvider.php

IntegrationServiceProvider.php in Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification 5.6.3, at src/Providers/IntegrationServiceProvider.php

170 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Integration Service Provider
4 *
5 * @package Forge12\DoubleOptIn\Providers
6 * @since 4.0.0
7 */
8
9 namespace Forge12\DoubleOptIn\Providers;
10
11 use Forge12\DoubleOptIn\Container\Container;
12 use Forge12\DoubleOptIn\Container\BootableProviderInterface;
13 use Forge12\DoubleOptIn\Integration\FormIntegrationRegistry;
14 use Forge12\DoubleOptIn\Integration\CF7Integration;
15 use Forge12\DoubleOptIn\Integration\CF7FollowUpAdapter;
16 use Forge12\DoubleOptIn\FollowUp\FollowUpAdapterRegistry;
17 use Forge12\DoubleOptIn\Frontend\ErrorNotification;
18 use Forge12\Shared\LoggerInterface;
19
20 if ( ! defined( 'ABSPATH' ) ) {
21 exit;
22 }
23
24 /**
25 * Class IntegrationServiceProvider
26 *
27 * Registers the form integration registry and core integrations.
28 *
29 * NOTE: The new integration system is prepared but NOT active by default.
30 * The legacy classes (CF7Frontend, AvadaFrontend) remain active for backward compatibility.
31 *
32 * To switch to the new system, use the filter:
33 * add_filter( 'f12_cf7_doubleoptin_use_new_integration_system', '__return_true' );
34 *
35 * This will disable the legacy classes and activate the new event-based integrations.
36 */
37 class IntegrationServiceProvider implements BootableProviderInterface {
38
39 /**
40 * {@inheritdoc}
41 */
42 public function register( Container $container ): void {
43 // Register the integration registry as a singleton
44 $container->singleton(
45 FormIntegrationRegistry::class,
46 function () use ( $container ) {
47 $registry = FormIntegrationRegistry::getInstance();
48
49 if ( $container->has( LoggerInterface::class ) ) {
50 $registry->setLogger( $container->get( LoggerInterface::class ) );
51 }
52
53 return $registry;
54 }
55 );
56
57 // Register CF7 Integration
58 $container->singleton(
59 CF7Integration::class,
60 function ( Container $c ) {
61 return new CF7Integration(
62 $c->get( LoggerInterface::class )
63 );
64 }
65 );
66
67 // Avada integration is no longer a Core-bundled feature in the
68 // monorepo era. It lives in the paid `addon-avada` plugin which
69 // registers itself via the AddonRegistry. See Phase 2 execution
70 // plan §7.11 and plan/phase-2-scaffold/packages/core/docs/avada-migration-notice.md
71 // for the customer migration flow.
72 }
73
74 /**
75 * {@inheritdoc}
76 */
77 public function boot( Container $container ): void {
78 /**
79 * Filter to enable the new integration system.
80 *
81 * By default, the new event-based integration system is active.
82 * Set this to false to use the legacy classes for backward compatibility.
83 *
84 * @since 4.0.0
85 *
86 * @param bool $useNewSystem Whether to use the new integration system. Default: true.
87 */
88 $useNewSystem = apply_filters( 'f12_cf7_doubleoptin_use_new_integration_system', true );
89
90 if ( ! $useNewSystem ) {
91 // Legacy system is active - only register the registry for API access
92 // but don't initialize integrations (legacy controllers handle this)
93 if ( $container->has( LoggerInterface::class ) ) {
94 $container->get( LoggerInterface::class )->debug(
95 'New integration system is disabled, legacy classes remain active',
96 array(
97 'plugin' => 'double-opt-in',
98 'component' => 'integration-provider',
99 )
100 );
101 }
102 return;
103 }
104
105 // Register universal error notification system
106 $errorNotification = new ErrorNotification();
107 $errorNotification->register();
108
109 $registry = $container->get( FormIntegrationRegistry::class );
110
111 // Register core integrations
112 $this->registerCoreIntegrations( $container, $registry );
113
114 // Allow other plugins to register integrations
115 do_action( 'f12_cf7_doubleoptin_register_integrations', $registry, $container );
116
117 // Initialize available integrations
118 add_action(
119 'init',
120 function () use ( $registry ) {
121 $registry->initialize();
122 },
123 5
124 );
125
126 if ( $container->has( LoggerInterface::class ) ) {
127 $container->get( LoggerInterface::class )->info(
128 'New integration system is active',
129 array(
130 'plugin' => 'double-opt-in',
131 'component' => 'integration-provider',
132 )
133 );
134 }
135 }
136
137 /**
138 * Register core integrations.
139 *
140 * @param Container $container The DI container.
141 * @param FormIntegrationRegistry $registry The integration registry.
142 *
143 * @return void
144 */
145 private function registerCoreIntegrations( Container $container, FormIntegrationRegistry $registry ): void {
146 // CF7 Integration — the only form integration bundled with Core.
147 // Every other form system (Avada, Elementor, Gravity Forms, WPForms)
148 // ships as a paid addon that registers via the AddonRegistry.
149 try {
150 $cf7Integration = $container->get( CF7Integration::class );
151 $registry->register( $cf7Integration );
152
153 if ( $container->has( FollowUpAdapterRegistry::class ) ) {
154 $container->get( FollowUpAdapterRegistry::class )->register( new CF7FollowUpAdapter( $cf7Integration ) );
155 }
156 } catch ( \Exception $e ) {
157 // Log but don't fail if CF7 integration can't be loaded
158 if ( $container->has( LoggerInterface::class ) ) {
159 $container->get( LoggerInterface::class )->warning(
160 'Failed to register CF7 integration',
161 array(
162 'plugin' => 'double-opt-in',
163 'error' => $e->getMessage(),
164 )
165 );
166 }
167 }
168 }
169 }
170