| 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: 6.0.1 |
| 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 <contact@automatorwp.com>, Ruben Garcia <rubengcdev@gmail.com> |
| 18 |
* @copyright Copyright (c) AutomatorWP |
| 19 |
*/ |
| 20 |
|
| 21 |
/* |
| 22 |
* Copyright (c) AutomatorWP (contact@automatorwp.com), Ruben Garcia (rubengcdev@gmail.com) |
| 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->includes(); |
| 103 |
self::$instance->modules(); |
| 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', '6.0.1' ); |
| 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 plugin files |
| 183 |
* |
| 184 |
* @access private |
| 185 |
* @since 1.0.0 |
| 186 |
* @return void |
| 187 |
*/ |
| 188 |
private function includes() { |
| 189 |
|
| 190 |
require_once AUTOMATORWP_DIR . 'includes/admin.php'; |
| 191 |
require_once AUTOMATORWP_DIR . 'includes/custom-tables.php'; |
| 192 |
require_once AUTOMATORWP_DIR . 'includes/ajax-functions.php'; |
| 193 |
require_once AUTOMATORWP_DIR . 'includes/filters.php'; |
| 194 |
require_once AUTOMATORWP_DIR . 'includes/functions.php'; |
| 195 |
require_once AUTOMATORWP_DIR . 'includes/cache.php'; |
| 196 |
require_once AUTOMATORWP_DIR . 'includes/cmb2.php'; |
| 197 |
require_once AUTOMATORWP_DIR . 'includes/cron.php'; |
| 198 |
require_once AUTOMATORWP_DIR . 'includes/scripts.php'; |
| 199 |
require_once AUTOMATORWP_DIR . 'includes/automation-ui.php'; |
| 200 |
require_once AUTOMATORWP_DIR . 'includes/automation-ui-recommendations.php'; |
| 201 |
require_once AUTOMATORWP_DIR . 'includes/automations.php'; |
| 202 |
require_once AUTOMATORWP_DIR . 'includes/integrations.php'; |
| 203 |
require_once AUTOMATORWP_DIR . 'includes/triggers.php'; |
| 204 |
require_once AUTOMATORWP_DIR . 'includes/actions.php'; |
| 205 |
require_once AUTOMATORWP_DIR . 'includes/tags.php'; |
| 206 |
require_once AUTOMATORWP_DIR . 'includes/tags-replacements.php'; |
| 207 |
require_once AUTOMATORWP_DIR . 'includes/events.php'; |
| 208 |
require_once AUTOMATORWP_DIR . 'includes/logs.php'; |
| 209 |
require_once AUTOMATORWP_DIR . 'includes/users.php'; |
| 210 |
require_once AUTOMATORWP_DIR . 'includes/utilities.php'; |
| 211 |
|
| 212 |
} |
| 213 |
|
| 214 |
/** |
| 215 |
* Include modules files |
| 216 |
* |
| 217 |
* @access private |
| 218 |
* @since 1.0.0 |
| 219 |
* @return void |
| 220 |
*/ |
| 221 |
private function modules() { |
| 222 |
|
| 223 |
require_once AUTOMATORWP_DIR . 'modules/ai-assistant/automatorwp-ai-assistant.php'; |
| 224 |
|
| 225 |
} |
| 226 |
|
| 227 |
/** |
| 228 |
* Include integrations files |
| 229 |
* |
| 230 |
* @access private |
| 231 |
* @since 1.0.0 |
| 232 |
* @return void |
| 233 |
*/ |
| 234 |
private function integrations() { |
| 235 |
|
| 236 |
$integrations_dir = AUTOMATORWP_DIR . 'integrations'; |
| 237 |
|
| 238 |
require_once AUTOMATORWP_DIR . 'integrations/filter/filter.php'; |
| 239 |
require_once AUTOMATORWP_DIR . 'integrations/automatorwp/automatorwp.php'; |
| 240 |
require_once AUTOMATORWP_DIR . 'integrations/wordpress/wordpress.php'; |
| 241 |
|
| 242 |
// Setup active plugins |
| 243 |
$active_plugins = array(); |
| 244 |
|
| 245 |
if( function_exists( 'get_option' ) ) { |
| 246 |
$active_plugins = (array) get_option( 'active_plugins', array() ); |
| 247 |
} |
| 248 |
|
| 249 |
// Setup active sitewide plugins |
| 250 |
$active_sitewide_plugins = array(); |
| 251 |
|
| 252 |
if ( is_multisite() && function_exists( 'get_site_option' ) ) { |
| 253 |
$active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' ); |
| 254 |
|
| 255 |
if( ! is_array( $active_sitewide_plugins ) ) { |
| 256 |
$active_sitewide_plugins = array(); |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
// Skip if integration is already active |
| 261 |
if( $this->is_integration_active( 'pro', $active_plugins, $active_sitewide_plugins ) ) { |
| 262 |
return; |
| 263 |
} |
| 264 |
|
| 265 |
$integrations = @opendir( $integrations_dir ); |
| 266 |
|
| 267 |
while ( ( $integration = @readdir( $integrations ) ) !== false ) { |
| 268 |
|
| 269 |
if ( $integration === '.' || $integration === '..' || $integration === 'index.php' ) { |
| 270 |
continue; |
| 271 |
} |
| 272 |
|
| 273 |
if ( $integration === 'filter' || $integration === 'automatorwp' || $integration === 'wordpress' ) { |
| 274 |
continue; |
| 275 |
} |
| 276 |
|
| 277 |
/** |
| 278 |
* Filter to allow third party plugins skip any integration |
| 279 |
* |
| 280 |
* @since 1.0.0 |
| 281 |
* |
| 282 |
* @param bool $skip |
| 283 |
* @param string $integration The integration slug as named in automatorwp/includes/integrations |
| 284 |
* @param array $active_plugins |
| 285 |
* @param array $active_sitewide_plugins |
| 286 |
* |
| 287 |
* @return bool |
| 288 |
*/ |
| 289 |
if( apply_filters( 'automatorwp_skip_integration', false, $integration, $active_plugins, $active_sitewide_plugins ) ) { |
| 290 |
continue; |
| 291 |
} |
| 292 |
|
| 293 |
// Skip if integration is already active |
| 294 |
if( $this->is_integration_active( $integration, $active_plugins, $active_sitewide_plugins ) ) { |
| 295 |
continue; |
| 296 |
} |
| 297 |
|
| 298 |
$integration_file = $integrations_dir . DIRECTORY_SEPARATOR . $integration . DIRECTORY_SEPARATOR . $integration . '.php'; |
| 299 |
|
| 300 |
// Skip if no file to load |
| 301 |
if( ! file_exists( $integration_file ) ) { |
| 302 |
continue; |
| 303 |
} |
| 304 |
|
| 305 |
require_once $integration_file; |
| 306 |
|
| 307 |
} |
| 308 |
|
| 309 |
closedir( $integrations ); |
| 310 |
|
| 311 |
} |
| 312 |
|
| 313 |
/** |
| 314 |
* Include integrations files |
| 315 |
* |
| 316 |
* @access private |
| 317 |
* @since 1.0.0 |
| 318 |
* @param string $integration |
| 319 |
* @param array $active_plugins |
| 320 |
* @param array $active_sitewide_plugins |
| 321 |
* @return bool |
| 322 |
*/ |
| 323 |
private function is_integration_active( $integration, $active_plugins, $active_sitewide_plugins ) { |
| 324 |
|
| 325 |
$plugins = array( |
| 326 |
"automatorwp-{$integration}/automatorwp-{$integration}.php", |
| 327 |
); |
| 328 |
|
| 329 |
if( $integration === 'elementor' ) { |
| 330 |
$plugins = array( |
| 331 |
"automatorwp-{$integration}-forms/automatorwp-{$integration}-forms.php", |
| 332 |
); |
| 333 |
} |
| 334 |
|
| 335 |
foreach( $plugins as $plugin ) { |
| 336 |
|
| 337 |
// Bail if plugin is active |
| 338 |
if( in_array( $plugin, $active_plugins, true ) ) { |
| 339 |
return true; |
| 340 |
} |
| 341 |
|
| 342 |
// Bail if plugin is network wide active |
| 343 |
if ( isset( $active_sitewide_plugins[$plugin] ) ) { |
| 344 |
return true; |
| 345 |
} |
| 346 |
|
| 347 |
// Consider integration active during it's activation |
| 348 |
if( isset( $_REQUEST['action'] ) && $_REQUEST['action'] === 'activate' |
| 349 |
&& isset( $_REQUEST['plugin'] ) && $_REQUEST['plugin'] === $plugin ) { |
| 350 |
return true; |
| 351 |
} |
| 352 |
|
| 353 |
// Support for bulk activate |
| 354 |
if( isset( $_REQUEST['action'] ) && $_REQUEST['action'] === 'activate-selected' |
| 355 |
&& isset( $_REQUEST['checked'] ) && is_array( $_REQUEST['checked'] ) |
| 356 |
&& in_array( $plugin, $_REQUEST['checked'] ) ) { |
| 357 |
return true; |
| 358 |
} |
| 359 |
|
| 360 |
} |
| 361 |
|
| 362 |
return false; |
| 363 |
|
| 364 |
} |
| 365 |
|
| 366 |
/** |
| 367 |
* Setup plugin hooks |
| 368 |
* |
| 369 |
* @access private |
| 370 |
* @since 1.0.0 |
| 371 |
* @return void |
| 372 |
*/ |
| 373 |
private function hooks() { |
| 374 |
|
| 375 |
// Setup our activation and deactivation hooks |
| 376 |
register_activation_hook( __FILE__, array( $this, 'activate' ) ); |
| 377 |
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) ); |
| 378 |
|
| 379 |
// Hook in all our important pieces |
| 380 |
add_action( 'plugins_loaded', array( $this, 'pre_init' ), 20 ); |
| 381 |
add_action( 'plugins_loaded', array( $this, 'init' ), 50 ); |
| 382 |
add_action( 'plugins_loaded', array( $this, 'post_init' ), 999 ); |
| 383 |
|
| 384 |
add_action( 'init', array( $this, 'load_textdomain' ), 10 ); |
| 385 |
|
| 386 |
} |
| 387 |
|
| 388 |
/** |
| 389 |
* Pre init function |
| 390 |
* |
| 391 |
* @access private |
| 392 |
* @since 1.4.6 |
| 393 |
* @return void |
| 394 |
*/ |
| 395 |
function pre_init() { |
| 396 |
|
| 397 |
// Load all integrations |
| 398 |
$this->integrations(); |
| 399 |
|
| 400 |
global $wpdb; |
| 401 |
|
| 402 |
$this->db = new AutomatorWP_Database(); |
| 403 |
|
| 404 |
// Setup WordPress database tables |
| 405 |
$this->db->posts = $wpdb->posts; |
| 406 |
$this->db->postmeta = $wpdb->postmeta; |
| 407 |
$this->db->users = $wpdb->users; |
| 408 |
$this->db->usermeta = $wpdb->usermeta; |
| 409 |
|
| 410 |
// Setup AutomatorWP database tables |
| 411 |
$this->db->automations = $wpdb->automatorwp_automations; |
| 412 |
$this->db->automations_meta = $wpdb->automatorwp_automations_meta; |
| 413 |
$this->db->triggers = $wpdb->automatorwp_triggers; |
| 414 |
$this->db->triggers_meta = $wpdb->automatorwp_triggers_meta; |
| 415 |
$this->db->actions = $wpdb->automatorwp_actions; |
| 416 |
$this->db->actions_meta = $wpdb->automatorwp_actions_meta; |
| 417 |
$this->db->logs = $wpdb->automatorwp_logs; |
| 418 |
$this->db->logs_meta = $wpdb->automatorwp_logs_meta; |
| 419 |
|
| 420 |
// Trigger our action to let other plugins know that AutomatorWP is getting initialized |
| 421 |
do_action( 'automatorwp_pre_init' ); |
| 422 |
} |
| 423 |
|
| 424 |
/** |
| 425 |
* Init function |
| 426 |
* |
| 427 |
* @access private |
| 428 |
* @since 1.0.0 |
| 429 |
* @return void |
| 430 |
*/ |
| 431 |
function init() { |
| 432 |
|
| 433 |
// Prevent to load text domains here |
| 434 |
add_filter( 'lang_dir_for_domain', array( $this, 'prevent_load_textdomain' ) ); |
| 435 |
|
| 436 |
// Trigger our action to let other plugins know that AutomatorWP is ready |
| 437 |
do_action( 'automatorwp_init' ); |
| 438 |
|
| 439 |
// Restore text domains load |
| 440 |
remove_filter( 'lang_dir_for_domain', array( $this, 'prevent_load_textdomain' ) ); |
| 441 |
|
| 442 |
} |
| 443 |
|
| 444 |
/** |
| 445 |
* Post init function |
| 446 |
* |
| 447 |
* @access private |
| 448 |
* @since 1.0.0 |
| 449 |
* @return void |
| 450 |
*/ |
| 451 |
function post_init() { |
| 452 |
|
| 453 |
// Trigger our action to let other plugins know that AutomatorWP has been initialized |
| 454 |
do_action( 'automatorwp_post_init' ); |
| 455 |
|
| 456 |
} |
| 457 |
|
| 458 |
/** |
| 459 |
* Activation |
| 460 |
* |
| 461 |
* @access private |
| 462 |
* @since 1.0.0 |
| 463 |
*/ |
| 464 |
function activate() { |
| 465 |
|
| 466 |
// Include our important bits |
| 467 |
$this->libraries(); |
| 468 |
$this->includes(); |
| 469 |
|
| 470 |
require_once AUTOMATORWP_DIR . 'includes/install.php'; |
| 471 |
|
| 472 |
automatorwp_install(); |
| 473 |
|
| 474 |
} |
| 475 |
|
| 476 |
/** |
| 477 |
* Deactivation |
| 478 |
* |
| 479 |
* @access private |
| 480 |
* @since 1.0.0 |
| 481 |
*/ |
| 482 |
function deactivate() { |
| 483 |
|
| 484 |
// Include our important bits |
| 485 |
$this->libraries(); |
| 486 |
$this->includes(); |
| 487 |
|
| 488 |
require_once AUTOMATORWP_DIR . 'includes/uninstall.php'; |
| 489 |
|
| 490 |
automatorwp_uninstall(); |
| 491 |
|
| 492 |
} |
| 493 |
|
| 494 |
public function prevent_load_textdomain() { |
| 495 |
return false; |
| 496 |
} |
| 497 |
|
| 498 |
/** |
| 499 |
* Internationalization |
| 500 |
* |
| 501 |
* @access public |
| 502 |
* @since 1.0.0 |
| 503 |
* @return void |
| 504 |
*/ |
| 505 |
public function load_textdomain() { |
| 506 |
|
| 507 |
// Set filter for language directory |
| 508 |
$lang_dir = AUTOMATORWP_DIR . '/languages/'; |
| 509 |
$lang_dir = apply_filters( 'automatorwp_languages_directory', $lang_dir ); |
| 510 |
|
| 511 |
// Traditional WordPress plugin locale filter |
| 512 |
$locale = apply_filters( 'plugin_locale', get_locale(), 'automatorwp' ); |
| 513 |
$mofile = sprintf( '%1$s-%2$s.mo', 'automatorwp', $locale ); |
| 514 |
|
| 515 |
// Setup paths to current locale file |
| 516 |
$mofile_local = $lang_dir . $mofile; |
| 517 |
$mofile_global = WP_LANG_DIR . '/automatorwp/' . $mofile; |
| 518 |
|
| 519 |
if( file_exists( $mofile_global ) ) { |
| 520 |
// Look in global /wp-content/languages/automatorwp/ folder |
| 521 |
load_textdomain( 'automatorwp', $mofile_global ); |
| 522 |
} elseif( file_exists( $mofile_local ) ) { |
| 523 |
// Look in local /wp-content/plugins/automatorwp/languages/ folder |
| 524 |
load_textdomain( 'automatorwp', $mofile_local ); |
| 525 |
} else { |
| 526 |
// Load the default language files |
| 527 |
load_plugin_textdomain( 'automatorwp', false, $lang_dir ); |
| 528 |
} |
| 529 |
|
| 530 |
} |
| 531 |
|
| 532 |
} |
| 533 |
|
| 534 |
/** |
| 535 |
* The main function responsible for returning the one true AutomatorWP instance to functions everywhere |
| 536 |
* |
| 537 |
* @since 1.0.0 |
| 538 |
* @return \AutomatorWP The one true AutomatorWP |
| 539 |
*/ |
| 540 |
function AutomatorWP() { |
| 541 |
return AutomatorWP::instance(); |
| 542 |
} |
| 543 |
|
| 544 |
AutomatorWP(); |