Plugin Directory

Changeset 3483496


Ignore:
Timestamp:
03/16/2026 07:18:36 AM (2 weeks ago)
Author:
yournotify
Message:

Release 2.1.6: normalize API integration to current endpoints

Location:
yournotify
Files:
38 added
8 edited

Legend:

Unmodified
Added
Removed
  • yournotify/trunk/admin-settings.php

    r3376881 r3483496  
    123123    }
    124124
    125     $lists = $body['data']['results'];
     125    $lists = isset($body['data']['results']) && is_array($body['data']['results']) ? $body['data']['results'] : (is_array($body['data']) ? $body['data'] : array());
    126126    $selected_list_id = get_option('yournotify_list_id');
    127127    ?>
  • yournotify/trunk/inc/yournotify-subscribe.php

    r2892073 r3483496  
    162162            $args = array(
    163163                'headers' => array(
    164                     'x-access-token' => sprintf( '%1$s', $api_key ),
     164                    'Authorization' => 'Bearer ' . $api_key,
    165165                ),
    166166            );
  • yournotify/trunk/includes/class-yournotify-automation.php

    r3242205 r3483496  
    8787        if ($current_step['type'] === 'email') {
    8888            $email = new Yournotify_Email();
    89             $email->send_email($current_step['to'], $current_step['subject'], $current_step['message']);
     89            $email->send_email(
     90                $current_step['name'] ?? $current_step['subject'] ?? 'Automation Email',
     91                $current_step['subject'] ?? 'Automation Email',
     92                $current_step['html'] ?? wpautop($current_step['message'] ?? ''),
     93                $current_step['text'] ?? ($current_step['message'] ?? ''),
     94                $current_step['status'] ?? 'running',
     95                get_option('yournotify_from_email'),
     96                $current_step['to'] ?? '',
     97                $current_step['recipient_name'] ?? '',
     98                $current_step['attribs'] ?? array()
     99            );
    90100        } elseif ($current_step['type'] === 'sms') {
    91101            $sms = new Yournotify_SMS();
    92             $sms->send_sms($current_step['to'], $current_step['message']);
     102            $sms->send_sms(
     103                $current_step['name'] ?? $current_step['subject'] ?? 'Automation SMS',
     104                $current_step['subject'] ?? '',
     105                $current_step['message'] ?? '',
     106                $current_step['status'] ?? 'running',
     107                get_option('yournotify_from_sender_id'),
     108                $current_step['to'] ?? '',
     109                $current_step['recipient_name'] ?? '',
     110                $current_step['attribs'] ?? array()
     111            );
    93112        }
    94113
  • yournotify/trunk/includes/class-yournotify-email.php

    r3242205 r3483496  
    11<?php
    22if (!defined('ABSPATH')) {
    3     exit; // Exit if accessed directly.
     3    exit;
    44}
    55
    66class Yournotify_Email {
    7     public function send_email($title, $subject, $html, $text, $status, $to, $name, $attribs) {
    8         $api_key = get_option('yournotify_api_key');
    9         $from_email = get_option('yournotify_from_email');
     7    public function send_email($title, $subject, $html, $text = '', $status = 'draft', $from = '', $to = null, $name = '', $attribs = array()) {
     8        $from_email = $from ?: get_option('yournotify_from_email');
     9        $recipient = is_array($to) ? $to : array(array(
     10            'email' => $to,
     11            'name' => $name,
     12            'attribs' => is_array($attribs) ? $attribs : array(),
     13        ));
    1014
    11         $body = array(
    12             'name' => $title,
    13             'subject' => $subject,
    14             'html' => $html,
    15             'text' => $text,
    16             'from' => $from_email,
    17             'status' => $status,
    18             'channel' => "email",
    19             'lists' => array(
    20                 (object)[
    21                     "email" => $to,
    22                     "name" => $name,
    23                     "attribs" => $attribs,
    24                 ]
    25             ),
     15        $payload = array(
     16            'name'       => $title,
     17            'subject'    => $subject,
     18            'html'       => $html,
     19            'body'       => $html,
     20            'text'       => $text,
     21            'from'       => $from_email,
     22            'from_email' => $from_email,
     23            'status'     => $status,
     24            'channel'    => 'email',
     25            'lists'      => $recipient,
    2626        );
    2727
    28         $response = wp_remote_post('https://api.yournotify.com/send-email', array(
    29             'method' => 'POST',
    30             'headers' => array(
    31                 'Authorization' => 'Bearer ' . $api_key,
    32                 'Content-Type' => 'application/json'
    33             ),
    34             'body' => json_encode($body)
    35         ));
    36 
     28        $response = Yournotify_API::request('campaigns/email', 'POST', $payload);
    3729        if (is_wp_error($response)) {
    3830            error_log('Email sending failed: ' . $response->get_error_message());
    3931            return false;
    4032        }
    41 
    42         $body = json_decode(wp_remote_retrieve_body($response), true);
    43         if (isset($body['success']) && $body['success']) {
     33        if (Yournotify_API::is_success($response)) {
    4434            return true;
    45         } else {
    46             error_log('Email sending failed: ' . wp_remote_retrieve_body($response));
    47             return false;
    4835        }
     36        error_log('Email sending failed: ' . wp_json_encode($response));
     37        return false;
    4938    }
    5039}
  • yournotify/trunk/includes/class-yournotify-sms.php

    r3242205 r3483496  
    11<?php
    22if (!defined('ABSPATH')) {
    3     exit; // Exit if accessed directly.
     3    exit;
    44}
    55
    66class Yournotify_SMS {
    7     public function send_sms($title, $subject, $text, $status, $to, $name, $attribs) {
    8         $api_key = get_option('yournotify_api_key');
    9         $from_sender_id = get_option('yournotify_from_sender_id');
     7    public function send_sms($title, $subject = '', $text = '', $status = 'draft', $from = '', $to = null, $name = '', $attribs = array()) {
     8        $sender = $from ?: get_option('yournotify_from_sender_id');
     9        $recipient = is_array($to) ? $to : array(array(
     10            'telephone' => $to,
     11            'name' => $name,
     12            'attribs' => is_array($attribs) ? $attribs : array(),
     13        ));
    1014
    11         $body = array(
    12             'name' => $title,
     15        $payload = array(
     16            'name'    => $title,
    1317            'subject' => $subject,
    14             'text' => $text,
    15             'from' => $from_sender_id,
    16             'status' => $status,
    17             'channel' => "sms",
    18             'lists' => array(
    19                 (object)[
    20                     "telephone" => $to,
    21                     "name" => $name,
    22                     "attribs" => $attribs,
    23                 ]
    24             ),
     18            'text'    => $text,
     19            'body'    => $text,
     20            'from'    => $sender,
     21            'sender'  => $sender,
     22            'status'  => $status,
     23            'channel' => 'sms',
     24            'lists'   => $recipient,
    2525        );
    2626
    27         $response = wp_remote_post('https://api.yournotify.com/send-sms', array(
    28             'method' => 'POST',
    29             'headers' => array(
    30                 'Authorization' => 'Bearer ' . $api_key,
    31                 'Content-Type' => 'application/json'
    32             ),
    33             'body' => json_encode($body)
    34         ));
    35 
     27        $response = Yournotify_API::request('campaigns/sms', 'POST', $payload);
    3628        if (is_wp_error($response)) {
    3729            error_log('SMS sending failed: ' . $response->get_error_message());
    3830            return false;
    3931        }
    40 
    41         $body = json_decode(wp_remote_retrieve_body($response), true);
    42         if (isset($body['success']) && $body['success']) {
     32        if (Yournotify_API::is_success($response)) {
    4333            return true;
    44         } else {
    45             error_log('SMS sending failed: ' . wp_remote_retrieve_body($response));
    46             return false;
    4734        }
     35        error_log('SMS sending failed: ' . wp_json_encode($response));
     36        return false;
    4837    }
    4938}
  • yournotify/trunk/includes/class-yournotify-subscription.php

    r3242205 r3483496  
    11<?php
    22if (!defined('ABSPATH')) {
    3     exit; // Exit if accessed directly.
     3    exit;
    44}
    55
    66class Yournotify_Subscription {
    77    public function add_contact($name, $email, $telephone, $selected_list_id = null) {
    8         $api_key = get_option('yournotify_api_key');
    98        if (is_null($selected_list_id)) {
    109            $selected_list_id = get_option('yournotify_list_id');
    1110        }
    1211
    13         $body = array(
    14             'name' => $name,
    15             'email' => $email,
     12        $payload = array(
     13            'name'      => $name,
     14            'email'     => $email,
    1615            'telephone' => $telephone,
    17             'lists' => array($selected_list_id)
     16            'lists'     => $selected_list_id ? array($selected_list_id) : array(),
    1817        );
    1918
    20         $response = wp_remote_post('https://api.yournotify.com/contacts', array(
    21             'method' => 'POST',
    22             'headers' => array(
    23                 'Authorization' => 'Bearer ' . $api_key,
    24                 'Content-Type' => 'application/json'
    25             ),
    26             'body' => json_encode($body)
    27         ));
    28 
     19        $response = Yournotify_API::request('contacts', 'POST', $payload);
    2920        if (is_wp_error($response)) {
    3021            error_log('Subscription failed: ' . $response->get_error_message());
    3122            return false;
    3223        }
    33 
    34         $body = json_decode(wp_remote_retrieve_body($response), true);
    35         if (isset($body['status']) && $body['status'] === "success") {
     24        if (Yournotify_API::is_success($response)) {
    3625            return true;
    37         } else {
    38             error_log('Subscription failed: ' . wp_remote_retrieve_body($response));
    39             return false;
    4026        }
     27        error_log('Subscription failed: ' . wp_json_encode($response));
     28        return false;
    4129    }
    4230}
  • yournotify/trunk/readme.txt

    r3383620 r3483496  
    44Requires at least: 4.6
    55Tested up to: 6.7
    6 Stable tag: 2.1.5
     6Stable tag: 2.1.6
    77License: GPLv3 or later
    88
     
    6666== Changelog ==
    6767
     68= 2.1.6 =
     69* Normalize plugin API calls to the current Yournotify endpoints.
     70* Add shared API client for bearer API-key requests.
     71* Fix automation/email/SMS helper compatibility with the current API surface.
     72
     73
    6874*Release Date - 23 May 2022*
    6975
  • yournotify/trunk/yournotify.php

    r3383620 r3483496  
    44 * Plugin URI: https://yournotify.com
    55 * Description: Yournotify WP Plugin — SMTP, Subscriber Form, Contact Form.
    6  * Version: 2.1.5
     6 * Version: 2.1.6
    77 * Author: Yournotify
    88 * Author URI: https://yournotify.com
     
    5858require_once __DIR__ . '/includes/class-yournotify-optin.php';
    5959require_once __DIR__ . '/includes/class-yournotify-contact.php';
     60require_once __DIR__ . '/includes/class-yournotify-api.php';
    6061// Activation hook for DB tables
    6162if (function_exists('register_activation_hook')) {
Note: See TracChangeset for help on using the changeset viewer.