add_action('wp_ajax_insta_download', 'insta_download_handler'); add_action('wp_ajax_nopriv_insta_download', 'insta_download_handler'); function insta_download_handler() { check_ajax_referer('insta_dl_nonce', 'nonce'); if (empty($_POST['url'])) { wp_send_json_error('Instagram URL is required'); } $insta_url = esc_url_raw($_POST['url']); // 👉 Render API endpoint $api_url = 'https://insta-api-cxmq.onrender.com/api/download'; $response = wp_remote_post($api_url, [ 'headers' => [ 'Content-Type' => 'application/json' ], 'body' => json_encode([ 'url' => $insta_url ]), 'timeout' => 20 ]); if (is_wp_error($response)) { wp_send_json_error('API request failed'); } $body = wp_remote_retrieve_body($response); $data = json_decode($body, true); if (isset($data['download_url'])) { wp_send_json_success($data['download_url']); } else { wp_send_json_error('Download link not found'); } }