| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plugin Name: Advanced Form Integration |
| 5 |
* Plugin URI: https://advancedformintegration.com/ |
| 6 |
* Description: Connect any WordPress form or event to 200+ apps — CRMs, email marketing, sheets, webhooks — with zero code. |
| 7 |
* Author: nasirahmed |
| 8 |
* Author URI: https://advancedformintegration.com/ |
| 9 |
* Version: 2.8.2 |
| 10 |
* License: GPL2 |
| 11 |
* Text Domain: advanced-form-integration |
| 12 |
* Domain Path: languages |
| 13 |
* Tags: form integration, crm, webhooks, automation, contact form 7 |
| 14 |
* Requires at least: 3.0.1 |
| 15 |
* Tested up to: 7.0 |
| 16 |
* Requires PHP: 7.4 |
| 17 |
* |
| 18 |
* Released under the GPL license |
| 19 |
* http://www.opensource.org/licenses/gpl-license.php |
| 20 |
* |
| 21 |
* This is an add-on for WordPress |
| 22 |
* http://wordpress.org/ |
| 23 |
* |
| 24 |
* ********************************************************************** |
| 25 |
* This program is free software; you can redistribute it and/or modify |
| 26 |
* it under the terms of the GNU General Public License as published by |
| 27 |
* the Free Software Foundation; either version 2 of the License, or |
| 28 |
* (at your option) any later version. |
| 29 |
* |
| 30 |
* This program is distributed in the hope that it will be useful, |
| 31 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 32 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 33 |
* GNU General Public License for more details. |
| 34 |
* |
| 35 |
* You should have received a copy of the GNU General Public License |
| 36 |
* along with this program; if not, write to the Free Software |
| 37 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 38 |
* ********************************************************************** |
| 39 |
*/ |
| 40 |
// don't call the file directly |
| 41 |
if ( !defined( 'ABSPATH' ) ) { |
| 42 |
exit; |
| 43 |
} |
| 44 |
if ( !function_exists( 'adfoin_fs' ) ) { |
| 45 |
// Create a helper function for easy SDK access. |
| 46 |
function adfoin_fs() { |
| 47 |
global $adfoin_fs; |
| 48 |
if ( !isset( $adfoin_fs ) ) { |
| 49 |
// Include Freemius SDK. |
| 50 |
require_once dirname( __FILE__ ) . '/freemius/start.php'; |
| 51 |
$adfoin_fs = fs_dynamic_init( array( |
| 52 |
'id' => '4417', |
| 53 |
'slug' => 'advanced-form-integration', |
| 54 |
'type' => 'plugin', |
| 55 |
'public_key' => 'pk_f94bb401ae01ff3a79f438df51715', |
| 56 |
'is_premium' => false, |
| 57 |
'premium_suffix' => 'Professional', |
| 58 |
'has_addons' => false, |
| 59 |
'has_paid_plans' => true, |
| 60 |
'menu' => array( |
| 61 |
'slug' => 'advanced-form-integration-settings', |
| 62 |
'support' => false, |
| 63 |
'parent' => array( |
| 64 |
'slug' => 'advanced-form-integration', |
| 65 |
), |
| 66 |
), |
| 67 |
'is_live' => true, |
| 68 |
'is_org_compliant' => true, |
| 69 |
) ); |
| 70 |
} |
| 71 |
return $adfoin_fs; |
| 72 |
} |
| 73 |
|
| 74 |
// Init Freemius. |
| 75 |
adfoin_fs(); |
| 76 |
// Signal that SDK was initiated. |
| 77 |
do_action( 'adfoin_fs_loaded' ); |
| 78 |
/** |
| 79 |
* Advanced Form Integration Main Class |
| 80 |
*/ |
| 81 |
class Advanced_Form_Integration { |
| 82 |
/** |
| 83 |
* Plugin Version |
| 84 |
* |
| 85 |
* @var string |
| 86 |
*/ |
| 87 |
public $version = '2.8.2'; |
| 88 |
|
| 89 |
/** |
| 90 |
* Initializes the Advanced_Form_Integration class |
| 91 |
* |
| 92 |
* Checks for an existing Advanced_Form_Integration instance |
| 93 |
* and if it doesn't find one, creates it. |
| 94 |
* |
| 95 |
* @since 1.0.0 |
| 96 |
* @return mixed | bool |
| 97 |
*/ |
| 98 |
public static function init() { |
| 99 |
static $instance = false; |
| 100 |
if ( !$instance ) { |
| 101 |
$instance = new Advanced_Form_Integration(); |
| 102 |
} |
| 103 |
return $instance; |
| 104 |
} |
| 105 |
|
| 106 |
/** |
| 107 |
* Constructor for the Advanced_Form_Integration class |
| 108 |
* |
| 109 |
* Sets up all the appropriate hooks and actions |
| 110 |
* |
| 111 |
* @since 1.0 |
| 112 |
* @return void |
| 113 |
*/ |
| 114 |
public function __construct() { |
| 115 |
register_activation_hook( __FILE__, [$this, 'activate'] ); |
| 116 |
register_deactivation_hook( __FILE__, [$this, 'deactivate'] ); |
| 117 |
add_action( |
| 118 |
'wp_insert_site', |
| 119 |
array($this, 'new_site_added'), |
| 120 |
10, |
| 121 |
6 |
| 122 |
); |
| 123 |
$this->init_plugin(); |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* Initialize plugin |
| 128 |
* |
| 129 |
* @since 1.0.0 |
| 130 |
* @return void |
| 131 |
*/ |
| 132 |
public function init_plugin() { |
| 133 |
/* Define constats */ |
| 134 |
$this->define_constants(); |
| 135 |
/* Include files */ |
| 136 |
$this->includes(); |
| 137 |
/* Instantiate classes */ |
| 138 |
$this->init_classes(); |
| 139 |
/* Initialize the action hooks */ |
| 140 |
$this->init_actions(); |
| 141 |
/* Initialize the filter hooks */ |
| 142 |
$this->init_filters(); |
| 143 |
} |
| 144 |
|
| 145 |
/** |
| 146 |
* Function activate |
| 147 |
* |
| 148 |
* This function creates the database tables for the plugin. |
| 149 |
* |
| 150 |
* @param bool $networkwide Whether to activate the plugin network-wide. |
| 151 |
*/ |
| 152 |
public function activate( $networkwide ) { |
| 153 |
if ( function_exists( 'is_multisite' ) && is_multisite() ) { |
| 154 |
if ( $networkwide ) { |
| 155 |
global $wpdb; |
| 156 |
$blogids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" ); |
| 157 |
foreach ( $blogids as $blog_id ) { |
| 158 |
switch_to_blog( $blog_id ); |
| 159 |
$this->create_table(); |
| 160 |
restore_current_blog(); |
| 161 |
} |
| 162 |
return; |
| 163 |
} |
| 164 |
} |
| 165 |
$this->create_table(); |
| 166 |
// Create default tables when plugin activates |
| 167 |
} |
| 168 |
|
| 169 |
/** |
| 170 |
* Function new_site_added |
| 171 |
* |
| 172 |
* This function creates the database tables for the plugin on a newly added site in a multisite network. |
| 173 |
* |
| 174 |
* @param object $site The newly added site object. |
| 175 |
*/ |
| 176 |
public function new_site_added( $site ) { |
| 177 |
if ( is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) { |
| 178 |
switch_to_blog( $site->blog_id ); |
| 179 |
$this->create_table(); |
| 180 |
restore_current_blog(); |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
/** |
| 185 |
* Function create_table |
| 186 |
* |
| 187 |
* This function creates the database tables for the plugin. |
| 188 |
* |
| 189 |
* @return void |
| 190 |
*/ |
| 191 |
private function create_table() { |
| 192 |
global $wpdb; |
| 193 |
$collate = ''; |
| 194 |
if ( $wpdb->has_cap( 'collation' ) ) { |
| 195 |
if ( !empty( $wpdb->charset ) ) { |
| 196 |
$collate .= "DEFAULT CHARACTER SET {$wpdb->charset}"; |
| 197 |
} |
| 198 |
if ( !empty( $wpdb->collate ) ) { |
| 199 |
$collate .= " COLLATE {$wpdb->collate}"; |
| 200 |
} |
| 201 |
} |
| 202 |
$table_schema = array("CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}adfoin_integration` (\n `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n `title` text NOT NULL,\n `form_provider` varchar(255) NOT NULL,\n `form_id` varchar(255) NOT NULL,\n `form_name` varchar(255) DEFAULT NULL,\n `action_provider` varchar(255) NOT NULL,\n `task` varchar(255) NOT NULL,\n `data` longtext DEFAULT NULL,\n `extra_data` longtext DEFAULT NULL,\n `status` int(1) NOT NULL,\n `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (`id`),\n KEY `form_provider_form_id_status` (`form_provider`(50),`form_id`(50),`status`),\n KEY `status` (`status`),\n KEY `action_provider` (`action_provider`(50))\n ) {$collate};", "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}adfoin_log` (\n `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n `response_code` int(3) DEFAULT NULL,\n `response_message` varchar(255) DEFAULT NULL,\n `integration_id` bigint(20) DEFAULT NULL,\n `request_data` longtext DEFAULT NULL,\n `response_data` longtext DEFAULT NULL,\n `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (`id`),\n KEY `integration_id_id` (`integration_id`,`id`),\n KEY `time` (`time`),\n KEY `response_code` (`response_code`)\n ) {$collate};"); |
| 203 |
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 204 |
foreach ( $table_schema as $table ) { |
| 205 |
dbDelta( $table ); |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
/** |
| 210 |
* One-time DB index migration. |
| 211 |
* |
| 212 |
* The original schema declared only `KEY id (id)` on adfoin_integration |
| 213 |
* and adfoin_log — no PRIMARY KEY, and none of the columns the plugin |
| 214 |
* actually filters by (form_provider, status, integration_id, time, |
| 215 |
* response_code) were indexed, so every read was a full table scan. |
| 216 |
* create_table() now ships the correct schema for fresh installs; this |
| 217 |
* brings already-activated sites up to the same shape on the first |
| 218 |
* wp-admin pageload after the update. |
| 219 |
* |
| 220 |
* Idempotent and version-stamped: it inspects the live indexes and only |
| 221 |
* adds what is missing, with each ALTER isolated (errors suppressed) so a |
| 222 |
* failure on one table or one index can't block the rest. |
| 223 |
* |
| 224 |
* @return void |
| 225 |
*/ |
| 226 |
public function run_db_index_migration() { |
| 227 |
if ( (int) get_option( 'adfoin_db_indexes_v1', 0 ) >= 1 ) { |
| 228 |
return; |
| 229 |
} |
| 230 |
global $wpdb; |
| 231 |
$tables = array( |
| 232 |
$wpdb->prefix . 'adfoin_integration' => array( |
| 233 |
'form_provider_form_id_status' => 'ADD INDEX `form_provider_form_id_status` (`form_provider`(50),`form_id`(50),`status`)', |
| 234 |
'status' => 'ADD INDEX `status` (`status`)', |
| 235 |
'action_provider' => 'ADD INDEX `action_provider` (`action_provider`(50))', |
| 236 |
), |
| 237 |
$wpdb->prefix . 'adfoin_log' => array( |
| 238 |
'integration_id_id' => 'ADD INDEX `integration_id_id` (`integration_id`,`id`)', |
| 239 |
'time' => 'ADD INDEX `time` (`time`)', |
| 240 |
'response_code' => 'ADD INDEX `response_code` (`response_code`)', |
| 241 |
), |
| 242 |
); |
| 243 |
// ALTER ... ADD INDEX on a duplicate name is a hard error; suppress |
| 244 |
// so the version stamp still gets written and the loop continues. |
| 245 |
$suppress = $wpdb->suppress_errors( true ); |
| 246 |
foreach ( $tables as $table => $indexes ) { |
| 247 |
// Skip a table that was never created (activation never ran). |
| 248 |
if ( !$wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) ) ) { |
| 249 |
continue; |
| 250 |
} |
| 251 |
$existing = $wpdb->get_col( "SHOW INDEX FROM `{$table}`", 2 ); |
| 252 |
// col 2 = Key_name |
| 253 |
$existing = ( is_array( $existing ) ? array_map( 'strtolower', $existing ) : array() ); |
| 254 |
// Promote `id` to a real PRIMARY KEY first — AUTO_INCREMENT |
| 255 |
// requires a key on the column at all times, so this must land |
| 256 |
// before the redundant secondary `KEY id` can be dropped. |
| 257 |
if ( !in_array( 'primary', $existing, true ) ) { |
| 258 |
$wpdb->query( "ALTER TABLE `{$table}` ADD PRIMARY KEY (`id`)" ); |
| 259 |
} |
| 260 |
foreach ( $indexes as $name => $add_clause ) { |
| 261 |
if ( !in_array( strtolower( $name ), $existing, true ) ) { |
| 262 |
$wpdb->query( "ALTER TABLE `{$table}` {$add_clause}" ); |
| 263 |
} |
| 264 |
} |
| 265 |
// Drop the now-redundant `KEY id (id)` once a PRIMARY KEY exists. |
| 266 |
$refreshed = $wpdb->get_col( "SHOW INDEX FROM `{$table}`", 2 ); |
| 267 |
$refreshed = ( is_array( $refreshed ) ? array_map( 'strtolower', $refreshed ) : array() ); |
| 268 |
if ( in_array( 'primary', $refreshed, true ) && in_array( 'id', $refreshed, true ) ) { |
| 269 |
$wpdb->query( "ALTER TABLE `{$table}` DROP INDEX `id`" ); |
| 270 |
} |
| 271 |
} |
| 272 |
$wpdb->suppress_errors( $suppress ); |
| 273 |
update_option( 'adfoin_db_indexes_v1', 1, 'no' ); |
| 274 |
} |
| 275 |
|
| 276 |
/** |
| 277 |
* Plugin deactivation function |
| 278 |
* |
| 279 |
* @since 1.0 |
| 280 |
* @return void |
| 281 |
*/ |
| 282 |
public function deactivate() { |
| 283 |
} |
| 284 |
|
| 285 |
/** |
| 286 |
* Function define_constants |
| 287 |
* |
| 288 |
* This function defines the plugin's constants. |
| 289 |
* |
| 290 |
* @return void |
| 291 |
*/ |
| 292 |
public function define_constants() { |
| 293 |
define( 'ADVANCED_FORM_INTEGRATION_VERSION', $this->version ); |
| 294 |
// Plugin Version |
| 295 |
define( 'ADVANCED_FORM_INTEGRATION_FILE', __FILE__ ); |
| 296 |
// Plugin Main Folder Path |
| 297 |
define( 'ADVANCED_FORM_INTEGRATION_PATH', dirname( ADVANCED_FORM_INTEGRATION_FILE ) ); |
| 298 |
// Parent Directory Path |
| 299 |
define( 'ADVANCED_FORM_INTEGRATION_INCLUDES', ADVANCED_FORM_INTEGRATION_PATH . '/includes' ); |
| 300 |
// Include Folder Path |
| 301 |
define( 'ADVANCED_FORM_INTEGRATION_URL', plugins_url( '', ADVANCED_FORM_INTEGRATION_FILE ) ); |
| 302 |
// URL Path |
| 303 |
define( 'ADVANCED_FORM_INTEGRATION_ASSETS', ADVANCED_FORM_INTEGRATION_URL . '/assets' ); |
| 304 |
// Asset Folder Path |
| 305 |
define( 'ADVANCED_FORM_INTEGRATION_VIEWS', ADVANCED_FORM_INTEGRATION_PATH . '/views' ); |
| 306 |
// View Folder Path |
| 307 |
define( 'ADVANCED_FORM_INTEGRATION_PLATFORMS', ADVANCED_FORM_INTEGRATION_PATH . '/platforms' ); |
| 308 |
// View Folder Path |
| 309 |
define( 'ADVANCED_FORM_INTEGRATION_TEMPLATES', ADVANCED_FORM_INTEGRATION_PATH . '/templates' ); |
| 310 |
// View Folder Path |
| 311 |
define( 'ADVANCED_FORM_INTEGRATION_PRO', ADVANCED_FORM_INTEGRATION_PATH . '/pro' ); |
| 312 |
// View Folder Path |
| 313 |
} |
| 314 |
|
| 315 |
/** |
| 316 |
* Include the required files |
| 317 |
* |
| 318 |
* @since 1.0 |
| 319 |
* @return void |
| 320 |
*/ |
| 321 |
public function includes() { |
| 322 |
require_once ADVANCED_FORM_INTEGRATION_INCLUDES . '/class-adfoin-db.php'; |
| 323 |
require_once ADVANCED_FORM_INTEGRATION_INCLUDES . '/class-adfoin-admin-header.php'; |
| 324 |
require_once ADVANCED_FORM_INTEGRATION_INCLUDES . '/class-adfoin-admin-menu.php'; |
| 325 |
require_once ADVANCED_FORM_INTEGRATION_INCLUDES . '/class-adfoin-integration.php'; |
| 326 |
require_once ADVANCED_FORM_INTEGRATION_INCLUDES . '/class-adfoin-log.php'; |
| 327 |
require_once ADVANCED_FORM_INTEGRATION_INCLUDES . '/class-adfoin-submission.php'; |
| 328 |
// Review nag (admin_notices) and Import/Export handlers |
| 329 |
// (admin_post_* + admin_notices) are only meaningful in admin |
| 330 |
// context. Skip them on front-end pageloads so the bottom of the |
| 331 |
// bootstrap stays cheap. is_admin() is true for wp-admin pages, |
| 332 |
// admin-ajax.php, and admin-post.php — covering every entry point |
| 333 |
// these classes hook into. |
| 334 |
if ( is_admin() ) { |
| 335 |
require_once ADVANCED_FORM_INTEGRATION_INCLUDES . '/class-adfoin-review.php'; |
| 336 |
require_once ADVANCED_FORM_INTEGRATION_INCLUDES . '/class-adfoin-import-export.php'; |
| 337 |
} |
| 338 |
require_once ADVANCED_FORM_INTEGRATION_INCLUDES . '/class-oauth.php'; |
| 339 |
require_once ADVANCED_FORM_INTEGRATION_INCLUDES . '/class-adfoin-oauth-manager.php'; |
| 340 |
require_once ADVANCED_FORM_INTEGRATION_INCLUDES . '/class-adfoin-account-manager.php'; |
| 341 |
require_once ADVANCED_FORM_INTEGRATION_INCLUDES . '/functions-adfoin.php'; |
| 342 |
require_once ADVANCED_FORM_INTEGRATION_INCLUDES . '/api/credentials.php'; |
| 343 |
$trigger_keys = adfoin_get_trigger_keys(); |
| 344 |
foreach ( $trigger_keys as $trigger_key ) { |
| 345 |
if ( file_exists( ADVANCED_FORM_INTEGRATION_INCLUDES . '/triggers/' . $trigger_key . '/' . $trigger_key . '.php' ) ) { |
| 346 |
require_once ADVANCED_FORM_INTEGRATION_INCLUDES . '/triggers/' . $trigger_key . '/' . $trigger_key . '.php'; |
| 347 |
} |
| 348 |
} |
| 349 |
$platform_settings = adfoin_get_action_platform_settings(); |
| 350 |
foreach ( $platform_settings as $platform => $value ) { |
| 351 |
if ( true == $value ) { |
| 352 |
if ( file_exists( ADVANCED_FORM_INTEGRATION_PLATFORMS . "/{$platform}/{$platform}.php" ) ) { |
| 353 |
require_once ADVANCED_FORM_INTEGRATION_PLATFORMS . "/{$platform}/{$platform}.php"; |
| 354 |
} |
| 355 |
} |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
/** |
| 360 |
* Instantiate classes |
| 361 |
* |
| 362 |
* @since 1.0 |
| 363 |
* @return void |
| 364 |
*/ |
| 365 |
public function init_classes() { |
| 366 |
// Admin Menu Class |
| 367 |
new Advanced_Form_Integration_Admin_Menu(); |
| 368 |
// Submission Handler Class |
| 369 |
new Advanced_Form_Integration_Submission(); |
| 370 |
} |
| 371 |
|
| 372 |
/** |
| 373 |
* Initializes action hooks |
| 374 |
* |
| 375 |
* @since 1.0 |
| 376 |
* @return void |
| 377 |
*/ |
| 378 |
public function init_actions() { |
| 379 |
add_action( 'init', array($this, 'localization_setup') ); |
| 380 |
add_action( 'admin_enqueue_scripts', array($this, 'register_scripts') ); |
| 381 |
add_action( 'wp_enqueue_scripts', array($this, 'register_public_scripts') ); |
| 382 |
add_action( 'plugins_loaded', array($this, 'load_action_scheduler') ); |
| 383 |
// One-time DB index migration — admin_init keeps the (possibly slow) |
| 384 |
// ALTER off front-end requests; it runs once then version-stamps out. |
| 385 |
add_action( 'admin_init', array($this, 'run_db_index_migration') ); |
| 386 |
} |
| 387 |
|
| 388 |
/** |
| 389 |
* Load Action Scheduler |
| 390 |
* |
| 391 |
* @since 1.0 |
| 392 |
* @return void |
| 393 |
*/ |
| 394 |
public function load_action_scheduler() { |
| 395 |
require_once ADVANCED_FORM_INTEGRATION_PATH . '/library/action-scheduler/action-scheduler.php'; |
| 396 |
} |
| 397 |
|
| 398 |
/** |
| 399 |
* Initialize plugin for localization |
| 400 |
* |
| 401 |
* @since 1.0 |
| 402 |
* |
| 403 |
* @uses load_plugin_textdomain() |
| 404 |
* |
| 405 |
* @return void |
| 406 |
*/ |
| 407 |
public function localization_setup() { |
| 408 |
load_plugin_textdomain( 'advanced-form-integration', false, dirname( plugin_basename( ADVANCED_FORM_INTEGRATION_FILE ) ) . '/languages/' ); |
| 409 |
} |
| 410 |
|
| 411 |
/** |
| 412 |
* Initializes action filters |
| 413 |
* |
| 414 |
* @since 1.0 |
| 415 |
* @return void |
| 416 |
*/ |
| 417 |
public function init_filters() { |
| 418 |
} |
| 419 |
|
| 420 |
/** |
| 421 |
* Register Scripts |
| 422 |
* |
| 423 |
* @since 1.0 |
| 424 |
* @return mixed | void |
| 425 |
*/ |
| 426 |
public function register_scripts( $hook ) { |
| 427 |
// Vue 3.5.x production build (minified, ~160 KB, no dev warnings). |
| 428 |
// The dev build (vue3.global.js) was used for the migration spike |
| 429 |
// and has been removed. vue.min.js (Vue 2) is kept on disk for |
| 430 |
// instant rollback — flip this source back to it if needed. |
| 431 |
// jQuery dependency dropped: Vue does not use jQuery. |
| 432 |
wp_register_script( |
| 433 |
'adfoin-vuejs', |
| 434 |
ADVANCED_FORM_INTEGRATION_ASSETS . '/js/vue3.global.prod.js', |
| 435 |
array(), |
| 436 |
$this->version, |
| 437 |
1 |
| 438 |
); |
| 439 |
// Vue 2 -> 3 compatibility shim — must load right after Vue 3 and |
| 440 |
// before any plugin script (re-creates `new Vue()` / `Vue.component()`). |
| 441 |
wp_register_script( |
| 442 |
'adfoin-vue3-shim', |
| 443 |
ADVANCED_FORM_INTEGRATION_ASSETS . '/js/vue3-compat-shim.js', |
| 444 |
array('adfoin-vuejs'), |
| 445 |
$this->version, |
| 446 |
1 |
| 447 |
); |
| 448 |
// Register shared Vue components (registered globally before the app boots) |
| 449 |
wp_register_script( |
| 450 |
'adfoin-searchable-select', |
| 451 |
ADVANCED_FORM_INTEGRATION_ASSETS . '/js/components/searchable-select.js', |
| 452 |
array('adfoin-vue3-shim'), |
| 453 |
$this->version, |
| 454 |
1 |
| 455 |
); |
| 456 |
// Register core utilities (helpers + per-platform lazy loader) |
| 457 |
wp_register_script( |
| 458 |
'adfoin-core', |
| 459 |
ADVANCED_FORM_INTEGRATION_ASSETS . '/js/core.js', |
| 460 |
array('adfoin-vue3-shim', 'adfoin-searchable-select'), |
| 461 |
$this->version, |
| 462 |
1 |
| 463 |
); |
| 464 |
// Register trigger components |
| 465 |
wp_register_script( |
| 466 |
'adfoin-triggers', |
| 467 |
ADVANCED_FORM_INTEGRATION_ASSETS . '/js/triggers.js', |
| 468 |
array('adfoin-core'), |
| 469 |
$this->version, |
| 470 |
1 |
| 471 |
); |
| 472 |
// Register Vue app initialization (lazy-loads one platform component on demand) |
| 473 |
wp_register_script( |
| 474 |
'adfoin-app', |
| 475 |
ADVANCED_FORM_INTEGRATION_ASSETS . '/js/app.js', |
| 476 |
array('adfoin-triggers'), |
| 477 |
$this->version, |
| 478 |
1 |
| 479 |
); |
| 480 |
// Backward-compat handle: assets/js/script.js is now an empty stub |
| 481 |
// kept so any third-party code that explicitly enqueues it still |
| 482 |
// resolves. All component code lives in platforms/<name>/<name>-component.js |
| 483 |
// and is fetched on demand by adfoinComponentLoader.loadPlatform(). |
| 484 |
wp_register_script( |
| 485 |
'adfoin-main-script', |
| 486 |
ADVANCED_FORM_INTEGRATION_ASSETS . '/js/script.js', |
| 487 |
array('adfoin-triggers'), |
| 488 |
$this->version, |
| 489 |
1 |
| 490 |
); |
| 491 |
// Stylesheet, localized payload, and the log-page code editor are |
| 492 |
// only useful on plugin admin pages. Skipping the rest avoids: |
| 493 |
// - the unused stylesheet hitting every admin pageload |
| 494 |
// - the scandir() inside adfoin_get_platform_scripts() |
| 495 |
// - shipping the localized adfoin object on screens that won't use it |
| 496 |
// wp_register_script() above remains universal so third-party code |
| 497 |
// that opts into adfoin-* handles still resolves them. |
| 498 |
if ( !$this->is_plugin_admin_page( $hook ) ) { |
| 499 |
return; |
| 500 |
} |
| 501 |
wp_enqueue_style( |
| 502 |
'adfoin-main-style', |
| 503 |
ADVANCED_FORM_INTEGRATION_ASSETS . '/css/asset.css', |
| 504 |
array(), |
| 505 |
$this->version |
| 506 |
); |
| 507 |
$platform_scripts = ( function_exists( 'adfoin_get_platform_scripts' ) ? adfoin_get_platform_scripts() : array() ); |
| 508 |
$localize_scripts = array( |
| 509 |
'nonce' => wp_create_nonce( 'advanced-form-integration' ), |
| 510 |
'delete_confirm' => __( 'Are you sure to delete the integration?', 'advanced-form-integration' ), |
| 511 |
'list_url' => admin_url( 'admin.php?page=advanced-form-integration&status=1' ), |
| 512 |
'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 513 |
'siteurl' => site_url(), |
| 514 |
'assetsUrl' => ADVANCED_FORM_INTEGRATION_ASSETS, |
| 515 |
'version' => $this->version, |
| 516 |
'loadingText' => __( 'Loading...', 'advanced-form-integration' ), |
| 517 |
'platformScripts' => $platform_scripts, |
| 518 |
); |
| 519 |
// Localize to core script (loaded first) |
| 520 |
wp_localize_script( 'adfoin-core', 'adfoin', $localize_scripts ); |
| 521 |
// Also localize to legacy main script for backward compatibility |
| 522 |
wp_localize_script( 'adfoin-main-script', 'adfoin', $localize_scripts ); |
| 523 |
$this->add_log_code_editor(); |
| 524 |
} |
| 525 |
|
| 526 |
/** |
| 527 |
* Whether the current admin pageload is one of this plugin's screens. |
| 528 |
* |
| 529 |
* Hook names follow WordPress's add_menu_page / add_submenu_page |
| 530 |
* convention for this plugin: |
| 531 |
* - top-level: `toplevel_page_advanced-form-integration` |
| 532 |
* - submenus: `afi_page_advanced-form-integration[-suffix]` |
| 533 |
* (The `afi_` prefix is derived from the menu title "AFI".) |
| 534 |
* |
| 535 |
* @since 1.131.2 |
| 536 |
* @param string $hook Hook suffix passed to admin_enqueue_scripts. |
| 537 |
* @return bool |
| 538 |
*/ |
| 539 |
private function is_plugin_admin_page( $hook ) { |
| 540 |
if ( empty( $hook ) || !is_string( $hook ) ) { |
| 541 |
return false; |
| 542 |
} |
| 543 |
if ( 'toplevel_page_advanced-form-integration' === $hook ) { |
| 544 |
return true; |
| 545 |
} |
| 546 |
return 0 === strpos( $hook, 'afi_page_advanced-form-integration' ); |
| 547 |
} |
| 548 |
|
| 549 |
/** |
| 550 |
* Function add_log_code_editor |
| 551 |
* |
| 552 |
* This function adds a code editor to the Advanced Form Integration log page. |
| 553 |
* |
| 554 |
* @return void |
| 555 |
*/ |
| 556 |
public function add_log_code_editor() { |
| 557 |
if ( !function_exists( 'get_current_screen' ) ) { |
| 558 |
return; |
| 559 |
} |
| 560 |
$screen = get_current_screen(); |
| 561 |
if ( !$screen || 'afi_page_advanced-form-integration-log' !== $screen->id ) { |
| 562 |
return; |
| 563 |
} |
| 564 |
$settings = wp_enqueue_code_editor( array( |
| 565 |
'type' => 'application/json', |
| 566 |
) ); |
| 567 |
if ( false === $settings ) { |
| 568 |
return; |
| 569 |
} |
| 570 |
// wp.codeEditor.initialize() prepends "#" to a string id, so pass |
| 571 |
// the BARE id — "#adfoin-log-request-data" produced the invalid |
| 572 |
// "##adfoin-log-request-data" selector and threw in newer jQuery. |
| 573 |
// The existence guard matters because this inline script also runs |
| 574 |
// on the log *list* screen, which has no request-data textarea. |
| 575 |
wp_add_inline_script( 'code-editor', sprintf( 'jQuery( function() { if ( document.getElementById( "adfoin-log-request-data" ) ) { wp.codeEditor.initialize( "adfoin-log-request-data", %s ); } } );', wp_json_encode( $settings ) ) ); |
| 576 |
} |
| 577 |
|
| 578 |
/** |
| 579 |
* Register Public Script |
| 580 |
* |
| 581 |
* @since 1.53.0 |
| 582 |
* @return mixed | void |
| 583 |
*/ |
| 584 |
public function register_public_scripts() { |
| 585 |
if ( 1 == get_option( 'adfoin_general_settings_utm' ) ) { |
| 586 |
wp_enqueue_script( |
| 587 |
'js.cookie', |
| 588 |
ADVANCED_FORM_INTEGRATION_ASSETS . '/js/js.cookie.js', |
| 589 |
array('jquery'), |
| 590 |
$this->version, |
| 591 |
1 |
| 592 |
); |
| 593 |
wp_enqueue_script( |
| 594 |
'afi-utm-grabber', |
| 595 |
ADVANCED_FORM_INTEGRATION_ASSETS . '/js/utm-grabber.js', |
| 596 |
array('jquery', 'js.cookie'), |
| 597 |
$this->version, |
| 598 |
1 |
| 599 |
); |
| 600 |
} |
| 601 |
} |
| 602 |
|
| 603 |
} |
| 604 |
|
| 605 |
$adfoin = Advanced_Form_Integration::init(); |
| 606 |
} |