Changeset 2115348
- Timestamp:
- 07/01/2019 10:45:11 AM (7 years ago)
- Location:
- subscribe-to-new-woocommerce-products/trunk
- Files:
-
- 3 edited
-
includes/class-wc-customer-product-subscription-email.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
subscribe-to-new-woocommerce-products.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
subscribe-to-new-woocommerce-products/trunk/includes/class-wc-customer-product-subscription-email.php
r1650582 r2115348 1 1 <?php 2 2 3 4 5 3 if(!defined('ABSPATH')) // http://docs.woothemes.com/document/create-a-plugin/ 6 7 4 { 8 9 5 exit; 10 11 6 } 12 7 13 14 15 8 class WC_Product_Subscription_Email extends WC_Email 16 17 9 { 18 19 10 public $product; 20 11 21 22 23 12 public function __construct() 24 25 13 { 26 27 14 $this->id = 'product_subscription_email'; 28 29 15 $this->customer_email = true; 30 31 16 $this->title = 'Product Subscription Email'; 32 33 17 $this->description = 'New product emails are sent to the email list when a new product is uploaded to the website.'; 34 35 18 $this->template_base = stnwp_get_plugin_path() . 'templates/'; 36 37 19 $this->heading = '{product_name} Available'; 38 39 20 $this->subject = '{product_name} Available on {site_title}'; 40 41 21 $this->template_html = 'emails/customer-product-subscription-email.php'; 42 43 22 $this->template_plain = 'emails/plain/customer-product-subscription-email.php'; 44 23 45 46 47 24 parent::__construct(); 48 49 25 } 50 26 51 52 53 27 public function trigger($post_id, $email_address) 54 55 28 { 56 57 $this->post_id = $post_id; 58 29 $this->post_id = $post_id; 59 30 $this->recipient = $email_address; 60 31 61 62 63 $this->find['product-name'] = '{product_name}'; 64 32 $this->find['product-name'] = '{product_name}'; 65 33 $this->replace['product-name'] = get_the_title($post_id); 66 34 67 68 69 if(!$this->recipient) 70 35 if(!$this->recipient || ($this->is_enabled() == false)) 71 36 { 72 73 37 return; 74 75 38 } 76 39 77 78 79 40 $this->send($this->recipient, $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments()); 80 81 41 } 82 42 83 84 85 43 public function get_content_html() // HTML Email Content Template 86 87 44 { 88 89 45 ob_start(); 90 46 91 92 93 47 wc_get_template( 94 95 48 $this->template_html, 96 97 49 array( 98 99 50 'email_heading' => $this->get_heading(), 100 101 51 'post_id' => $this->post_id, 102 103 52 'plain_text' => false, 104 105 53 'email' => $this 106 107 54 ), 108 109 55 '', 110 111 56 stnwp_get_plugin_path() . 'templates/' 112 113 57 ); 114 58 59 return ob_get_clean(); 60 } 115 61 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 ); 116 77 117 78 return ob_get_clean(); 118 119 79 } 120 80 121 122 123 public function get_content_plain() // Plain Email Content Template 124 81 public function init_form_fields() // Email Template Settings 125 82 { 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' 145 89 ), 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 ) 151 116 ); 152 153 154 155 return ob_get_clean();156 157 117 } 158 159 160 161 public function init_form_fields() // Email Template Settings162 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 235 118 } 236 237 119 ?> 238 -
subscribe-to-new-woocommerce-products/trunk/readme.txt
r1650585 r2115348 2 2 3 3 Contributors: Lewis Self 4 Donate Link: https:// selfdesigns.co.uk4 Donate Link: https://www.lewisself.co.uk/ 5 5 Tags: woocommerce, new, products, notification, subscription, subscribe, newsletter, email 6 6 Requires at least: 4.0 7 Tested up to: 4.7.47 Tested up to: 5.0.0 8 8 Stable tag: Trunk 9 9 License: GPLv2 10 Version: 1.0. 110 Version: 1.0.2 11 11 12 12 == Description == … … 54 54 == Changelog == 55 55 56 = 1.0.2 (01/07/2019) = 57 * Stopped emails being when disabled in email settings 58 * Fixed error when WooCommerce disabled 59 56 60 = 1.0.1 (03/05/2017) = 57 61 * Fixed admin widget dashboard bug -
subscribe-to-new-woocommerce-products/trunk/subscribe-to-new-woocommerce-products.php
r1650582 r2115348 2 2 3 3 /* 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 9 11 */ 10 12 … … 36 38 } 37 39 add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'stnwp_add_setting_link'); 38 39 function stnwp_create_admin_widget() // Create admin widget40 {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 HTML53 {54 if(current_user_can('administrator'))55 {56 if(isset($_REQUEST['_wpnonce']))57 {58 if(wp_verify_nonce($_REQUEST['_wpnonce'])) // Verify the nonce59 {60 if($_POST['update_submitted'])61 {62 $sanatized_emails = array();63 40 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'); 72 53 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(); 74 65 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 } 78 74 79 if($email_subscribers) 80 { 81 foreach($email_subscribers as $email_subscriber) 82 { 83 $email_list_count++; 75 $email_subscribers = get_option('stnwp_subscribers'); 84 76 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 = ''; 88 80 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 } 98 100 99 101 function stnwp_new_product_created($new_status, $old_status, $post) … … 170 172 function stnwp_woocommerce_inactive() // Error if WooCommerce not active 171 173 { 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>'; 173 175 } 174 add_action('admin_notices', ' wprne_woocommerce_inactive');176 add_action('admin_notices', 'stnwp_woocommerce_inactive'); 175 177 } 176 178
Note: See TracChangeset
for help on using the changeset viewer.