PluginProbe
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification / 5.5.0
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification v5.5.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 3.0.70 3.0.71 3.0.72 3.1.0 All 34 releases
double-opt-in / src / Providers / IntegrationServiceProvider.php

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

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