PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 5.8.5
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v5.8.5
6.0.3 6.0.2 6.0.1 6.0.0 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 5.7.9.2 5.7.9.1 5.7.8 5.7.9 5.7.6 5.7.7 5.7.5 5.7.4 5.7.3 5.7.2 5.7.1 trunk 5.6.0 5.6.1 All 34 releases
automatorwp / automatorwp.php

automatorwp.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 5.8.5, at automatorwp.php

546 lines 16.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: AutomatorWP
4 * Plugin URI: https://automatorwp.com
5 * Description: Connect your WordPress plugins together and create automated workflows with no code!
6 * Version: 5.8.5
7 * Author: AutomatorWP
8 * Author URI: https://automatorwp.com/
9 * Text Domain: automatorwp
10 * Domain Path: /languages/
11 * Requires PHP: 7.0
12 * Requires at least: 4.4
13 * Tested up to: 7.1
14 * License: GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html)
15 *
16 * @package AutomatorWP
17 * @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]>
18 * @copyright Copyright (c) AutomatorWP
19 */
20
21 /*
22 * Copyright (c) AutomatorWP ([email protected]), Ruben Garcia ([email protected])
23 *
24 * This program is free software: you can redistribute it and/or modify it
25 * under the terms of the GNU Affero General Public License, version 3,
26 * as published by the Free Software Foundation.
27 *
28 * This program is distributed in the hope that it will be useful, but
29 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
30 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General
31 * Public License for more details.
32 *
33 * You should have received a copy of the GNU Affero General Public License
34 * along with this program. If not, see <http://www.gnu.org/licenses/>.
35 */
36
37 final class AutomatorWP {
38
39 /**
40 * @var AutomatorWP $instance The one true AutomatorWP
41 * @since 1.0.0
42 */
43 private static $instance;
44
45 /**
46 * @var array $settings Stored settings
47 * @since 1.0.2
48 */
49 public $settings = null;
50
51 /**
52 * @var array $integrations Registered integrations
53 * @since 1.0.0
54 */
55 public $integrations = array();
56
57 /**
58 * @var array $triggers Registered triggers
59 * @since 1.0.0
60 */
61 public $triggers = array();
62
63 /**
64 * @var array $actions Registered actions
65 * @since 1.0.0
66 */
67 public $actions = array();
68
69 /**
70 * @var array $filters Registered filters
71 * @since 1.0.0
72 */
73 public $filters = array();
74
75 /**
76 * @var AutomatorWP_Database $db Database object
77 * @since 1.0.0
78 */
79 public $db;
80
81 /**
82 * @var array $cache Cache class
83 * @since 1.0.0
84 */
85 public $cache = array();
86
87 /**
88 * Get active instance
89 *
90 * @access public
91 * @since 1.0.0
92 * @return AutomatorWP self::$instance The one true AutomatorWP
93 */
94 public static function instance() {
95
96 if( ! self::$instance ) {
97
98 self::$instance = new AutomatorWP();
99 self::$instance->constants();
100 self::$instance->libraries();
101 self::$instance->classes();
102 self::$instance->compatibility();
103 self::$instance->includes();
104 self::$instance->hooks();
105
106 }
107
108 return self::$instance;
109
110 }
111
112 /**
113 * Setup plugin constants
114 *
115 * @access private
116 * @since 1.0.0
117 * @return void
118 */
119 private function constants() {
120
121 // Plugin version
122 define( 'AUTOMATORWP_VER', '5.8.5' );
123
124 // Plugin file
125 define( 'AUTOMATORWP_FILE', __FILE__ );
126
127 // Plugin path
128 define( 'AUTOMATORWP_DIR', plugin_dir_path( __FILE__ ) );
129
130 // Plugin URL
131 define( 'AUTOMATORWP_URL', plugin_dir_url( __FILE__ ) );
132
133 }
134
135 /**
136 * Include plugin libraries
137 *
138 * @access private
139 * @since 1.0.0
140 * @return void
141 */
142 private function libraries() {
143
144 // Custom Tables
145 require_once AUTOMATORWP_DIR . 'libraries/ct/init.php';
146 require_once AUTOMATORWP_DIR . 'libraries/ct-ajax-list-table/ct-ajax-list-table.php';
147
148 // CMB2
149 require_once AUTOMATORWP_DIR . 'libraries/cmb2/init.php';
150 require_once AUTOMATORWP_DIR . 'libraries/cmb2-metatabs-options/cmb2_metatabs_options.php';
151 require_once AUTOMATORWP_DIR . 'libraries/cmb2-tabs/cmb2-tabs.php';
152 require_once AUTOMATORWP_DIR . 'libraries/cmb2-field-edd-license/cmb2-field-edd-license.php';
153 require_once AUTOMATORWP_DIR . 'libraries/cmb2-field-switch/cmb2-field-switch.php';
154 require_once AUTOMATORWP_DIR . 'libraries/cmb2-field-js-controls/cmb2-field-js-controls.php';
155 require_once AUTOMATORWP_DIR . 'libraries/cmb2-field-tooltip/cmb2-field-tooltip.php';
156
157 // Custom CMB2 fields
158 require_once AUTOMATORWP_DIR . 'libraries/automatorwp-select.php';
159 require_once AUTOMATORWP_DIR . 'libraries/automatorwp-select-filter.php';
160
161 }
162
163 /**
164 * Include plugin classes
165 *
166 * @access private
167 * @since 1.0.0
168 * @return void
169 */
170 private function classes() {
171
172 require_once AUTOMATORWP_DIR . 'classes/database.php';
173 require_once AUTOMATORWP_DIR . 'classes/automation-type.php';
174 require_once AUTOMATORWP_DIR . 'classes/automation-loop.php';
175 require_once AUTOMATORWP_DIR . 'classes/integration-trigger.php';
176 require_once AUTOMATORWP_DIR . 'classes/integration-action.php';
177 require_once AUTOMATORWP_DIR . 'classes/integration-filter.php';
178
179 }
180
181 /**
182 * Include compatibility files
183 *
184 * @access private
185 * @since 4.2.0
186 * @return void
187 */
188 private function compatibility() {
189
190 // GamiPress backward compatibility
191 require_once AUTOMATORWP_DIR . 'includes/compatibility/4.2.0.php';
192
193 }
194
195 /**
196 * Include plugin files
197 *
198 * @access private
199 * @since 1.0.0
200 * @return void
201 */
202 private function includes() {
203
204 // The rest of files
205 require_once AUTOMATORWP_DIR . 'includes/admin.php';
206 require_once AUTOMATORWP_DIR . 'includes/custom-tables.php';
207 require_once AUTOMATORWP_DIR . 'includes/ajax-functions.php';
208 require_once AUTOMATORWP_DIR . 'includes/filters.php';
209 require_once AUTOMATORWP_DIR . 'includes/functions.php';
210 require_once AUTOMATORWP_DIR . 'includes/cache.php';
211 require_once AUTOMATORWP_DIR . 'includes/cmb2.php';
212 require_once AUTOMATORWP_DIR . 'includes/cron.php';
213 require_once AUTOMATORWP_DIR . 'includes/scripts.php';
214 require_once AUTOMATORWP_DIR . 'includes/automation-ui.php';
215 require_once AUTOMATORWP_DIR . 'includes/automation-ui-recommendations.php';
216 require_once AUTOMATORWP_DIR . 'includes/automations.php';
217 require_once AUTOMATORWP_DIR . 'includes/integrations.php';
218 require_once AUTOMATORWP_DIR . 'includes/triggers.php';
219 require_once AUTOMATORWP_DIR . 'includes/actions.php';
220 require_once AUTOMATORWP_DIR . 'includes/tags.php';
221 require_once AUTOMATORWP_DIR . 'includes/tags-replacements.php';
222 require_once AUTOMATORWP_DIR . 'includes/events.php';
223 require_once AUTOMATORWP_DIR . 'includes/logs.php';
224 require_once AUTOMATORWP_DIR . 'includes/users.php';
225 require_once AUTOMATORWP_DIR . 'includes/utilities.php';
226
227 }
228
229 /**
230 * Include integrations files
231 *
232 * @access private
233 * @since 1.0.0
234 * @return void
235 */
236 private function integrations() {
237
238 $integrations_dir = AUTOMATORWP_DIR . 'integrations';
239
240 require_once AUTOMATORWP_DIR . 'integrations/filter/filter.php';
241 require_once AUTOMATORWP_DIR . 'integrations/automatorwp/automatorwp.php';
242 require_once AUTOMATORWP_DIR . 'integrations/wordpress/wordpress.php';
243
244 // Setup active plugins
245 $active_plugins = array();
246
247 if( function_exists( 'get_option' ) ) {
248 $active_plugins = (array) get_option( 'active_plugins', array() );
249 }
250
251 // Setup active sitewide plugins
252 $active_sitewide_plugins = array();
253
254 if ( is_multisite() && function_exists( 'get_site_option' ) ) {
255 $active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' );
256
257 if( ! is_array( $active_sitewide_plugins ) ) {
258 $active_sitewide_plugins = array();
259 }
260 }
261
262 // Skip if integration is already active
263 if( $this->is_integration_active( 'pro', $active_plugins, $active_sitewide_plugins ) ) {
264 return;
265 }
266
267 $integrations = @opendir( $integrations_dir );
268
269 while ( ( $integration = @readdir( $integrations ) ) !== false ) {
270
271 if ( $integration === '.' || $integration === '..' || $integration === 'index.php' ) {
272 continue;
273 }
274
275 if ( $integration === 'filter' || $integration === 'automatorwp' || $integration === 'wordpress' ) {
276 continue;
277 }
278
279 /**
280 * Filter to allow third party plugins skip any integration
281 *
282 * @since 1.0.0
283 *
284 * @param bool $skip
285 * @param string $integration The integration slug as named in automatorwp/includes/integrations
286 * @param array $active_plugins
287 * @param array $active_sitewide_plugins
288 *
289 * @return bool
290 */
291 if( apply_filters( 'automatorwp_skip_integration', false, $integration, $active_plugins, $active_sitewide_plugins ) ) {
292 continue;
293 }
294
295 // Skip if integration is already active
296 if( $this->is_integration_active( $integration, $active_plugins, $active_sitewide_plugins ) ) {
297 continue;
298 }
299
300 $integration_file = $integrations_dir . DIRECTORY_SEPARATOR . $integration . DIRECTORY_SEPARATOR . $integration . '.php';
301
302 // Skip if no file to load
303 if( ! file_exists( $integration_file ) ) {
304 continue;
305 }
306
307 require_once $integration_file;
308
309 }
310
311 closedir( $integrations );
312
313 }
314
315 /**
316 * Include integrations files
317 *
318 * @access private
319 * @since 1.0.0
320 * @param string $integration
321 * @param array $active_plugins
322 * @param array $active_sitewide_plugins
323 * @return bool
324 */
325 private function is_integration_active( $integration, $active_plugins, $active_sitewide_plugins ) {
326
327 $plugins = array(
328 "automatorwp-{$integration}/automatorwp-{$integration}.php",
329 );
330
331 if( $integration === 'elementor' ) {
332 $plugins = array(
333 "automatorwp-{$integration}-forms/automatorwp-{$integration}-forms.php",
334 );
335 }
336
337 foreach( $plugins as $plugin ) {
338
339 // Bail if plugin is active
340 if( in_array( $plugin, $active_plugins, true ) ) {
341 return true;
342 }
343
344 // Bail if plugin is network wide active
345 if ( isset( $active_sitewide_plugins[$plugin] ) ) {
346 return true;
347 }
348
349 // Consider integration active during it's activation
350 if( isset( $_REQUEST['action'] ) && $_REQUEST['action'] === 'activate'
351 && isset( $_REQUEST['plugin'] ) && $_REQUEST['plugin'] === $plugin ) {
352 return true;
353 }
354
355 // Support for bulk activate
356 if( isset( $_REQUEST['action'] ) && $_REQUEST['action'] === 'activate-selected'
357 && isset( $_REQUEST['checked'] ) && is_array( $_REQUEST['checked'] )
358 && in_array( $plugin, $_REQUEST['checked'] ) ) {
359 return true;
360 }
361
362 }
363
364 return false;
365
366 }
367
368 /**
369 * Setup plugin hooks
370 *
371 * @access private
372 * @since 1.0.0
373 * @return void
374 */
375 private function hooks() {
376
377 // Setup our activation and deactivation hooks
378 register_activation_hook( __FILE__, array( $this, 'activate' ) );
379 register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
380
381 // Hook in all our important pieces
382 add_action( 'plugins_loaded', array( $this, 'pre_init' ), 20 );
383 add_action( 'plugins_loaded', array( $this, 'init' ), 50 );
384 add_action( 'plugins_loaded', array( $this, 'post_init' ), 999 );
385
386 add_action( 'init', array( $this, 'load_textdomain' ), 10 );
387
388 }
389
390 /**
391 * Pre init function
392 *
393 * @access private
394 * @since 1.4.6
395 * @return void
396 */
397 function pre_init() {
398
399 // Load all integrations
400 $this->integrations();
401
402 global $wpdb;
403
404 $this->db = new AutomatorWP_Database();
405
406 // Setup WordPress database tables
407 $this->db->posts = $wpdb->posts;
408 $this->db->postmeta = $wpdb->postmeta;
409 $this->db->users = $wpdb->users;
410 $this->db->usermeta = $wpdb->usermeta;
411
412 // Setup AutomatorWP database tables
413 $this->db->automations = $wpdb->automatorwp_automations;
414 $this->db->automations_meta = $wpdb->automatorwp_automations_meta;
415 $this->db->triggers = $wpdb->automatorwp_triggers;
416 $this->db->triggers_meta = $wpdb->automatorwp_triggers_meta;
417 $this->db->actions = $wpdb->automatorwp_actions;
418 $this->db->actions_meta = $wpdb->automatorwp_actions_meta;
419 $this->db->logs = $wpdb->automatorwp_logs;
420 $this->db->logs_meta = $wpdb->automatorwp_logs_meta;
421
422 // Trigger our action to let other plugins know that AutomatorWP is getting initialized
423 do_action( 'automatorwp_pre_init' );
424 }
425
426 /**
427 * Init function
428 *
429 * @access private
430 * @since 1.0.0
431 * @return void
432 */
433 function init() {
434
435 // Prevent to load text domains here
436 add_filter( 'lang_dir_for_domain', array( $this, 'prevent_load_textdomain' ) );
437
438 // Trigger our action to let other plugins know that AutomatorWP is ready
439 do_action( 'automatorwp_init' );
440
441 // Restore text domains load
442 remove_filter( 'lang_dir_for_domain', array( $this, 'prevent_load_textdomain' ) );
443
444 }
445
446 /**
447 * Post init function
448 *
449 * @access private
450 * @since 1.0.0
451 * @return void
452 */
453 function post_init() {
454
455 // Trigger our action to let other plugins know that AutomatorWP has been initialized
456 do_action( 'automatorwp_post_init' );
457
458 }
459
460 /**
461 * Activation
462 *
463 * @access private
464 * @since 1.0.0
465 */
466 function activate() {
467
468 // Include our important bits
469 $this->libraries();
470 $this->includes();
471
472 require_once AUTOMATORWP_DIR . 'includes/install.php';
473
474 automatorwp_install();
475
476 }
477
478 /**
479 * Deactivation
480 *
481 * @access private
482 * @since 1.0.0
483 */
484 function deactivate() {
485
486 // Include our important bits
487 $this->libraries();
488 $this->includes();
489
490 require_once AUTOMATORWP_DIR . 'includes/uninstall.php';
491
492 automatorwp_uninstall();
493
494 }
495
496 public function prevent_load_textdomain() {
497 return false;
498 }
499
500 /**
501 * Internationalization
502 *
503 * @access public
504 * @since 1.0.0
505 * @return void
506 */
507 public function load_textdomain() {
508
509 // Set filter for language directory
510 $lang_dir = AUTOMATORWP_DIR . '/languages/';
511 $lang_dir = apply_filters( 'automatorwp_languages_directory', $lang_dir );
512
513 // Traditional WordPress plugin locale filter
514 $locale = apply_filters( 'plugin_locale', get_locale(), 'automatorwp' );
515 $mofile = sprintf( '%1$s-%2$s.mo', 'automatorwp', $locale );
516
517 // Setup paths to current locale file
518 $mofile_local = $lang_dir . $mofile;
519 $mofile_global = WP_LANG_DIR . '/automatorwp/' . $mofile;
520
521 if( file_exists( $mofile_global ) ) {
522 // Look in global /wp-content/languages/automatorwp/ folder
523 load_textdomain( 'automatorwp', $mofile_global );
524 } elseif( file_exists( $mofile_local ) ) {
525 // Look in local /wp-content/plugins/automatorwp/languages/ folder
526 load_textdomain( 'automatorwp', $mofile_local );
527 } else {
528 // Load the default language files
529 load_plugin_textdomain( 'automatorwp', false, $lang_dir );
530 }
531
532 }
533
534 }
535
536 /**
537 * The main function responsible for returning the one true AutomatorWP instance to functions everywhere
538 *
539 * @since 1.0.0
540 * @return \AutomatorWP The one true AutomatorWP
541 */
542 function AutomatorWP() {
543 return AutomatorWP::instance();
544 }
545
546 AutomatorWP();