// ============================= // SH-SARTORE ESCROW CORE LOGIC // ============================= // 1. Set Custom Email Sender add_filter('wp_mail_from', fn() => 'admin@sh-sartore.com'); add_filter('wp_mail_from_name', fn() => 'Shโ€‘Sartore Escrow System'); // 2. Load CSS & JS Assets function enqueue_escrow_assets() { wp_enqueue_style('escrow-style', get_template_directory_uri() . '/css/dark-glass-theme.css'); if (is_page_template('page-templates/escrow-form.php')) { wp_enqueue_script('escrow-ajax', get_template_directory_uri() . '/js/escrow-ajax.js', ['jquery'], null, true); wp_localize_script('escrow-ajax', 'escrowAjax', [ 'ajax_url' => admin_url('admin-ajax.php'), 'escrow_nonce' => wp_create_nonce('escrow_ajax_nonce') ]); } if (is_page_template('page-templates/complete-escrow.php')) { wp_enqueue_script('wallet-status', get_template_directory_uri() . '/js/wallet-status.js', ['jquery'], null, true); wp_localize_script('wallet-status', 'walletAjax', [ 'ajax_url' => admin_url('admin-ajax.php'), 'escrow_nonce' => wp_create_nonce('escrow_ajax_nonce') ]); } } add_action('wp_enqueue_scripts', 'enqueue_escrow_assets'); // 3. Register Custom Post Types add_action('init', function () { register_post_type('escrow_deal', [ 'labels' => ['name' => 'Escrow Deals'], 'public' => true, 'show_in_menu' => true, 'supports' => ['title'] ]); register_post_type('escrow_review', [ 'labels' => ['name' => 'Escrow Reviews'], 'public' => false, 'show_ui' => true, 'menu_icon' => 'dashicons-format-status', 'supports' => ['title', 'editor', 'custom-fields'] ]); register_post_type('escrow_dispute', [ 'labels' => ['name' => 'Escrow Disputes'], 'public' => false, 'show_ui' => true, 'menu_icon' => 'dashicons-warning', 'supports' => ['title', 'editor', 'custom-fields'] ]); }); // 4. Submit Escrow via AJAX (with debug + email + redirect) add_action('wp_ajax_submit_escrow_ajax', 'submit_escrow_ajax'); add_action('wp_ajax_nopriv_submit_escrow_ajax', 'submit_escrow_ajax'); function submit_escrow_ajax() { check_ajax_referer('escrow_ajax_nonce', 'escrow_nonce'); $debug = []; $deal_id = wp_insert_post([ 'post_title' => sanitize_text_field($_POST['deal_title']), 'post_type' => 'escrow_deal', 'post_status'=> 'publish', ]); if (!$deal_id) { wp_send_json_error(['message' => 'โŒ Failed to create deal.']); } $debug[] = "โœ… Deal created with ID: $deal_id"; $fields = [ 'deal_type', 'currency', 'fee_payer', 'due_date', 'inspection_period', 'item_name', 'price', 'description', 'shipping', 'buyer_phone' ]; foreach ($fields as $field) { $value = sanitize_text_field($_POST[$field] ?? ''); update_post_meta($deal_id, $field, $value); $debug[] = "๐Ÿ“ Meta saved: $field = $value"; } $buyer_email = sanitize_email($_POST['buyer_email']); $seller_email = sanitize_email($_POST['seller_email']); $price = floatval($_POST['price']); $fee = round($price * 0.05, 2); $total = $price + $fee; update_post_meta($deal_id, 'buyer_email', $buyer_email); update_post_meta($deal_id, 'seller_email', $seller_email); update_post_meta($deal_id, 'escrow_fee', $fee); update_post_meta($deal_id, 'buyer_pays', $total); update_post_meta($deal_id, 'seller_receives', $price); update_post_meta($deal_id, 'escrow_status', 'pending'); $debug[] = "๐Ÿ’ฐ Amounts stored: price=$price fee=$fee total=$total"; $link = esc_url(site_url("/complete-escrow/?id=$deal_id")); $subject = '๐Ÿ” New Escrow Deal Submitted'; $headers = ['Content-Type: text/html; charset=UTF-8']; $body = "

๐Ÿš€ Escrow Deal Details

Transaction: {$_POST['deal_title']}

Item: {$_POST['item_name']}

Currency: {$_POST['currency']}

Amount: \${$price} + Fee \${$fee} = \${$total}

Buyer: $buyer_email

Seller: $seller_email

๐Ÿ”— Complete or View Escrow Deal

Powered by Shโ€‘Sartore Escrow โ€” Visit Website

"; $recipients = [$buyer_email, $seller_email, get_option('admin_email')]; $sent = wp_mail($recipients, $subject, $body, $headers); $debug[] = $sent ? '๐Ÿ“ง Email sent successfully' : 'โŒ Email sending failed'; // Debug log to admin wp_mail(get_option('admin_email'), '๐Ÿ› ๏ธ Escrow Debug Log', implode("\n", $debug), ['Content-Type: text/plain']); wp_send_json_success(['redirect' => $link]); } // 5. Payment Verification add_action('wp_ajax_verify_payment_callback', 'verify_payment_callback'); add_action('wp_ajax_nopriv_verify_payment_callback', 'verify_payment_callback'); function verify_payment_callback() { check_ajax_referer('escrow_ajax_nonce', 'escrow_nonce'); $deal_id = intval($_POST['deal_id']); update_post_meta($deal_id, 'tx_hash', sanitize_text_field($_POST['tx_hash'])); update_post_meta($deal_id, 'escrow_status', 'paid'); update_post_meta($deal_id, 'payment_verified', true); update_post_meta($deal_id, 'payment_verified_at', current_time('mysql')); wp_send_json_success(['message' => 'โœ… Payment confirmed.']); } // 6. Wallet Getter function get_wallet_address($currency) { switch (strtoupper($currency)) { case 'BTC': return get_option('escrow_wallet_btc', ''); case 'ETH': return get_option('escrow_wallet_eth', ''); case 'USDT-ERC20': return get_option('escrow_wallet_usdt_erc20', ''); case 'USDT-TRC20': return get_option('escrow_wallet_usdt_trc20', ''); default: return ''; } } https://sh-sartore.com/wp-sitemap-posts-post-1.xmlhttps://sh-sartore.com/wp-sitemap-posts-page-1.xmlhttps://sh-sartore.com/wp-sitemap-taxonomies-category-1.xmlhttps://sh-sartore.com/wp-sitemap-users-1.xml