// ========================================================================= // AIFOD x ZAAN SYSTEM LOGIC CORE: CPT ENGINE, SANITIZATION & GOOGLE SHEET SYNC // ========================================================================= // 1. Structural Layer: Register Backup Database Custom Post Type add_action('init', 'instantiate_summit_backup_cpt'); function instantiate_summit_backup_cpt() { register_post_type('summit_registration', array( 'labels' => array( 'name' => 'Summit Registrations', 'singular_name' => 'Registration Entry', ), 'public' => false, 'show_ui' => true, // Exposes management records UI component within wp-admin 'capability_type' => 'post', 'capabilities' => array('create_posts' => false), // Guard rails block manual layout inputs 'map_meta_cap' => true, 'supports' => array('title'), 'menu_icon' => 'dashicons-clipboard', )); } // 2. Network Endpoint Processing Layer: Secure Webhook Handler add_action('wp_ajax_execute_summit_registration_pipeline', 'process_summit_registration_payload'); add_action('wp_ajax_nopriv_execute_summit_registration_pipeline', 'process_summit_registration_payload'); function process_summit_registration_payload() { // Cryptographic token authorization check if ( ! isset($_POST['summit_secure_nonce']) || ! wp_verify_nonce($_POST['summit_secure_nonce'], 'summit_security_token_action') ) { wp_send_json_error('CSRF Token processing check failed. Session unsafe.'); } // Explicit server-side structural data normalization & cleansing sanitization $name = sanitize_text_field($_POST['full_name']); $email = sanitize_email($_POST['email']); $phone = sanitize_text_field($_POST['phone']); $org = sanitize_text_field($_POST['organization']); $job = sanitize_text_field($_POST['job_title']); $requests = sanitize_textarea_field($_POST['special_requests']); // Explicit architectural logic validation check if ( empty($name) || empty($email) || ! is_email($email) ) { wp_send_json_error('Server-side processing error: Mandatory parameter values validation failed.'); } // STEP A: Store a backup record locally inside MySQL database via our Custom Post Type $local_record_id = wp_insert_post(array( 'post_title' => $name . ' [' . $email . ']', 'post_type' => 'summit_registration', 'post_status' => 'publish' )); if ( $local_record_id ) { update_post_meta($local_record_id, '_meta_attendee_email', $email); update_post_meta($local_record_id, '_meta_attendee_phone', $phone); update_post_meta($local_record_id, '_meta_attendee_org', $org); update_post_meta($local_record_id, '_meta_attendee_job', $job); update_post_meta($local_record_id, '_meta_attendee_requests', $requests); } // STEP B: Execute out-of-band asynchronous processing pipe straight to Google Sheet API App Script Webhook // !! REPLACE THIS WITH YOUR APPS SCRIPT WEB APP DEPLOYMENT URL DURING TRIAL RUN !! $google_sheets_target_url = 'https://script.google.com/macros/s/YOUR_DEPLOID_ID_GOES_HERE/exec'; $data_payload = array( 'date' => current_time('Y-m-d H:i:s'), 'full_name' => $name, 'email' => $email, 'phone' => $phone, 'organization' => $org, 'job_title' => $job, 'special_requests' => $requests ); $api_network_response = wp_remote_post($google_sheets_target_url, array( 'method' => 'POST', 'timeout' => 15, 'body' => json_encode($data_payload), 'headers' => array('Content-Type' => 'application/json') )); // Handle Network Droppers Gracefully. Since it's saved in the CPT Database Backup, it's NOT a total loss! if ( is_wp_error($api_network_response) ) { wp_send_json_success('🎉 Registration captured securely on localized system storage grid! (Google Sync delayed).'); } // Success response wp_send_json_success('🎉 Registration processed! Data verified and synced over to Google Sheets.'); }