Plugin Directory

Changeset 2115348


Ignore:
Timestamp:
07/01/2019 10:45:11 AM (7 years ago)
Author:
lewisself
Message:

Updated plugin to 1.0.2

Location:
subscribe-to-new-woocommerce-products/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • subscribe-to-new-woocommerce-products/trunk/includes/class-wc-customer-product-subscription-email.php

    r1650582 r2115348  
    11<?php
    22
    3 
    4 
    53    if(!defined('ABSPATH')) // http://docs.woothemes.com/document/create-a-plugin/
    6 
    74    {
    8 
    95        exit;
    10 
    116    }
    127
    13 
    14 
    158    class WC_Product_Subscription_Email extends WC_Email
    16 
    179    {
    18 
    1910        public $product;
    2011
    21 
    22 
    2312        public function __construct()
    24 
    2513        {
    26 
    2714            $this->id             = 'product_subscription_email';
    28 
    2915            $this->customer_email = true;
    30 
    3116            $this->title          = 'Product Subscription Email';
    32 
    3317            $this->description    = 'New product emails are sent to the email list when a new product is uploaded to the website.';
    34 
    3518            $this->template_base  = stnwp_get_plugin_path() . 'templates/';
    36 
    3719            $this->heading        = '{product_name} Available';
    38 
    3920            $this->subject        = '{product_name} Available on {site_title}';
    40 
    4121            $this->template_html  = 'emails/customer-product-subscription-email.php';
    42 
    4322            $this->template_plain = 'emails/plain/customer-product-subscription-email.php';
    4423
    45 
    46 
    4724            parent::__construct();
    48 
    4925        }
    5026
    51 
    52 
    5327        public function trigger($post_id, $email_address)
    54 
    5528        {
    56 
    57             $this->post_id   = $post_id;
    58 
     29            $this->post_id   = $post_id;
    5930            $this->recipient = $email_address;
    6031
    61 
    62 
    63             $this->find['product-name']      = '{product_name}';
    64 
     32            $this->find['product-name']    = '{product_name}';
    6533            $this->replace['product-name'] = get_the_title($post_id);
    6634
    67 
    68 
    69             if(!$this->recipient)
    70 
     35            if(!$this->recipient || ($this->is_enabled() == false))
    7136            {
    72 
    7337                return;
    74 
    7538            }
    7639
    77 
    78 
    7940            $this->send($this->recipient, $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments());
    80 
    8141        }
    8242
    83 
    84 
    8543        public function get_content_html() // HTML Email Content Template
    86 
    8744        {
    88 
    8945            ob_start();
    9046
    91 
    92 
    9347            wc_get_template(
    94 
    9548                $this->template_html,
    96 
    9749                array(
    98 
    9950                    'email_heading' => $this->get_heading(),
    100 
    10151                    'post_id'       => $this->post_id,
    102 
    10352                    'plain_text'    => false,
    104 
    10553                    'email'               => $this
    106 
    10754                ),
    108 
    10955                '',
    110 
    11156                stnwp_get_plugin_path() . 'templates/'
    112 
    11357            );
    11458
     59            return ob_get_clean();
     60        }
    11561
     62        public function get_content_plain() // Plain Email Content Template
     63        {
     64            ob_start();
     65
     66            woocommerce_get_template(
     67                $this->template_plain,
     68                array(
     69                    'email_heading' => $this->get_heading(),
     70                    'post_id'       => $this->post_id,
     71                    'plain_text'    => true,
     72                    'email'               => $this
     73                ),
     74                '',
     75                stnwp_get_plugin_path() . 'templates/'
     76            );
    11677
    11778            return ob_get_clean();
    118 
    11979        }
    12080
    121 
    122 
    123         public function get_content_plain() // Plain Email Content Template
    124 
     81        public function init_form_fields() // Email Template Settings
    12582        {
    126 
    127             ob_start();
    128 
    129 
    130 
    131             woocommerce_get_template(
    132 
    133                 $this->template_plain,
    134 
    135                 array(
    136 
    137                     'email_heading' => $this->get_heading(),
    138 
    139                     'post_id'       => $this->post_id,
    140 
    141                     'plain_text'    => true,
    142 
    143                     'email'               => $this
    144 
     83            $this->form_fields = array(
     84                'enabled'       => array(
     85                    'title'       => 'Enable/Disable',
     86                    'type'        => 'checkbox',
     87                    'label'       => 'Enable this email notification',
     88                    'default'     => 'yes'
    14589                ),
    146 
    147                 '',
    148 
    149                 stnwp_get_plugin_path() . 'templates/'
    150 
     90                'subject'           => array(
     91                    'title'       => 'Subject',
     92                    'type'        => 'text',
     93                    'description' => sprintf('This controls the email subject line. Leave blank to use the default subject: <code>%s</code>.', $this->subject),
     94                    'placeholder' => '',
     95                    'default'     => ''
     96                ),
     97                'heading'       => array(
     98                    'title'       => 'Email Heading',
     99                    'type'        => 'text',
     100                    'description' => sprintf('This controls the main heading contained within the email notification. Leave blank to use the default heading: <code>%s</code>.', $this->heading),
     101                    'placeholder' => '',
     102                    'default'     => ''
     103                ),
     104                'email_type'    => array(
     105                    'title'       => 'Email type',
     106                    'type'        => 'select',
     107                    'description' => 'Choose which format of email to send.',
     108                    'default'     => 'html',
     109                    'class'       => 'email_type',
     110                    'options'     => array(
     111                        'plain'       => 'Plain text',
     112                        'html'        => 'HTML',
     113                        'multipart'   => 'Multipart'
     114                    )
     115                )
    151116            );
    152 
    153 
    154 
    155             return ob_get_clean();
    156 
    157117        }
    158 
    159 
    160 
    161         public function init_form_fields() // Email Template Settings
    162 
    163         {
    164 
    165             $this->form_fields = array(
    166 
    167                 'enabled'       => array(
    168 
    169                     'title'       => 'Enable/Disable',
    170 
    171                     'type'        => 'checkbox',
    172 
    173                     'label'       => 'Enable this email notification',
    174 
    175                     'default'     => 'yes'
    176 
    177                 ),
    178 
    179                 'subject'           => array(
    180 
    181                     'title'       => 'Subject',
    182 
    183                     'type'        => 'text',
    184 
    185                     'description' => sprintf('This controls the email subject line. Leave blank to use the default subject: <code>%s</code>.', $this->subject),
    186 
    187                     'placeholder' => '',
    188 
    189                     'default'     => ''
    190 
    191                 ),
    192 
    193                 'heading'       => array(
    194 
    195                     'title'       => 'Email Heading',
    196 
    197                     'type'        => 'text',
    198 
    199                     'description' => sprintf('This controls the main heading contained within the email notification. Leave blank to use the default heading: <code>%s</code>.', $this->heading),
    200 
    201                     'placeholder' => '',
    202 
    203                     'default'     => ''
    204 
    205                 ),
    206 
    207                 'email_type'    => array(
    208 
    209                     'title'       => 'Email type',
    210 
    211                     'type'        => 'select',
    212 
    213                     'description' => 'Choose which format of email to send.',
    214 
    215                     'default'     => 'html',
    216 
    217                     'class'       => 'email_type',
    218 
    219                     'options'     => array(
    220 
    221                         'plain'       => 'Plain text',
    222 
    223                         'html'        => 'HTML',
    224 
    225                         'multipart'   => 'Multipart'
    226 
    227                     )
    228 
    229                 )
    230 
    231             );
    232 
    233         }
    234 
    235118    }
    236 
    237119?>
    238 
  • subscribe-to-new-woocommerce-products/trunk/readme.txt

    r1650585 r2115348  
    22
    33Contributors: Lewis Self
    4 Donate Link: https://selfdesigns.co.uk
     4Donate Link: https://www.lewisself.co.uk/
    55Tags: woocommerce, new, products, notification, subscription, subscribe, newsletter, email
    66Requires at least: 4.0
    7 Tested up to: 4.7.4
     7Tested up to: 5.0.0
    88Stable tag: Trunk
    99License: GPLv2
    10 Version: 1.0.1
     10Version: 1.0.2
    1111
    1212== Description ==
     
    5454== Changelog ==
    5555
     56= 1.0.2 (01/07/2019) =
     57* Stopped emails being when disabled in email settings
     58* Fixed error when WooCommerce disabled
     59
    5660= 1.0.1 (03/05/2017) =
    5761* Fixed admin widget dashboard bug
  • subscribe-to-new-woocommerce-products/trunk/subscribe-to-new-woocommerce-products.php

    r1650582 r2115348  
    22
    33    /*
    4         Plugin Name: Subscribe To New WooCommerce Products
    5         Description: Lets customers input an email address to be notified when new products are uploaded to the website.
    6         Version:     1.0.1
    7         Author:      Lewis Self
    8         Author URI:  http://selfdesigns.co.uk
     4        Plugin Name:          Subscribe To New WooCommerce Products
     5        Description:          Lets customers input an email address to be notified when new products are uploaded to the website.
     6        Version:              1.0.2
     7        Author:               Lewis Self
     8        Author URI:           https://www.lewisself.co.uk/
     9        WC requires at least: 3.0.0
     10        WC tested up to:      3.6.4
    911    */
    1012
     
    3638            }
    3739            add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'stnwp_add_setting_link');
    38      
    39       function stnwp_create_admin_widget() // Create admin widget
    40       {
    41         if(current_user_can('administrator'))
    42         {
    43           wp_add_dashboard_widget(
    44             'subscribe_to_new_woocommerce_products',
    45             'New Product Subscribers',
    46             'stnwp_create_admin_widget_html'
    47           );
    48         }
    49       }
    50       add_action('wp_dashboard_setup', 'stnwp_create_admin_widget');
    51        
    52       function stnwp_create_admin_widget_html() // Admin widget HTML
    53       {
    54         if(current_user_can('administrator'))
    55         {
    56           if(isset($_REQUEST['_wpnonce']))
    57           {
    58             if(wp_verify_nonce($_REQUEST['_wpnonce'])) // Verify the nonce
    59             {
    60               if($_POST['update_submitted'])
    61               {
    62                 $sanatized_emails = array();
    6340
    64                 foreach(explode("\n", $_POST['product_subscription_emails']) as $product_subscription_email) // Loop and sanatize all email addresses in array
    65                 {
    66                   $sanatized_emails[] = sanitize_email($product_subscription_email);
    67                 }
    68                 update_option('stnwp_subscribers', $sanatized_emails);
    69               }
    70             }
    71           }
     41            function stnwp_create_admin_widget() // Create admin widget
     42            {
     43                if(current_user_can('administrator'))
     44                {
     45                    wp_add_dashboard_widget(
     46                        'subscribe_to_new_woocommerce_products',
     47                        'New Product Subscribers',
     48                        'stnwp_create_admin_widget_html'
     49                    );
     50                }
     51            }
     52            add_action('wp_dashboard_setup', 'stnwp_create_admin_widget');
    7253
    73           $email_subscribers = get_option('stnwp_subscribers');
     54            function stnwp_create_admin_widget_html() // Admin widget HTML
     55            {
     56                if(current_user_can('administrator'))
     57                {
     58                    if(isset($_REQUEST['_wpnonce']))
     59                    {
     60                        if(wp_verify_nonce($_REQUEST['_wpnonce'])) // Verify the nonce
     61                        {
     62                            if($_POST['update_submitted'])
     63                            {
     64                                $sanatized_emails = array();
    7465
    75           $email_list_count        = 0;
    76           $email_subscribers_total = count($email_subscribers);
    77           $textbox_value           = '';
     66                                foreach(explode("\n", $_POST['product_subscription_emails']) as $product_subscription_email) // Loop and sanatize all email addresses in array
     67                                {
     68                                    $sanatized_emails[] = sanitize_email($product_subscription_email);
     69                                }
     70                                update_option('stnwp_subscribers', $sanatized_emails);
     71                            }
     72                        }
     73                    }
    7874
    79           if($email_subscribers)
    80           {
    81             foreach($email_subscribers as $email_subscriber)
    82             {
    83               $email_list_count++;
     75                    $email_subscribers = get_option('stnwp_subscribers');
    8476
    85               $textbox_value .= $email_subscriber . (($email_list_count != $email_subscribers_total) ? "\n" : ''); // Stops blank array values on save
    86             }
    87           }
     77                    $email_list_count        = 0;
     78                    $email_subscribers_total = count($email_subscribers);
     79                    $textbox_value           = '';
    8880
    89           echo '<form method="post" action="#">';
    90           wp_nonce_field(); // Create nonce
    91           echo '  <p>Add each email on a new line</p>';
    92           echo '  <textarea style="width:100%; resize:none; height:100px;" name="product_subscription_emails">' . esc_textarea($textbox_value) . '</textarea>';
    93           echo '  <input type="submit" name="save" class="button button-primary" value="Update List" style="margin:10px 0 0 0;">';
    94           echo '  <input type="hidden" name="update_submitted" value="true">';
    95           echo '</form>';
    96         }
    97       }
     81                    if($email_subscribers)
     82                    {
     83                        foreach($email_subscribers as $email_subscriber)
     84                        {
     85                            $email_list_count++;
     86
     87                            $textbox_value .= $email_subscriber . (($email_list_count != $email_subscribers_total) ? "\n" : ''); // Stops blank array values on save
     88                        }
     89                    }
     90
     91                    echo '<form method="post" action="#">';
     92                    wp_nonce_field(); // Create nonce
     93                    echo '  <p>Add each email on a new line</p>';
     94                    echo '  <textarea style="width:100%; resize:none; height:100px;" name="product_subscription_emails">' . esc_textarea($textbox_value) . '</textarea>';
     95                    echo '  <input type="submit" name="save" class="button button-primary" value="Update List" style="margin:10px 0 0 0;">';
     96                    echo '  <input type="hidden" name="update_submitted" value="true">';
     97                    echo '</form>';
     98                }
     99            }
    98100
    99101            function stnwp_new_product_created($new_status, $old_status, $post)
     
    170172        function stnwp_woocommerce_inactive() // Error if WooCommerce not active
    171173        {
    172             '<div class="error"><p>The WooCommerce plugin needs to be enabled to use the Product Subscription For WooCommerce plugin.</p></div>';
     174            echo '<div class="error"><p>The WooCommerce plugin needs to be enabled to use the Product Subscription For WooCommerce plugin.</p></div>';
    173175        }
    174         add_action('admin_notices', 'wprne_woocommerce_inactive');
     176        add_action('admin_notices', 'stnwp_woocommerce_inactive');
    175177    }
    176178
Note: See TracChangeset for help on using the changeset viewer.