Plugin Directory

Changeset 3377264


Ignore:
Timestamp:
10/13/2025 06:55:17 AM (6 months ago)
Author:
yournotify
Message:

v2.0.7: stable release (Subscriber Form + SMTP tabs, fixed save, preconfigured smtp.yournotify.com:587 TLS).

Location:
yournotify/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • yournotify/trunk/includes/class-yournotify-optin.php

    r3377258 r3377264  
    33
    44/**
    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
    910 */
    1011add_action('init', function(){
     
    1819      ], $atts, 'yournotify_subscribe');
    1920
    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','');
    2525
    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','');
    2829
    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>';
    3131      $html .= '<input type="hidden" name="action" value="yournotify_subscribe_submit">';
    3232      $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
    3339      $html .= '<p class="yn-field yn-name"><input type="text" name="name" required placeholder="'.esc_attr($atts['name_placeholder']).'"></p>';
    3440      $html .= '<p class="yn-field yn-email"><input type="email" name="email" required placeholder="'.esc_attr($atts['email_placeholder']).'"></p>';
     
    3844      $html .= '</form>';
    3945
    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
    4147      $html .= '<script>(function(){'
    42         .'var f=document.getElementById("'.esc_js($form_id).'");'
     48        .'var f=document.getElementById("'.esc_js($form_id).'"); if(!f) return;'
    4349        .'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          .'}'
    5660        .'});'
    5761      .'})();</script>';
     
    6266});
    6367
    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) */
    6569if (!function_exists('yournotify__inject_required_fields')) {
    6670  function yournotify__inject_required_fields(){
  • yournotify/trunk/readme.txt

    r3377258 r3377264  
    44Requires at least: 4.6
    55Tested up to: 6.7
    6 Stable tag: 2.0.6
     6Stable tag: 2.0.7
    77License: GPLv3 or later
    88
  • yournotify/trunk/yournotify.php

    r3377258 r3377264  
    44 * Plugin URI: https://yournotify.com
    55 * Description: Yournotify WP Plugin — Subscriber Form and SMTP override.
    6  * Version: 2.0.6
     6 * Version: 2.0.7
    77 * Author: Yournotify
    88 * Author URI: https://yournotify.com
Note: See TracChangeset for help on using the changeset viewer.