-
Notifications
You must be signed in to change notification settings - Fork 10
/
cf7-to-zapier.php
214 lines (190 loc) · 7.84 KB
/
cf7-to-zapier.php
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
/**
*
* @package Cf7_To_Zapier
* @since 1.0.0
*
* Plugin Name: CF7 to Webhook
* Plugin URI: https://github.com/mariovalney/cf7-to-zapier
* Description: Use Contact Form 7 as a trigger to any webhook like Zapier!
* Version: 3.0.6
* Author: Mário Valney
* Author URI: http://mariovalney.com/me
* Text Domain: cf7-to-zapier
* Domain Path: /languages
*
*/
// If this file is called directly, call the cops.
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
if ( ! class_exists( 'Cf7_To_Zapier' ) ) {
class Cf7_To_Zapier {
/**
* The array of actions registered with WordPress.
*
* @since 1.0.0
* @access protected
* @var array $actions The actions registered with WordPress to fire when the plugin loads.
*/
protected $actions = array();
/**
* The array of filters registered with WordPress.
*
* @since 1.0.0
* @access protected
* @var array $filters The filters registered with WordPress to fire when the plugin loads.
*/
protected $filters = array();
/**
* The array of modules of plugin.
*
* @since 1.0.0
* @access protected
* @var array $modules The modules to be used in this plugin.
*/
protected $modules = array();
/**
* Define the core functionality of the plugin.
*
* @since 1.0.0
*/
public function __construct() {
$this->include_functions_file();
$this->define_hooks();
$this->add_modules();
}
/**
* Define things to run when activate plugin
*
* @since 1.0.0
*/
public function on_activation() {
flush_rewrite_rules();
}
/**
* Register the hooks for Core
*
* @since 1.0.0
* @access private
*/
private function define_hooks() {
// Internationalization
$this->add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) );
// Activation Hook
register_activation_hook( __FILE__, array( $this, 'on_activation' ) );
}
/**
* Load all the plugins modules.
*
* @since 1.0.0
* @access private
*/
private function add_modules() {
// Require module files:
require_once plugin_dir_path( __FILE__ ) . 'modules/cf7/class-module-cf7.php';
require_once plugin_dir_path( __FILE__ ) . 'modules/zapier/class-module-zapier.php';
// Instantiate the Module's classes:
$this->modules['cf7'] = new CFTZ_Module_CF7( $this );
$this->modules['zapier'] = new CFTZ_Module_Zapier( $this );
}
/**
* Load the core functions file
*
* @since 1.0.0
* @access private
*/
private function include_functions_file() {
require_once plugin_dir_path( __FILE__ ) . 'includes/functions-debug.php';
}
/**
* A utility function that is used to register the actions and hooks into a single
* collection.
*
* @since 1.0.0
* @access private
* @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
* @param string $hook The name of the WordPress filter that is being registered.
* @param string $callback The callback function or a array( $obj, 'method' ) to public method of a class.
* @param int $priority The priority at which the function should be fired.
* @param int $accepted_args The number of arguments that should be passed to the $callback.
* @return array The collection of actions and filters registered with WordPress.
*/
private function add_hook( $hooks, $hook, $callback, $priority, $accepted_args ) {
$hooks[] = array(
'hook' => $hook,
'callback' => $callback,
'priority' => $priority,
'accepted_args' => $accepted_args
);
return $hooks;
}
/**
* Add a new action to the collection to be registered with WordPress.
*
* @since 1.0.0
* @param string $hook The name of the WordPress action that is being registered.
* @param string $callback The callback function or a array( $obj, 'method' ) to public method of a class.
* @param int $priority Optional. he priority at which the function should be fired. Default is 10.
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
*/
public function add_action( $hook, $callback, $priority = 10, $accepted_args = 1 ) {
$this->actions = $this->add_hook( $this->actions, $hook, $callback, $priority, $accepted_args );
}
/**
* Add a new filter to the collection to be registered with WordPress.
*
* @since 1.0.0
* @param string $hook The name of the WordPress filter that is being registered.
* @param string $callback The callback function or a array( $obj, 'method' ) to public method of a class.
* @param int $priority Optional. he priority at which the function should be fired. Default is 10.
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1
*/
public function add_filter( $hook, $callback, $priority = 10, $accepted_args = 1 ) {
$this->filters = $this->add_hook( $this->filters, $hook, $callback, $priority, $accepted_args );
}
/**
* Define the locale for this plugin for internationalization.
*
*
* @since 1.0.0
* @access private
*/
public function load_plugin_textdomain() {
load_plugin_textdomain( 'cf7-to-zapier', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
/**
* Run the plugin.
*
* @since 1.0.0
*/
public function run() {
// Definitions to plugin
define( 'CFTZ_VERSION', '3.0.6' );
define( 'CFTZ_PLUGIN_FILE', __FILE__ );
define( 'CFTZ_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
define( 'CFTZ_PLUGIN_PATH', WP_PLUGIN_DIR . '/' . dirname( CFTZ_PLUGIN_BASENAME ) );
define( 'CFTZ_PLUGIN_DIR', dirname( CFTZ_PLUGIN_BASENAME ) );
define( 'CFTZ_PLUGIN_URL', plugins_url( '', __FILE__ ) );
// Definition of upload_dir
if ( ! defined( 'CFTZ_UPLOAD_DIR' ) ) {
define( 'CFTZ_UPLOAD_DIR', 'cf7-to-webhook-uploads' );
}
// Running Modules (first of all)
foreach ( $this->modules as $module ) {
$module->run();
}
// Running Filters
foreach ( $this->filters as $hook ) {
add_filter( $hook['hook'], $hook['callback'], $hook['priority'], $hook['accepted_args'] );
}
// Running Actions
foreach ( $this->actions as $hook ) {
add_action( $hook['hook'], $hook['callback'], $hook['priority'], $hook['accepted_args'] );
}
}
}
}
/**
* Making things happening
*/
$ctz_core = new Cf7_To_Zapier();
$ctz_core->run();