// --- ST. MARY MEMBERSHIP FORM EMAIL & DATABASE HANDLER (WITH PHOTO UPLOADS) --- // 1. Create a Secure Admin Menu for Membership Submissions add_action('init', 'st_mary_create_membership_post_type'); function st_mary_create_membership_post_type() { register_post_type('membership_entry', array( 'labels' => array( 'name' => 'Membership Forms', 'singular_name' => 'Membership Form', 'menu_name' => 'Membership Forms', 'all_items' => 'All Memberships' ), 'public' => false, 'show_ui' => true, 'menu_position' => 22, 'menu_icon' => 'dashicons-groups', 'supports' => array('title', 'editor') )); } // 2. Process the Form Submission & File Uploads add_action('wp_ajax_st_mary_submit_membership', 'handle_st_mary_membership_form'); add_action('wp_ajax_nopriv_st_mary_submit_membership', 'handle_st_mary_membership_form'); function handle_st_mary_membership_form() { $to = 'edmontonsailitemeheretpr@gmail.com'; // Build the Title / Subject $first_name = isset($_POST['first_name']) ? sanitize_text_field($_POST['first_name']) : ''; $last_name = isset($_POST['last_name']) ? sanitize_text_field($_POST['last_name']) : ''; $subject = 'New Membership Registration - ' . $first_name . ' ' . $last_name; // Build the HTML Table Body $message = '
'; $message .= ''; $message .= ''; // ACTION A: Save securely to the WordPress Database $post_id = wp_insert_post(array( 'post_title' => $subject, 'post_content' => $message, 'post_status' => 'private', 'post_type' => 'membership_entry' )); // ACTION B: Attempt to send the HTML Email $headers = array('Content-Type: text/html; charset=UTF-8'); wp_mail($to, $subject, $message, $headers); if ($post_id) { wp_send_json_success('Form saved successfully'); } else { wp_send_json_error('Form failed to save'); } } Skip to content