Changeset 3377264
- Timestamp:
- 10/13/2025 06:55:17 AM (6 months ago)
- Location:
- yournotify/trunk
- Files:
-
- 3 edited
-
includes/class-yournotify-optin.php (modified) (4 diffs)
-
readme.txt (modified) (1 diff)
-
yournotify.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
yournotify/trunk/includes/class-yournotify-optin.php
r3377258 r3377264 3 3 4 4 /** 5 * Shortcode: [yournotify_subscribe] 6 * - Fields: name (required), email (required), telephone (optional) 7 * - SUBMISSION: posts to hidden iframe target to prevent page navigation 8 * - Zero changes to SMTP, settings, or server handlers (keeps v2.0.2 logic) 5 * Shortcode: [yournotify_subscribe] — v2.0.7 patch 6 * - Adds hidden api_key + list_id fields (from saved options) to mirror v1.1.7 behavior 7 * - Keeps Name / Email / Telephone fields 8 * - Uses jQuery.ajax (with fetch fallback) to submit without navigation 9 * - Does NOT modify settings, SMTP, router, or handlers 9 10 */ 10 11 add_action('init', function(){ … … 18 19 ], $atts, 'yournotify_subscribe'); 19 20 20 $form_id = 'yn_sub_' . uniqid(); 21 $frame_id = $form_id . '_frame'; 22 $action = admin_url('admin-ajax.php'); 23 $nonce = wp_create_nonce('yournotify_subscribe'); 24 $redirect = get_option('yournotify_success_redirect',''); 21 $form_id = 'yn_sub_' . uniqid(); 22 $action = admin_url('admin-ajax.php'); 23 $nonce = wp_create_nonce('yournotify_subscribe'); 24 $redirect = get_option('yournotify_success_redirect',''); 25 25 26 // Hidden iframe sink 27 $html = '<iframe id="'.esc_attr($frame_id).'" name="'.esc_attr($frame_id).'" style="display:none;"></iframe>'; 26 // Pull saved creds to include exactly like v1.1.7 (frontend field) 27 $api_key = get_option('yournotify_api_key',''); 28 $list_id = get_option('yournotify_list_id',''); 28 29 29 // Form posts to the iframe (prevents full page navigation, even without JS) 30 $html .= '<form id="'.esc_attr($form_id).'" method="post" action="'.esc_url($action).'" class="yournotify-subscribe-form" target="'.esc_attr($frame_id).'" data-redirect="'.esc_attr($redirect).'" novalidate>'; 30 $html = '<form id="'.esc_attr($form_id).'" method="post" action="'.esc_url($action).'" class="yournotify-subscribe-form" data-redirect="'.esc_attr($redirect).'" novalidate>'; 31 31 $html .= '<input type="hidden" name="action" value="yournotify_subscribe_submit">'; 32 32 $html .= '<input type="hidden" name="_wpnonce" value="'.esc_attr($nonce).'">'; 33 34 // IMPORTANT: send jwt/api_key + list_id in the POST body (v1.1.7 style) 35 if ($api_key) { $html .= '<input type="hidden" name="api_key" value="'.esc_attr($api_key).'">'; } 36 if ($list_id) { $html .= '<input type="hidden" name="list_id" value="'.esc_attr($list_id).'">'; } 37 38 // Visible fields 33 39 $html .= '<p class="yn-field yn-name"><input type="text" name="name" required placeholder="'.esc_attr($atts['name_placeholder']).'"></p>'; 34 40 $html .= '<p class="yn-field yn-email"><input type="email" name="email" required placeholder="'.esc_attr($atts['email_placeholder']).'"></p>'; … … 38 44 $html .= '</form>'; 39 45 40 // Lightweight JS: when the iframe loads, parse JSON and show message. No fetch/XHR; server remains unchanged.46 // Submit via jQuery (like 2.0.0), with fetch fallback 41 47 $html .= '<script>(function(){' 42 .'var f=document.getElementById("'.esc_js($form_id).'"); '48 .'var f=document.getElementById("'.esc_js($form_id).'"); if(!f) return;' 43 49 .'var r=document.getElementById("'.esc_js($form_id).'_resp");' 44 .'var redir=f?f.getAttribute("data-redirect"):"";' 45 .'var i=document.getElementById("'.esc_js($frame_id).'");' 46 .'if(!i) return;' 47 .'i.addEventListener("load", function(){' 48 .'try {' 49 .'var d=i.contentDocument||i.contentWindow.document;' 50 .'var t=d && d.body ? d.body.textContent : "";' 51 .'if(!t){ if(r) r.textContent=""; return; }' 52 .'try{ var j=JSON.parse(t); }catch(e){ if(r) r.textContent=""; return; }' 53 .'if(j && j.success){ if(redir){ window.location = redir; return; } if(r){ r.textContent = (j.data && j.data.message) ? j.data.message : "'.esc_js(__('Subscribed','yournotify')).'"; } }' 54 .'else { if(r){ r.textContent = (j && j.data && j.data.message) ? j.data.message : "'.esc_js(__('Subscription failed. Please try again.','yournotify')).'"; } }' 55 .'} catch(e) { /* silent */ }' 50 .'var redir=f.getAttribute("data-redirect")||"";' 51 .'function ok(msg){ if(redir){window.location=redir;return;} if(r){r.textContent=msg||"'.esc_js(__('Subscribed','yournotify')).'";} }' 52 .'function fail(msg){ if(r){r.textContent=msg||"'.esc_js(__('Subscription failed. Please try again.','yournotify')).'";} }' 53 .'f.addEventListener("submit",function(e){ e.preventDefault(); if(r){r.textContent="'.esc_js(__('Sending…','yournotify')).'";}' 54 .'var fd=new FormData(f);' 55 .'if(window.jQuery){' 56 .'jQuery.ajax({url:f.action,method:"POST",data:fd,processData:false,contentType:false,success:function(j){try{if(typeof j==="string"){j=JSON.parse(j);} }catch(e){} if(j&&j.success){ok(j.data&&j.data.message);}else{fail(j&&j.data&&j.data.message);} },error:function(){fail();}});' 57 .'}else{' 58 .'fetch(f.action,{method:"POST",credentials:"same-origin",body:fd}).then(function(res){return res.json();}).then(function(j){ if(j&&j.success){ok(j.data&&j.data.message);}else{fail(j&&j.data&&j.data.message);} }).catch(function(){fail();});' 59 .'}' 56 60 .'});' 57 61 .'})();</script>'; … … 62 66 }); 63 67 64 /* Preserve server-side helpers if not already present (no changes to your existing ones) */68 /* Preserve server-side helpers if not present (no changes if you already have them) */ 65 69 if (!function_exists('yournotify__inject_required_fields')) { 66 70 function yournotify__inject_required_fields(){ -
yournotify/trunk/readme.txt
r3377258 r3377264 4 4 Requires at least: 4.6 5 5 Tested up to: 6.7 6 Stable tag: 2.0. 66 Stable tag: 2.0.7 7 7 License: GPLv3 or later 8 8 -
yournotify/trunk/yournotify.php
r3377258 r3377264 4 4 * Plugin URI: https://yournotify.com 5 5 * Description: Yournotify WP Plugin — Subscriber Form and SMTP override. 6 * Version: 2.0. 66 * Version: 2.0.7 7 7 * Author: Yournotify 8 8 * Author URI: https://yournotify.com
Note: See TracChangeset
for help on using the changeset viewer.