PluginProbe
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification / trunk
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification vtrunk
5.7.0 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 All 39 releases
double-opt-in / src / Providers / IntegrationServiceProvider.php

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

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