' ) );
add_submenu_page( 'advanced-form-integration', esc_html__( 'Advanced Form Integration', 'advanced-form-integration' ), esc_html__( 'Integrations', 'advanced-form-integration' ), 'manage_options', 'advanced-form-integration', array( $this, 'adfoin_routing' ) );
$hook2 = add_submenu_page( 'advanced-form-integration', esc_html__( 'Integrations', 'advanced-form-integration' ), esc_html__( 'Add New', 'advanced-form-integration' ), 'manage_options', 'advanced-form-integration-new', array( $this, 'adfoin_new_integration' ) );
$hook3 = add_submenu_page( 'advanced-form-integration', esc_html__( 'Settings', 'advanced-form-integration' ), esc_html__( 'Settings', 'advanced-form-integration'), 'manage_options', 'advanced-form-integration-settings', array( $this,'adfoin_settings') );
$hook4 = add_submenu_page( 'advanced-form-integration', esc_html__( 'Log', 'advanced-form-integration' ), esc_html__( 'Log', 'advanced-form-integration'), 'manage_options', 'advanced-form-integration-log', array( $this,'adfoin_log') );
$hook5 = add_submenu_page( 'advanced-form-integration', esc_html__( 'Export / Import', 'advanced-form-integration' ), esc_html__( 'Export / Import', 'advanced-form-integration'), 'manage_options', 'advanced-form-integration-import-export', array( $this,'adfoin_import_export' ) );
add_submenu_page( 'advanced-form-integration', esc_html__( 'Get Help', 'advanced-form-integration' ), esc_html__( 'Get Help', 'advanced-form-integration'), 'manage_options', 'advanced-form-integration-help', array( $this,'adfoin_get_help') );
add_action( 'admin_head-' . $hook1, array( $this, 'enqueue_assets' ) );
add_action( 'admin_head-' . $hook2, array( $this, 'enqueue_assets' ) );
add_action( 'admin_head-' . $hook3, array( $this, 'enqueue_assets' ) );
add_action( 'admin_head-' . $hook4, array( $this, 'enqueue_assets' ) );
add_action( 'admin_head-' . $hook5, array( $this, 'enqueue_assets' ) );
// Add screen options for log page
add_action( "load-$hook4", array( $this, 'adfoin_log_screen_options' ) );
}
/**
* Add screen options for log list table
*/
public function adfoin_log_screen_options() {
if ( isset( $_GET['action'] ) && 'view' == $_GET['action'] ) {
return;
}
$option = 'per_page';
$args = array(
'label' => esc_html__( 'Logs per page', 'advanced-form-integration' ),
'default' => 20,
'option' => 'adfoin_log_per_page'
);
add_screen_option( $option, $args );
}
public function enqueue_assets() {
wp_enqueue_script( 'adfoin-vuejs' );
// Determine current page context
$page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
$action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : '';
// Always load core utilities
wp_enqueue_script(
'adfoin-core',
ADVANCED_FORM_INTEGRATION_ASSETS . '/js/core.js',
array( 'adfoin-vuejs' ),
ADVANCED_FORM_INTEGRATION_VERSION,
true
);
// Load triggers and actions only on new/edit integration pages
$needs_integration_scripts = (
$page === 'advanced-form-integration-new' ||
( $page === 'advanced-form-integration' && $action === 'edit' )
);
if ( $needs_integration_scripts ) {
// Load trigger components (always needed for new/edit)
wp_enqueue_script(
'adfoin-triggers',
ADVANCED_FORM_INTEGRATION_ASSETS . '/js/triggers.js',
array( 'adfoin-core' ),
ADVANCED_FORM_INTEGRATION_VERSION,
true
);
// Load Vue app initialization (handles lazy loading of action components)
wp_enqueue_script(
'adfoin-app',
ADVANCED_FORM_INTEGRATION_ASSETS . '/js/app.js',
array( 'adfoin-triggers' ),
ADVANCED_FORM_INTEGRATION_VERSION,
true
);
// Action components (script.js) will be lazy loaded when user selects an action provider
// This saves ~550KB on initial page load
}
// Allow plugins to add custom scripts
do_action( 'adfoin_custom_script' );
// For settings, log, and list pages - only load core (no action components needed)
// This significantly reduces load time on these pages
}
/**
* Display the Tasks page.
*
* @return void
*/
public function adfoin_routing() {
include ADVANCED_FORM_INTEGRATION_INCLUDES . '/class-adfoin-list-table.php';
$action = isset( $_GET['action'] ) ? $_GET['action'] : 'list';
$id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0;
switch ( $action ) {
case 'edit':
$this->adfoin_edit( $id );
break;
case 'duplicate':
$this->adfoin_duplicate_integration($id);
break;
default:
$this->adfoin_list_page() ;
break;
}
}
/*
* This function generates the list of connections
*/
public function adfoin_list_page() {
if ( isset( $_GET['status'] ) ) {
$status = $_GET['status'];
}
adfoin_display_admin_header();
?>
adfoin_log_view( $id );
break;
default:
$this->adfoin_log_list_page() ;
break;
}
}
/*
* Get Help Submenu View
*/
public function adfoin_get_help( $value = '' ) {
include ADVANCED_FORM_INTEGRATION_VIEWS . '/get_help.php';
}
/*
* This function generates the list of connections
*/
public function adfoin_log_list_page() {
?>
Log
prefix . "adfoin_integration";
$sql = $wpdb->prepare( "SELECT * FROM {$table} WHERE id = %d", $id );
$data = $wpdb->get_row( $sql, ARRAY_A );
$data['title'] = __( 'Copy of ', 'advanced-form-integration') . $data['title'];
$result = $wpdb->insert(
$table,
array(
'title' => $data['title'],
'form_provider' => $data['form_provider'],
'form_id' => $data['form_id'],
'form_name' => $data['form_name'],
'action_provider' => $data['action_provider'],
'task' => $data['task'],
'data' => $data['data'],
'status' => 0
)
);
advanced_form_integration_redirect( admin_url( 'admin.php?page=advanced-form-integration' ) );
exit;
}
}