{\rtf1\ansi\ansicpg1252\cocoartf2822 \cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;} {\colortbl;\red255\green255\blue255;} {\*\expandedcolortbl;;} \paperw11900\paperh16840\margl1440\margr1440\vieww11520\viewh8400\viewkind0 \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0 \f0\fs24 \cf0

Settings saved.

';\ \});\ \}\ \}\ add_action('admin_init', 'tubeline_save_settings');\ \ function tubeline_send_email($to, $subject, $email_html) \{\ $sent = false;\ if (class_exists('\\\\MailPoet\\\\API\\\\API')) \{\ try \{\ $mailpoet_api = \\MailPoet\\API\\API::MP('v1');\ $mailpoet_api->sendTransactionalEmail([\ 'to' => [$to],\ 'subject' => $subject,\ 'body' => $email_html\ ]);\ $sent = true;\ \} catch (\\Throwable $e) \{\ $sent = wp_mail($to, $subject, $email_html, ["Content-Type: text/html; charset=UTF-8"]);\ \}\ \} else \{\ $sent = wp_mail($to, $subject, $email_html, ["Content-Type: text/html; charset=UTF-8"]);\ \}\ return $sent;\ \}\ \ function tubeline_email_sender_page() \{\ if (!current_user_can('manage_woocommerce')) \{\ wp_die('Sorry, you do not have access to this page.');\ \}\ $default_template = get_option('tubeline_default_template');\ if (!$default_template) \{\ $default_template = '
\

Hi \{first_name\},

\

Thanks again for your order!

\ \{video_block\}\ \{custom_message_block\}\

Kind regards,

\

Ben

\
';\ \}\ // FIX: Correct retrieval of saved default subject\ $default_subject = get_option('tubeline_default_subject') ?: 'A Personal Video For You!';\ \ if (isset($_POST['tubeline_send_email'])) \{\ $order_id = intval($_POST['order_id']);\ $youtube_link = sanitize_text_field($_POST['youtube_link']);\ $custom_message = sanitize_text_field($_POST['custom_message']);\ $email_template = stripslashes($_POST['email_template'] ?: $default_template);\ $email_subject = sanitize_text_field($_POST['email_subject'] ?: $default_subject);\ \ $order = wc_get_order($order_id);\ if ($order) \{\ $to = $order->get_billing_email();\ $first_name = $order->get_billing_first_name() ?: 'there';\ \ preg_match('/https:\\/\\/(?:www\\.)?(?:youtube\\.com|youtu\\.be)\\/[^\\s]+/', $youtube_link, $matches);\ $youtube_url = $matches[0] ?? null;\ $thumbnail = null;\ if ($youtube_url && preg_match('/(?:v=|\\/)([0-9A-Za-z_-]\{11\})/', $youtube_url, $vid_match)) \{\ $video_id = $vid_match[1];\ $thumbnail = "https://img.youtube.com/vi/\{$video_id\}/hqdefault.jpg";\ \}\ \ $video_block = '';\ if ($youtube_url && $thumbnail) \{\ $video_block = '\

Here\'92s a short video I recorded just for you:

\ Mars-Tronic Logo\
\ \ Watch Video\ \ ';\ \}\ \ $custom_message_block = '';\ if (!empty($custom_message)) \{\ $custom_message_block = '
' . esc_html($custom_message) . '
';\ \}\ \ $email_html = str_replace(\ ['\{first_name\}', '\{video_block\}', '\{custom_message_block\}'],\ [esc_html($first_name), $video_block, $custom_message_block],\ $email_template\ );\ \ $sent = tubeline_send_email($to, $email_subject, $email_html);\ \ if ($sent) \{\ echo '

Email sent successfully to ' . esc_html($to) . '.

';\ \} else \{\ echo '

Email failed to send.

';\ \}\ \}\ \}\ \ $orders = wc_get_orders(['limit' => 25, 'orderby' => 'date', 'order' => 'DESC']);\ ?>\
\

\ \ Tubeline: Send Personal Video Email\

\
\