Plugin Directory

Changeset 3377250


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

v2.0.5: 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

    r3377124 r3377250  
    22if (!defined('ABSPATH')) exit;
    33
    4 /** Shortcode: [yournotify_subscribe] — AJAX, no page redirect */
     4/**
     5 * Shortcode: [yournotify_subscribe]
     6 * - Fields: name (required), email (required), telephone (optional)
     7 * - AJAX submit with jQuery (matches v2.0.0 behavior), fetch() fallback
     8 * - Does NOT alter settings, SMTP, or other plugin behavior
     9 */
    510add_action('init', function(){
    611  if (!shortcode_exists('yournotify_subscribe')) {
     
    1318      ], $atts, 'yournotify_subscribe');
    1419
    15       // Safer IDs and values
    16       $action   = admin_url('admin-ajax.php');
    17       $nonce    = wp_create_nonce('yournotify_subscribe');
    18       $form_id  = 'yn_sub_' . uniqid(); // avoid any dependency
     20      $form_id = 'yn_sub_' . uniqid();
     21      $action  = admin_url('admin-ajax.php');
     22      $nonce   = wp_create_nonce('yournotify_subscribe');
    1923      $redirect = get_option('yournotify_success_redirect','');
    2024
     
    2226      $html .= '<input type="hidden" name="action" value="yournotify_subscribe_submit">';
    2327      $html .= '<input type="hidden" name="_wpnonce" value="'.esc_attr($nonce).'">';
    24 
    25       // Name (required)
    26       $html .= '<p><input type="text" name="name" required placeholder="'.esc_attr($atts['name_placeholder']).'"></p>';
    27 
    28       // Email (required)
    29       $html .= '<p><input type="email" name="email" required placeholder="'.esc_attr($atts['email_placeholder']).'"></p>';
    30 
    31       // Telephone (optional)
    32       $html .= '<p><input type="tel" name="telephone" placeholder="'.esc_attr($atts['tel_placeholder']).'"></p>';
    33 
    34       $html .= '<p><button type="submit">'.esc_html($atts['button_text']).'</button></p>';
     28      $html .= '<p class="yn-field yn-name"><input type="text" name="name" required placeholder="'.esc_attr($atts['name_placeholder']).'"></p>';
     29      $html .= '<p class="yn-field yn-email"><input type="email" name="email" required placeholder="'.esc_attr($atts['email_placeholder']).'"></p>';
     30      $html .= '<p class="yn-field yn-telephone"><input type="tel" name="telephone" placeholder="'.esc_attr($atts['tel_placeholder']).'"></p>';
     31      $html .= '<p class="yn-actions"><button type="submit">'.esc_html($atts['button_text']).'</button></p>';
    3532      $html .= '<div class="yournotify-response" id="'.esc_attr($form_id).'_resp" aria-live="polite" style="margin-top:6px;"></div>';
    3633      $html .= '</form>';
    3734
    38       // Minimal JS: intercept submit, POST via fetch, show message inline
    39       $html .= '<script>(function(){try{'
     35      // Submit: prefer jQuery.ajax like v2.0.0; fallback to fetch
     36      $html .= '<script>(function(){'
    4037        .'var f=document.getElementById("'.esc_js($form_id).'"); if(!f) return;'
    4138        .'var r=document.getElementById("'.esc_js($form_id).'_resp");'
    4239        .'var redir=f.getAttribute("data-redirect")||"";'
    43         .'f.addEventListener("submit",function(e){e.preventDefault();'
    44           .'if(r) r.textContent="'.esc_js(__('Sending…','yournotify')).'";'
     40        .'function ok(msg){ if(redir){window.location=redir;return;} if(r){r.textContent=msg||"'.esc_js(__('Subscribed','yournotify')).'";} }'
     41        .'function fail(msg){ if(r){r.textContent=msg||"'.esc_js(__('Subscription failed. Please try again.','yournotify')).'";} }'
     42        .'f.addEventListener("submit",function(e){ e.preventDefault(); if(r){r.textContent="'.esc_js(__('Sending…','yournotify')).'";}'
    4543          .'var fd=new FormData(f);'
    46           .'fetch(f.action,{method:"POST",credentials:"same-origin",body:fd})'
    47             .'.then(function(res){return res.json();})'
    48             .'.then(function(j){'
    49               .'if(j&&j.success){ if(redir){window.location=redir;return;}'
    50               .'r.textContent=(j.data&&j.data.message)?j.data.message:"'.esc_js(__('Subscribed','yournotify')).'";}'
    51               .'else{ var msg=(j&&j.data&&j.data.message)?j.data.message:"'.esc_js(__('Subscription failed. Please try again.','yournotify')).'"; r.textContent=msg; }'
    52             .'})'
    53             .'.catch(function(){ if(r) r.textContent="'.esc_js(__('Request failed. Please try again.','yournotify')).'"; });'
     44          .'if(window.jQuery){'
     45            .'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();}});'
     46          .'}else{'
     47            .'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();});'
     48          .'}'
    5449        .'});'
    55       .'}catch(e){/* noop */}})();</script>';
     50      .'})();</script>';
    5651
    5752      return $html;
     
    5954  }
    6055});
     56
     57/**
     58 * Keep existing server-side behavior:
     59 * - yournotify__inject_required_fields (api_key, list_id)
     60 * - yournotify__normalize_submit_fields (telephone -> phone)
     61 * - yournotify_subscribe_submit handlers
     62 *
     63 * If these helpers do not exist in your build, add them below (no-op otherwise).
     64 */
     65if (!function_exists('yournotify__inject_required_fields')) {
     66  function yournotify__inject_required_fields(){
     67    if (empty($_POST['list_id'])) {
     68      $lid = get_option('yournotify_list_id','');
     69      if ($lid) $_POST['list_id'] = $lid;
     70    }
     71    if (empty($_POST['api_key'])) {
     72      $k = get_option('yournotify_api_key','');
     73      if ($k) $_POST['api_key'] = $k;
     74    }
     75  }
     76  add_action('wp_ajax_yournotify_subscribe_submit', 'yournotify__inject_required_fields', 1);
     77  add_action('wp_ajax_nopriv_yournotify_subscribe_submit', 'yournotify__inject_required_fields', 1);
     78}
     79
     80if (!function_exists('yournotify__normalize_submit_fields')) {
     81  function yournotify__normalize_submit_fields(){
     82    if (!empty($_POST['telephone']) && empty($_POST['phone'])) {
     83      $_POST['phone'] = $_POST['telephone'];
     84    }
     85    if (isset($_POST['name']))  $_POST['name']  = sanitize_text_field($_POST['name']);
     86    if (isset($_POST['email'])) $_POST['email'] = sanitize_email($_POST['email']);
     87    if (isset($_POST['telephone'])) $_POST['telephone'] = preg_replace('/[^0-9+\-\s\(\)]/', '', $_POST['telephone']);
     88    if (isset($_POST['phone']))     $_POST['phone']     = preg_replace('/[^0-9+\-\s\(\)]/', '', $_POST['phone']);
     89  }
     90  add_action('wp_ajax_yournotify_subscribe_submit', 'yournotify__normalize_submit_fields', 2);
     91  add_action('wp_ajax_nopriv_yournotify_subscribe_submit', 'yournotify__normalize_submit_fields', 2);
     92}
  • yournotify/trunk/readme.txt

    r3377124 r3377250  
    44Requires at least: 4.6
    55Tested up to: 6.7
    6 Stable tag: 2.0.4
     6Stable tag: 2.0.5
    77License: GPLv3 or later
    88
  • yournotify/trunk/yournotify.php

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