PluginProbe
SMTP for Contact Form 7 / 1.1.2
SMTP for Contact Form 7 v1.1.2
1.1.2 trunk 0.0.1 1.0.0 1.1.0 1.1.1
cf7-smtp / cf7-smtp.php

cf7-smtp.php in SMTP for Contact Form 7 1.1.2, at cf7-smtp.php

171 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * SMTP for Contact From 7
4 * A trustworthy SMTP plugin for Contact Form 7. Simple and useful.
5 *
6 * Plugin Name: SMTP for Contact Form 7
7 * Plugin URI: https://wordpress.org/plugins/cf7-smtp
8 * Description: A trustworthy SMTP plugin for Contact Form 7. Simple and useful.
9 * Version: 1.1.2
10 * Author: codekraft
11 * Contributors: gardenboi, MemoryShadow
12 * Author URI: https://modul-r.codekraft.it/
13 * Text Domain: cf7-smtp
14 * License: GPL 2.0+
15 * License URI: http://www.gnu.org/licenses/gpl-3.0.txt
16 * Text Domain: cf7-smtp
17 * Domain Path: /languages
18 * Requires PHP: 7.4
19 * Requires Plugins: contact-form-7
20 *
21 * @package cf7_smtp
22 * @author Erik Golinelli <erik@codekraft.it>
23 * @copyright 2022 Erik
24 * @license GPL 2.0+
25 * @link https://modul-r.codekraft.it/
26 */
27
28 // If this file is called directly, abort.
29 if ( ! defined( 'ABSPATH' ) ) {
30 die( 'We\'re sorry, but you can not directly access this file.' );
31 }
32
33 define( 'CF7_SMTP_NAME', 'Contact Form 7 - SMTP' );
34 define( 'CF7_SMTP_MIN_PHP_VERSION', '7.4' );
35 define( 'CF7_SMTP_VERSION', '1.1.2' );
36
37 define( 'CF7_SMTP_PLUGIN_ROOT', plugin_dir_path( __FILE__ ) );
38 define( 'CF7_SMTP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
39
40 /**
41 * Define the constants for the plugin
42 */
43 if ( ! defined( 'CF7_SMTP_USER_NAME' ) ) {
44 define( 'CF7_SMTP_USER_NAME', null );
45 }
46 if ( ! defined( 'CF7_SMTP_USER_PASS' ) ) {
47 define( 'CF7_SMTP_USER_PASS', null );
48 }
49 if ( ! defined( 'CF7_SMTP_OAUTH2_CLIENT_ID' ) ) {
50 define( 'CF7_SMTP_OAUTH2_CLIENT_ID', null );
51 }
52 if ( ! defined( 'CF7_SMTP_OAUTH2_CLIENT_SECRET' ) ) {
53 define( 'CF7_SMTP_OAUTH2_CLIENT_SECRET', null );
54 }
55
56 /**
57 * Define the settings as array for easier management
58 */
59 if ( ! defined( 'CF7_SMTP_SETTINGS' ) ) {
60 define(
61 'CF7_SMTP_SETTINGS',
62 array(
63 'user_name' => CF7_SMTP_USER_NAME,
64 'user_pass' => CF7_SMTP_USER_PASS,
65 'oauth2_client_id' => CF7_SMTP_OAUTH2_CLIENT_ID,
66 'oauth2_client_secret' => CF7_SMTP_OAUTH2_CLIENT_SECRET,
67 )
68 );
69 }
70
71 /**
72 * Check if the PHP version is supported and show an error if not
73 */
74 if ( version_compare( PHP_VERSION, CF7_SMTP_MIN_PHP_VERSION, '<=' ) ) {
75 add_action(
76 'admin_init',
77 static function () {
78 deactivate_plugins( plugin_basename( __FILE__ ) );
79 }
80 );
81 add_action(
82 'admin_notices',
83 static function () {
84 echo wp_kses_post(
85 sprintf(
86 '<div class="notice notice-error"><p>%s</p></div>',
87 esc_html__( 'SMTP for Contact Form 7 requires PHP 7.1 or newer.', 'cf7-smtp' )
88 )
89 );
90 }
91 );
92
93 // Return early to prevent loading the plugin.
94 return;
95 }//end if
96
97 // Load Composer Autoloader and Functions once
98 $cf7_smtp_libraries = require_once CF7_SMTP_PLUGIN_ROOT . 'vendor/autoload.php';
99 require_once CF7_SMTP_PLUGIN_ROOT . 'functions/functions.php';
100
101 /**
102 * If the plugin is not being installed then
103 * register the activation and deactivation hooks
104 * and load the plugin
105 */
106 if ( ! wp_installing() ) {
107
108 /* It's a hook that is called when the plugin is activated or deactivated. */
109 register_activation_hook( __FILE__, array( new \cf7_smtp\Backend\ActDeact(), 'activate' ) );
110 register_deactivation_hook( __FILE__, array( new \cf7_smtp\Backend\ActDeact(), 'deactivate' ) );
111
112 /* Initialize the plugin once all plugins are loaded. */
113 add_action(
114 'plugins_loaded',
115 static function () {
116 /**
117 * Run the migration safely once WP is ready.
118 * This handles the case where the plugin was updated via WordPress auto-update
119 * (which does NOT fire the activation hook) so new option keys are added
120 * automatically on the very next request after an update.
121 */
122 \cf7_smtp\Backend\ActDeact::maybe_upgrade();
123 }
124 );
125
126 /* Initialize the Engine after ensuring CF7 is present */
127 add_action(
128 'init',
129 static function () use ( $cf7_smtp_libraries ) {
130 // Bail if Contact Form 7 isn't active.
131 if ( ! class_exists( 'WPCF7_Service' ) ) {
132 return;
133 }
134
135 // Initialize the Engine.
136 try {
137 new \cf7_smtp\Engine\Initialize( $cf7_smtp_libraries );
138 } catch ( Exception $e ) {
139 return;
140 }
141
142 $file = path_join( CF7_SMTP_PLUGIN_ROOT, 'integration/integration.php' );
143
144 if ( file_exists( $file ) ) {
145 include_once $file;
146 }
147 },
148 11
149 );
150 }//end if
151
152 /**
153 * Call the integration action to mount our plugin as a component
154 * into the intefration page
155 */
156 add_action( 'wpcf7_init', 'cf7_smtp_register_service', 1, 0 );
157
158 /**
159 * Register the SMTP service with Contact Form 7
160 *
161 * @return void
162 */
163 function cf7_smtp_register_service() {
164 $integration = WPCF7_Integration::get_instance();
165 $integration->add_category( 'email_services', 'Email Services' );
166 $integration->add_service(
167 'cf7-smtp',
168 cf7_smtp\Integration\Service::get_instance()
169 );
170 }
171