__( 'EverWebinar', 'advanced-form-integration' ), 'tasks' => array( 'register_webinar' => __( 'Register to webinar', 'advanced-form-integration' ) ) ); return $actions; } add_filter( 'adfoin_settings_tabs', 'adfoin_everwebinar_settings_tab', 10, 1 ); function adfoin_everwebinar_settings_tab( $providers ) { $providers['everwebinar'] = __( 'EverWebinar', 'advanced-form-integration' ); return $providers; } add_action( 'adfoin_settings_view', 'adfoin_everwebinar_settings_view', 10, 1 ); function adfoin_everwebinar_settings_view( $current_tab ) { if( $current_tab != 'everwebinar' ) { return; } if ( ! class_exists( 'ADFOIN_Account_Manager' ) ) { require_once plugin_dir_path( __FILE__ ) . '../../includes/class-adfoin-account-manager.php'; } $fields = array( array( 'name' => 'apiToken', 'label' => __( 'API Token', 'advanced-form-integration' ), 'type' => 'text', 'required' => true, 'mask' => true, 'placeholder' => __( 'Enter your API Token', 'advanced-form-integration' ), 'show_in_table' => true ) ); $instructions = sprintf( '
%s
', __('Go to My webinars, click ADVANCED menu of any listed webinar, go to API custom integration and copy API Key', 'advanced-form-integration') ); ADFOIN_Account_Manager::render_settings_view( 'everwebinar', __( 'EverWebinar', 'advanced-form-integration' ), $fields, $instructions ); } add_action( 'wp_ajax_adfoin_get_everwebinar_credentials', 'adfoin_get_everwebinar_credentials', 10, 0 ); /* * Get EverWebinar credentials */ function adfoin_get_everwebinar_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( 'everwebinar' ); } add_action( 'wp_ajax_adfoin_save_everwebinar_credentials', 'adfoin_save_everwebinar_credentials', 10, 0 ); /* * Save EverWebinar credentials */ function adfoin_save_everwebinar_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( 'everwebinar', array( 'apiToken' ) ); } /* * EverWebinar Credentials List */ function adfoin_everwebinar_get_credentials_list() { $credentials = adfoin_read_credentials( 'everwebinar' ); foreach ($credentials as $option) { printf('', esc_attr($option['id']), esc_html($option['title'])); } } // Legacy single-account import: surfaces old `adfoin_everwebinar_*` 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( 'everwebinar', array( 'apiToken' => 'adfoin_everwebinar_api_token', ) ); } }, 20 ); // Deprecated - kept for backward compatibility add_action( 'admin_post_adfoin_save_everwebinar_api_token', 'adfoin_save_everwebinar_api_token', 10, 0 ); function adfoin_save_everwebinar_api_token() { // Security Check // Authorization check adfoin_require_manage_options(); if (! wp_verify_nonce( $_POST['_nonce'], 'adfoin_everwebinar_settings' ) ) { die( __( 'Security check Failed', 'advanced-form-integration' ) ); } $api_token = sanitize_text_field( wp_unslash( $_POST["adfoin_everwebinar_api_token"] ) ); // Save tokens update_option( "adfoin_everwebinar_api_token", $api_token ); advanced_form_integration_redirect( "admin.php?page=advanced-form-integration-settings&tab=everwebinar" ); } add_action( 'adfoin_add_js_fields', 'adfoin_everwebinar_js_fields', 10, 1 ); function adfoin_everwebinar_js_fields( $field_data ) {} add_action( 'adfoin_action_fields', 'adfoin_everwebinar_action_fields' ); function adfoin_everwebinar_action_fields() { ?> 30, 'method' => 'POST', 'headers' => array( 'Content-Type' => 'application/x-www-form-urlencoded', ), 'body' => array( 'api_key' => $api_token ) ); $accounts = wp_remote_request( $url, $args ); if( !is_wp_error( $accounts ) ) { $body = json_decode( $accounts["body"] ); $lists = wp_list_pluck( $body->webinars, 'name', 'webinar_id' ); wp_send_json_success( $lists ); } else { wp_send_json_error(); } } add_action( 'wp_ajax_adfoin_get_everwebinar_schedules', 'adfoin_get_everwebinar_schedules', 10, 0 ); /* * Get EverWebinar schedules */ function adfoin_get_everwebinar_schedules() { // Security Check if (! wp_verify_nonce( $_POST['_nonce'], 'advanced-form-integration' ) ) { die( __( 'Security check Failed', 'advanced-form-integration' ) ); } $cred_id = isset( $_POST['credId'] ) ? sanitize_text_field( wp_unslash( $_POST['credId'] ) ) : ''; $credentials = adfoin_get_credentials_by_id( 'everwebinar', $cred_id ); $api_token = isset( $credentials['apiToken'] ) ? $credentials['apiToken'] : ''; // Backward compatibility: fallback to old options if credentials not found if( empty( $api_token ) ) { $api_token = get_option( 'adfoin_everwebinar_api_token' ) ? get_option( 'adfoin_everwebinar_api_token' ) : ''; } if( ! $api_token ) { wp_send_json_error(); } $webinar_id = $_POST["webinarId"] ? sanitize_text_field( wp_unslash( $_POST["webinarId"] ) ) : ""; if( ! $webinar_id ) { wp_send_json_error(); } $url = "https://api.webinarjam.com/everwebinar/webinar"; $args = array( 'timeout' => 30, 'method' => 'POST', 'headers' => array( 'Content-Type' => 'application/x-www-form-urlencoded', ), 'body' => array( 'api_key' => $api_token, 'webinar_id' => $webinar_id ) ); $webinars = wp_remote_request( $url, $args ); if( !is_wp_error( $webinars ) ) { $body = json_decode( $webinars["body"] ); $schedules = wp_list_pluck( $body->webinar->schedules, 'date', 'schedule' ); wp_send_json_success( $schedules ); } else { wp_send_json_error(); } } add_action( 'adfoin_everwebinar_job_queue', 'adfoin_everwebinar_job_queue', 10, 1 ); function adfoin_everwebinar_job_queue( $data ) { adfoin_everwebinar_send_data( $data['record'], $data['posted_data'] ); } /* * Handles sending data to Everwebinar API */ function adfoin_everwebinar_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"]; // Backward compatibility: if no cred_id, use first available credential if( empty( $cred_id ) ) { $all_credentials = adfoin_read_credentials( 'everwebinar' ); if( !empty( $all_credentials ) ) { $cred_id = $all_credentials[0]['id']; } } $credentials = adfoin_get_credentials_by_id( 'everwebinar', $cred_id ); $api_token = isset( $credentials['apiToken'] ) ? $credentials['apiToken'] : ''; // Backward compatibility: fallback to old options if credentials not found if( empty( $api_token ) ) { $api_token = get_option( 'adfoin_everwebinar_api_token' ) ? get_option( 'adfoin_everwebinar_api_token' ) : ''; } if( !$api_token ) { return; } $webinar_id = empty( $data["webinarId"] ) ? "" : $data["webinarId"]; $schedule_id = empty( $data["scheduleId"] ) ? "" : $data["scheduleId"]; $email = empty( $data["email"] ) ? "" : adfoin_get_parsed_values( $data["email"], $posted_data ); $first_name = empty( $data["firstName"] ) ? "" : adfoin_get_parsed_values( $data["firstName"], $posted_data ); $last_name = empty( $data["lastName"] ) ? "" : adfoin_get_parsed_values( $data["lastName"], $posted_data ); $ip_address = empty( $data["ipAddress"] ) ? "" : adfoin_get_parsed_values( $data["ipAddress"], $posted_data ); $country_code = empty( $data["phoneCountryCode"] ) ? "" : adfoin_get_parsed_values( $data["phoneCountryCode"], $posted_data ); $phone = empty( $data["phone"] ) ? "" : adfoin_get_parsed_values( $data["phone"], $posted_data ); $timezone = empty( $data["timezone"] ) ? "" : adfoin_get_parsed_values( $data["timezone"], $posted_data ); $date = empty( $data["date"] ) ? "" : adfoin_get_parsed_values( $data["date"], $posted_data ); if( $task == "register_webinar" ) { $url = "https://api.webinarjam.com/everwebinar/register"; $args = array( 'timeout' => 30, 'method' => 'POST', 'headers' => array( 'Content-Type' => 'application/x-www-form-urlencoded', ), 'body' => array( 'api_key' => $api_token, 'webinar_id' => $webinar_id, 'schedule' => $schedule_id, 'email' => $email, 'first_name' => $first_name, 'last_name' => $last_name, 'phone_country_code' => $country_code, 'phone' => $phone, 'ip_address' => $ip_address, 'timezone' => $timezone, 'date' => $date, ) ); $response = wp_remote_request( $url, $args ); adfoin_add_to_log( $response, $url, $args, $record ); } return; }