Plugin Directory

Changeset 3198711


Ignore:
Timestamp:
11/28/2024 09:36:43 AM (15 months ago)
Author:
notificationmaster
Message:

version 1.4.7

Location:
notification-master
Files:
1043 added
2 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • notification-master/trunk/includes/class-plugin.php

    r3158511 r3198711  
    1717use Notification_Master\WebPush\Loader as WebPush_Loader;
    1818use Notification_Master\Connections\Process as Connections_Process;
     19use Notification_Master\WebPush\Background_Process as WebPush_Background_Process;
     20use Notification_Master\Email\Background_Process as Email_Background_Process;
    1921use Notification_Master\Logger;
    2022use Notification_Master\Notification_Logger;
     
    138140        // Load webpush class.
    139141        WebPush_Loader::get_instance();
     142        // Load webpush background process class.
     143        WebPush_Background_Process::get_instance();
     144        // Load email background process class.
     145        Email_Background_Process::get_instance();
    140146
    141147        // Load logger class.
  • notification-master/trunk/includes/class-utils.php

    r3144651 r3198711  
    251251        return json_decode( wp_json_encode( $array ) );
    252252    }
     253
     254    /**
     255     * Enqueue async action.
     256     *
     257     * @since 1.4.6
     258     *
     259     * @param string $action Action.
     260     * @param array  $args Args.
     261     *
     262     * @return void
     263     */
     264    public static function enqueue_async_action( $action, $args ) {
     265        $option_name = "ntfm_background_process_{$action}_" . bin2hex( random_bytes( 10 ) );
     266        $updated     = update_option(
     267            $option_name,
     268            $args,
     269            false
     270        );
     271
     272        if ( $updated ) {
     273            as_enqueue_async_action(
     274                "notification_master_{$action}_process",
     275                array(
     276                    'option_name' => $option_name,
     277                ),
     278                "ntfm_background_process_{$action}",
     279                false
     280            );
     281        }
     282    }
     283
     284    /**
     285     * Get action hook name.
     286     *
     287     * @since 1.4.6
     288     *
     289     * @param string $action Action.
     290     *
     291     * @return string
     292     */
     293    public static function get_action_hook( $action ) {
     294        return "notification_master_{$action}_process";
     295    }
    253296}
  • notification-master/trunk/includes/connections/class-process.php

    r3189998 r3198711  
    1414use Notification_Master\Abstracts\Trigger;
    1515use Notification_Master\Settings;
    16 use Notification_Master\Background_Process;
     16use Notification_Master\Utils;
     17
     18use function Notification_Master\Notification_Master;
    1719
    1820/**
     
    2426
    2527    /**
    26      * Background tasks.
     28     * Action name.
    2729     *
    28      * @var Background_Process
     30     * @since 1.4.6
     31     *
     32     * @var string
    2933     */
    30     protected $background_tasks;
     34    public $action_name = 'connections';
    3135
    3236    /**
     
    6064     */
    6165    private function __construct() {
    62         $this->background_tasks = new Background_Process();
     66        $hook = Utils::get_action_hook( $this->action_name );
     67        // Process connection.
     68        add_action( $hook, array( $this, 'process_async_connections' ), 10, 1 );
    6369    }
    6470
     
    7884
    7985        if ( $background_process ) {
    80             $this->background_tasks->push_to_queue( array( $connections, $trigger, $notification_id ) );
    81             $this->background_tasks->save()->dispatch();
     86            $args = array(
     87                'connections'     => $connections,
     88                'trigger'         => $trigger,
     89                'notification_id' => $notification_id,
     90            );
     91
     92            Utils::enqueue_async_action( $this->action_name, $args );
    8293            return;
    8394        }
     
    126137        }
    127138    }
     139
     140    /**
     141     * Process async connections.
     142     *
     143     * @since 1.4.6
     144     *
     145     * @param string $option_name Option name.
     146     *
     147     * @return void
     148     */
     149    public function process_async_connections( $option_name ) {
     150        $option = get_option( $option_name );
     151        if ( ! $option ) {
     152            Notification_Master()->logger->error(
     153                'async_process_connections_option_not_found',
     154                array(
     155                    'option_name' => $option_name,
     156                )
     157            );
     158            return;
     159        }
     160
     161        $connections     = $option['connections'];
     162        $trigger         = $option['trigger'];
     163        $notification_id = $option['notification_id'];
     164
     165        $this->process( $connections, $trigger, $notification_id );
     166
     167        delete_option( $option_name );
     168    }
    128169}
  • notification-master/trunk/includes/db/models/class-logs-model.php

    r3158511 r3198711  
    140140        global $wpdb;
    141141
     142        // Check if table exists.
     143        if ( ! $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ntfm_logs'" ) ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- No caching needed.
     144            return;
     145        }
     146
    142147        $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}ntfm_logs WHERE created_at < %s", $date ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- No caching needed.
    143148    }
  • notification-master/trunk/includes/db/models/class-notification-logs-model.php

    r3158511 r3198711  
    160160        global $wpdb;
    161161
     162        // Check if table exists.
     163        if ( ! $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}ntfm_notification_logs'" ) ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- No caching needed.
     164            return;
     165        }
     166
    162167        $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}ntfm_notification_logs WHERE created_at < %s", $date ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- No caching needed.
    163168    }
  • notification-master/trunk/includes/integrations/class-email-integration.php

    r3189998 r3198711  
    1414use Notification_Master\Abstracts\Integration;
    1515use Notification_Master\Users\Users;
     16use Notification_Master\Utils;
     17use Notification_Master\Triggers\Loader as Triggers_Loader;
    1618
    1719use function Notification_Master\Notification_Master;
     
    185187        $message         = $this->attributes['message'];
    186188
    187         $headers = array(
    188             'Content-Type: text/html; charset=UTF-8',
    189         );
    190 
    191         if ( empty( $emails ) ) {
    192             Notification_Master()->notification_logger->error(
    193                 $this->slug,
    194                 $this->prepare_response(
    195                     array(
    196                         'message' => __( 'No emails found.', 'notification-master' ),
    197                         'emails'  => $emails,
    198                         'subject' => $subject,
    199                         'body'    => $message,
    200                         'headers' => $headers,
    201                     )
    202                 )
    203             );
    204             return;
    205         }
    206 
    207         $this->send_notification( $emails, $subject, $message, $headers );
     189        $this->process_batch(
     190            array(
     191                'emails'        => $emails,
     192                'current_index' => 0,
     193                'subject'       => $subject,
     194                'message'       => $message,
     195                'args'          => array(
     196                    'notification_name' => $this->notification_name,
     197                    'trigger'           => $this->trigger->get_slug(),
     198                ),
     199            )
     200        );
    208201    }
    209202
     
    255248        // Do action after send email.
    256249        do_action( 'notification_master_after_send_email', $result, $emails, $subject, $message, $headers );
     250    }
     251
     252    /**
     253     * Process patch.
     254     *
     255     * @since 1.4.6
     256     *
     257     * @param array $data Data.
     258     *
     259     * @return void
     260     */
     261    public function process_batch( $data ) {
     262        $emails        = $data['emails'] ?? array();
     263        $current_index = $data['current_index'] ?? 0;
     264        $subject       = $data['subject'];
     265        $message       = $data['message'];
     266        $args          = $data['args'] ?? array();
     267
     268        if ( empty( $emails ) || empty( $subject ) || empty( $message ) || empty( $args ) ) {
     269            return;
     270        }
     271
     272        if ( ! $this->notification_name ) {
     273            $this->notification_name = $args['notification_name'];
     274        }
     275
     276        if ( ! $this->trigger ) {
     277            $this->trigger = Triggers_Loader::get_instance()->get_trigger( $args['trigger'] );
     278        }
     279
     280        $headers = array(
     281            'Content-Type: text/html; charset=UTF-8',
     282        );
     283
     284        $emails_chunk = array_slice( $emails, $current_index, 10 );
     285        foreach ( $emails_chunk as $email ) {
     286            $this->send_notification( $email, $subject, $message, $headers );
     287            ++$current_index;
     288        }
     289
     290        if ( $current_index < count( $emails ) ) {
     291            $data['current_index'] = $current_index;
     292            Utils::enqueue_async_action( $this->slug, $data );
     293        }
    257294    }
    258295
  • notification-master/trunk/includes/integrations/class-webpush-integration.php

    r3170169 r3198711  
    1717use Notification_Master\DB\Models\Subscription_Model;
    1818use Notification_Master\Settings;
    19 use Notification_Master\WebPush\Background_Process;
    2019use Notification_Master\WebPush\Loader as WebPush_Loader;
     20use Notification_Master\Triggers\Loader as Triggers_Loader;
     21use Notification_Master\Utils;
    2122
    2223use function Notification_Master\Notification_Master;
     
    5354     */
    5455    public $description = 'Send your notifications to WebPush.';
    55 
    56     /**
    57      * Background tasks.
    58      *
    59      * @var Background_Process
    60      */
    61     protected $background_tasks;
    62 
    63     /**
    64      * Constructor.
    65      *
    66      * @since 1.0.0
    67      */
    68     public function __construct() {
    69         parent::__construct();
    70 
    71         $this->background_tasks = new Background_Process();
    72         add_action( 'notification_master_process_webpush_notification', array( $this, 'process_batch' ), 10, 4 );
    73     }
    7456
    7557    /**
     
    154136     */
    155137    public function send_notification( $title, $message, $icon, $image, $url, $urgency ) {
    156         $this->process_batch(
    157             array(
     138        $args = array(
     139            'notification' => array(
    158140                'title'   => $title,
    159141                'message' => $message,
     
    163145                'urgency' => $urgency,
    164146            ),
    165             1,
    166             $this->trigger,
    167             $this->notification_name
     147            'page'         => 1,
     148            'args'         => array(
     149                'trigger'           => $this->trigger->get_slug(),
     150                'notification_name' => $this->notification_name,
     151            ),
    168152        );
     153        $this->process_batch( $args );
    169154    }
    170155
     
    174159     * @since 1.2.1
    175160     *
    176      * @param array   $notification Notification.
    177      * @param int     $page         Page.
    178      * @param Trigger $trigger     Trigger.
    179      * @param string  $notification_name Notification name.
     161     * @param array $data|string $data Args.
    180162     *
    181163     * @return void
    182164     */
    183     public function process_batch( $notification, $page, $trigger, $notification_name ) {
     165    public function process_batch( $data ) {
     166        $notification = $data['notification'] ?? array();
     167        $page         = $data['page'] ?? 1;
     168        $args         = $data['args'] ?? array();
     169        if ( empty( $notification ) || empty( $args ) ) {
     170            return;
     171        }
     172
    184173        if ( ! $this->trigger ) {
    185             $this->trigger = $trigger;
     174            $this->trigger = Triggers_Loader::get_instance()->get_trigger( $args['trigger'] );
    186175        }
    187176
    188177        if ( ! $this->notification_name ) {
    189             $this->notification_name = $notification_name;
     178            $this->notification_name = $args['notification_name'];
    190179        }
    191180
     
    199188
    200189        $subscriptions = Subscription_Model::get_rows( $limit, $page, 'subscribed' );
    201         $auth          = array(
     190        if ( empty( $subscriptions ) ) {
     191            return;
     192        }
     193
     194        $auth = array(
    202195            'VAPID' => array(
    203196                'subject'    => home_url(),
     
    279272        $count = Subscription_Model::get_count();
    280273        if ( $count > ( $page * $limit ) ) {
    281             $this->background_tasks->push_to_queue( array( $notification, $page + 1, $trigger, $notification_name ) );
    282             $this->background_tasks->save()->dispatch();
     274            $data['page'] = $page + 1;
     275            Utils::enqueue_async_action( $this->slug, $data );
    283276        }
    284277    }
  • notification-master/trunk/includes/webpush/class-background-process.php

    r3151000 r3198711  
    55 * @package notification-master
    66 *
    7  * @since 1.4.0
     7 * @since 1.4.6
    88 */
    99
    1010namespace Notification_Master\WebPush;
    1111
    12 use Notification_Master\Libraries\WP_Background_Processing\WP_Background_Process;
     12use Notification_Master\Utils;
     13use Notification_Master\Integrations\Loader as Integrations_Loader;
    1314
    1415/**
    1516 * Background Process class.
    1617 */
    17 class Background_Process extends WP_Background_Process {
     18class Background_Process {
    1819
    1920    /**
    20      * Action
     21     * Action name.
     22     *
     23     * @since 1.4.6
    2124     *
    2225     * @var string
    2326     */
    24     protected $action = 'ntfm_web_background_process';
     27    public $action_name = 'webpush';
    2528
    2629    /**
    27      * Really long running process
     30     * Instance of this class.
    2831     *
    29      * @return int
     32     * @since 1.4.6
     33     *
     34     * @var Background_Process
    3035     */
    31     public function really_long_running_task() {
    32         return sleep( 5 );
     36    private static $instance;
     37
     38    /**
     39     * Get instance of this class.
     40     *
     41     * @since 1.4.6
     42     *
     43     * @return Background_Process
     44     */
     45    public static function get_instance() {
     46        if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Background_Process ) ) {
     47            self::$instance = new Background_Process();
     48        }
     49
     50        return self::$instance;
    3351    }
    3452
    3553    /**
    36      * Task
     54     * Constructor.
    3755     *
    38      * @param mixed $item
    39      *
    40      * @return mixed
     56     * @since 1.4.6
    4157     */
    42     protected function task( $item ) {
    43         if ( ! empty( $item ) ) {
    44             $this->really_long_running_task();
    45             list( $notification, $page, $trigger, $notification_name ) = $item;
    46 
    47             if ( empty( $notification ) ) {
    48                 return false;
    49             }
    50 
    51             do_action( 'notification_master_process_webpush_notification', $notification, $page, $trigger, $notification_name );
    52         }
    53 
    54         return false;
     58    private function __construct() {
     59        $hook = Utils::get_action_hook( $this->action_name );
     60        add_action( $hook, array( $this, 'process_batch' ) );
    5561    }
    5662
    5763    /**
    58      * Complete
     64     * Process batch.
     65     *
     66     * @since 1.4.6
     67     *
     68     * @param string $option_name Option name.
    5969     *
    6070     * @return void
    6171     */
    62     protected function complete() {
    63         parent::complete();
     72    public function process_batch( $option_name ) {
     73        $data    = get_option( $option_name, array() );
     74        $webpush = Integrations_Loader::get_instance()->get_integration( 'webpush' );
     75        $webpush->process_batch( $data );
     76        delete_option( $option_name );
    6477    }
    6578}
  • notification-master/trunk/languages/notification-master.pot

    r3189998 r3198711  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Notification Master 1.4.6\n"
     5"Project-Id-Version: Notification Master 1.4.7\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/notification-master\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2024-11-16T07:02:53+01:00\n"
     12"POT-Creation-Date: 2024-11-28T10:23:31+01:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.10.0\n"
     
    226226
    227227#: includes/integrations/class-discord-integration.php:62
    228 #: includes/integrations/class-email-integration.php:170
     228#: includes/integrations/class-email-integration.php:172
    229229#: includes/integrations/class-webhook-integration.php:62
    230230msgid "Invalid attributes."
     
    241241msgstr ""
    242242
    243 #: includes/integrations/class-email-integration.php:76
     243#: includes/integrations/class-email-integration.php:78
    244244msgid "You do not have permission to perform this action."
    245245msgstr ""
    246246
    247 #: includes/integrations/class-email-integration.php:86
     247#: includes/integrations/class-email-integration.php:88
    248248msgid "Email is required."
    249249msgstr ""
    250250
    251 #: includes/integrations/class-email-integration.php:96
     251#: includes/integrations/class-email-integration.php:98
    252252msgid "Subject is required."
    253253msgstr ""
    254254
    255 #: includes/integrations/class-email-integration.php:106
     255#: includes/integrations/class-email-integration.php:108
    256256msgid "Body is required."
    257257msgstr ""
    258258
    259 #: includes/integrations/class-email-integration.php:123
    260 #: includes/integrations/class-email-integration.php:245
     259#: includes/integrations/class-email-integration.php:125
     260#: includes/integrations/class-email-integration.php:238
    261261msgid "Email sent successfully."
    262262msgstr ""
    263263
    264 #: includes/integrations/class-email-integration.php:129
    265 #: includes/integrations/class-email-integration.php:232
     264#: includes/integrations/class-email-integration.php:131
     265#: includes/integrations/class-email-integration.php:225
    266266msgid "Failed to send email."
    267 msgstr ""
    268 
    269 #: includes/integrations/class-email-integration.php:196
    270 msgid "No emails found."
    271267msgstr ""
    272268
     
    312308
    313309#: includes/integrations/class-webhook-integration.php:142
    314 #: includes/integrations/class-webpush-integration.php:261
     310#: includes/integrations/class-webpush-integration.php:254
    315311msgid "Notification sent successfully."
    316312msgstr ""
    317313
    318 #: includes/integrations/class-webpush-integration.php:106
     314#: includes/integrations/class-webpush-integration.php:88
    319315msgid "WebPush is not configured."
    320316msgstr ""
    321317
    322 #: includes/integrations/class-webpush-integration.php:119
     318#: includes/integrations/class-webpush-integration.php:101
    323319msgid "Invalid attributes"
    324320msgstr ""
  • notification-master/trunk/notifications-master.php

    r3189998 r3198711  
    55 * Description: Enhance user engagement. Trigger notifications for events, support multiple channels like email and Discord, and personalize with dynamic merge tags. Easy setup and customization.
    66 *
    7  * Version: 1.4.6
     7 * Version: 1.4.7
    88 *
    99 * Author: Notification Master
     
    2626
    2727// Define notification-master constants.
    28 define( 'NOTIFICATION_MASTER_VERSION', '1.4.6' );
     28define( 'NOTIFICATION_MASTER_VERSION', '1.4.7' );
    2929define( 'NOTIFICATION_MASTER_FILE', __FILE__ );
    3030define( 'NOTIFICATION_MASTER_DIR', plugin_dir_path( __FILE__ ) );
     
    3333define( 'NOTIFICATION_MASTER_SITE', 'https://notification-master.com' );
    3434
    35 // Load the libraries.
    36 require_once NOTIFICATION_MASTER_DIR . 'includes/libraries/vendor/autoload.php';
     35// Action scheduler.
     36require_once NOTIFICATION_MASTER_DIR . 'includes/libraries/load.php';
    3737
    3838// autoload.
    3939require_once NOTIFICATION_MASTER_DIR . 'includes/autoload.php';
     40
    4041
    4142Notification_Master\Plugin::get_instance();
  • notification-master/trunk/readme.txt

    r3189998 r3198711  
    33Donate link: https://notification-master.com
    44Tags: web push, email, alerts, notifications, push notifications
    5 Stable tag: 1.4.6
     5Stable tag: 1.4.7
    66Requires at least: 4.9
    77Tested up to: 6.7
     
    160160== Changelog ==
    161161
     162= 1.4.7 =
     163* Enhanced: The background processing for notifications. 
     164* Fixed: Resolved a privacy issue where email notifications displayed all recipients' email addresses.
     165
    162166= 1.4.6 =
    163167* Added: WordPress Classic Editor for email notifications, enabling users to add rich content, images, and more.
Note: See TracChangeset for help on using the changeset viewer.