__( 'Demio', 'advanced-form-integration' ), 'tasks' => array( 'reg_people' => __( 'Register people to Webinar', 'advanced-form-integration' ), ) ); return $actions; } add_filter( 'adfoin_settings_tabs', 'adfoin_demio_settings_tab', 10, 1 ); function adfoin_demio_settings_tab( $providers ) { $providers['demio'] = __( 'Demio', 'advanced-form-integration' ); return $providers; } add_action( 'adfoin_settings_view', 'adfoin_demio_settings_view', 10, 1 ); function adfoin_demio_settings_view( $current_tab ) { if( $current_tab != 'demio' ) { return; } if ( ! class_exists( 'ADFOIN_Account_Manager' ) ) { require_once plugin_dir_path( __FILE__ ) . '../../includes/class-adfoin-account-manager.php'; } $fields = array( array( 'name' => 'apiKey', 'label' => __( 'API Key', 'advanced-form-integration' ), 'type' => 'text', 'required' => true, 'mask' => true, 'placeholder' => __( 'Enter your API Key', 'advanced-form-integration' ), 'show_in_table' => true ), array( 'name' => 'apiSecret', 'label' => __( 'API Secret', 'advanced-form-integration' ), 'type' => 'text', 'required' => true, 'mask' => true, 'placeholder' => __( 'Enter your API Secret', 'advanced-form-integration' ), 'show_in_table' => true ) ); $instructions = sprintf( '
%s
', __('Go to Settings > API > copy API Key and API Secret', 'advanced-form-integration') ); ADFOIN_Account_Manager::render_settings_view( 'demio', __( 'Demio', 'advanced-form-integration' ), $fields, $instructions ); } add_action( 'wp_ajax_adfoin_get_demio_credentials', 'adfoin_get_demio_credentials', 10, 0 ); /* * Get Demio credentials */ function adfoin_get_demio_credentials() { if ( ! class_exists( 'ADFOIN_Account_Manager' ) ) { require_once plugin_dir_path( __FILE__ ) . '../../includes/class-adfoin-account-manager.php'; } ADFOIN_Account_Manager::ajax_get_credentials_list( 'demio' ); } add_action( 'wp_ajax_adfoin_save_demio_credentials', 'adfoin_save_demio_credentials', 10, 0 ); /* * Save Demio credentials */ function adfoin_save_demio_credentials() { if ( ! class_exists( 'ADFOIN_Account_Manager' ) ) { require_once plugin_dir_path( __FILE__ ) . '../../includes/class-adfoin-account-manager.php'; } ADFOIN_Account_Manager::ajax_save_credentials( 'demio', array( 'apiKey', 'apiSecret' ) ); } /* * Demio Credentials List */ function adfoin_demio_get_credentials_list() { $credentials = adfoin_read_credentials( 'demio' ); foreach ($credentials as $option) { printf('', esc_attr($option['id']), esc_html($option['title'])); } } // Legacy single-account import: surfaces old `adfoin_demio_*` options // as a Legacy Account record when the new credentials store is empty. add_action( 'plugins_loaded', function() { if ( class_exists( 'ADFOIN_Account_Manager' ) ) { ADFOIN_Account_Manager::register_legacy_option_importer( 'demio', array( 'apiKey' => 'adfoin_demio_api_key', 'apiSecret' => 'adfoin_demio_api_secret', ) ); } }, 20 ); // Deprecated - kept for backward compatibility add_action( 'admin_post_adfoin_demio_save_api_key', 'adfoin_save_demio_api_key', 10, 0 ); function adfoin_save_demio_api_key() { // Security Check // Authorization check adfoin_require_manage_options(); if (! wp_verify_nonce( $_POST['_nonce'], 'adfoin_demio_settings' ) ) { die( __( 'Security check Failed', 'advanced-form-integration' ) ); } $api_key = sanitize_text_field( wp_unslash( $_POST["adfoin_demio_api_key"] ) ); $api_secret = sanitize_text_field( wp_unslash( $_POST["adfoin_demio_api_secret"] ) ); // Save keys update_option( "adfoin_demio_api_key", $api_key ); update_option( "adfoin_demio_api_secret", $api_secret ); advanced_form_integration_redirect( "admin.php?page=advanced-form-integration-settings&tab=demio" ); } add_action( 'adfoin_action_fields', 'adfoin_demio_action_fields' ); function adfoin_demio_action_fields() { ?> 30, 'method' => $method, 'headers' => array( 'Content-Type' => 'application/json', 'Api-Key' => $api_key, 'Api-Secret' => $api_secret, ) ); if( 'POST' == $method || 'PUT' == $method ) { $args['body'] = wp_json_encode( $data ); } $response = wp_remote_request( $url, $args ); if( $record ) { adfoin_add_to_log( $response, $url, $args, $record ); } return $response; } add_action( 'adfoin_demio_job_queue', 'adfoin_demio_job_queue', 10, 1 ); function adfoin_demio_job_queue( $data ) { adfoin_demio_send_data( $data['record'], $data['posted_data'] ); } /* * Handles sending data to demio API */ function adfoin_demio_send_data( $record, $posted_data ) { $record_data = json_decode( $record["data"], true ); if ( adfoin_check_conditional_logic( $record_data['action_data']['cl'] ?? array(), $posted_data ) ) { return; } $data = $record_data['field_data']; $cred_id = isset( $data['credId'] ) ? $data['credId'] : ''; $task = $record['task']; $event_id = isset( $data['eventId'] ) ? $data['eventId'] : ''; $session_id = isset( $data['sessionId'] ) ? $data['sessionId'] : ''; // Backward compatibility: if no cred_id, use first available credential if( empty( $cred_id ) ) { $all_credentials = adfoin_read_credentials( 'demio' ); if( !empty( $all_credentials ) ) { $cred_id = $all_credentials[0]['id']; } } if( $task == 'reg_people' ) { $email = empty( $data['email'] ) ? '' : trim( adfoin_get_parsed_values( $data['email'], $posted_data ) ); $name = empty( $data['name'] ) ? '' : adfoin_get_parsed_values( $data['name'], $posted_data ); // $last_name = empty( $data['last_name'] ) ? '' : adfoin_get_parsed_values( $data['last_name'], $posted_data ); // $company = empty( $data['company'] ) ? '' : adfoin_get_parsed_values( $data['company'], $posted_data ); // $website = empty( $data['website'] ) ? '' : adfoin_get_parsed_values( $data['website'], $posted_data ); // $phone_number = empty( $data['phone_number'] ) ? '' : adfoin_get_parsed_values( $data['phone_number'], $posted_data ); // $gdpr = empty( $data['gdpr'] ) ? '' : adfoin_get_parsed_values( $data['gdpr'], $posted_data ); // $refUrl = empty( $data['refUrl'] ) ? '' : adfoin_get_parsed_values( $data['refUrl'], $posted_data ); $data = array( 'id' => $event_id, 'date_id' => $session_id, 'name' => $name, 'email' => $email, // 'last_name' => $last_name, // 'company' => $company, // 'website' => $website, // 'phone_number' => $phone_number, // 'gdpr' => $gdpr, // 'ref_url' => $refUrl ); $data = array_filter( $data ); $return = adfoin_demio_request( 'event/register', 'POST', $data, $record, $cred_id ); } return; }