-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcf7-propstack-integration.php
More file actions
162 lines (139 loc) · 4.36 KB
/
cf7-propstack-integration.php
File metadata and controls
162 lines (139 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/**
* Plugin Name: Contact Form 7 - Propstack Integration
* Plugin URI: https://github.com/codebypanduro/cf7-propstack-integration
* Description: Integrate Contact Form 7 with Propstack CRM to automatically create contacts from form submissions.
* Version: 1.3.1
* Author: Code by Panduro
* Author URI: https://codebypanduro.dk
* License: GPL v2 or later
* Text Domain: cf7-propstack-integration
* Domain Path: /languages
* Requires at least: 5.0
* Tested up to: 6.4
* Requires PHP: 7.4
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
// Define plugin constants
define('CF7_PROPSTACK_VERSION', '1.3.1');
define('CF7_PROPSTACK_PLUGIN_URL', plugin_dir_url(__FILE__));
define('CF7_PROPSTACK_PLUGIN_PATH', plugin_dir_path(__FILE__));
define('CF7_PROPSTACK_PLUGIN_BASENAME', plugin_basename(__FILE__));
/**
* Main plugin class
*/
class CF7_Propstack_Integration
{
/**
* Constructor
*/
public function __construct()
{
add_action('init', array($this, 'init'));
add_action('plugins_loaded', array($this, 'load_textdomain'));
register_activation_hook(__FILE__, array($this, 'activate'));
register_deactivation_hook(__FILE__, array($this, 'deactivate'));
}
/**
* Initialize the plugin
*/
public function init()
{
// Check if Contact Form 7 is active
if (!$this->is_cf7_active()) {
add_action('admin_notices', array($this, 'cf7_missing_notice'));
return;
}
// Load the API client first
require_once CF7_PROPSTACK_PLUGIN_PATH . 'includes/class-propstack-api.php';
// Load the plugin updater for GitHub releases
require_once CF7_PROPSTACK_PLUGIN_PATH . 'includes/class-plugin-updater.php';
new CF7_Propstack_Plugin_Updater();
// Load admin functionality
if (is_admin()) {
require_once CF7_PROPSTACK_PLUGIN_PATH . 'includes/admin/class-admin.php';
new CF7_Propstack_Admin();
}
// Load the integration handler after CF7 is fully loaded
add_action('wpcf7_init', array($this, 'load_integration_handler'));
}
/**
* Load the integration handler
*/
public function load_integration_handler()
{
require_once CF7_PROPSTACK_PLUGIN_PATH . 'includes/class-integration-handler.php';
new CF7_Propstack_Integration_Handler();
}
/**
* Load plugin textdomain
*/
public function load_textdomain()
{
load_plugin_textdomain('cf7-propstack-integration', false, dirname(plugin_basename(__FILE__)) . '/languages');
}
/**
* Check if Contact Form 7 is active
*/
private function is_cf7_active()
{
return class_exists('WPCF7');
}
/**
* Display notice if Contact Form 7 is not active
*/
public function cf7_missing_notice()
{
?>
<div class="notice notice-error">
<p><?php _e('Contact Form 7 - Propstack Integration requires Contact Form 7 to be installed and activated.', 'cf7-propstack-integration'); ?></p>
</div>
<?php
}
/**
* Plugin activation
*/
public function activate()
{
// Create default options
$default_options = array(
'api_key' => '',
'debug_mode' => false
);
add_option('cf7_propstack_options', $default_options);
// Create database table for field mappings
$this->create_mappings_table();
}
/**
* Plugin deactivation
*/
public function deactivate()
{
// Clean up if needed
}
/**
* Create database table for field mappings
*/
private function create_mappings_table()
{
global $wpdb;
$table_name = $wpdb->prefix . 'cf7_propstack_mappings';
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
form_id varchar(255) NOT NULL,
cf7_field varchar(255) NOT NULL,
propstack_field varchar(255) NOT NULL,
created_at datetime DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY form_field (form_id, cf7_field)
) $charset_collate;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}
}
// Initialize the plugin
new CF7_Propstack_Integration();