Changeset 1740284
- Timestamp:
- 10/03/2017 12:20:06 PM (8 years ago)
- Location:
- wp-lemme-know/trunk
- Files:
-
- 5 edited
-
plugin.php (modified) (2 diffs)
-
readme.txt (modified) (4 diffs)
-
src/ajax.php (modified) (1 diff)
-
src/publish.php (modified) (5 diffs)
-
src/settings.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-lemme-know/trunk/plugin.php
r1566665 r1740284 3 3 /* 4 4 Plugin Name: Lemme Know 5 Plugin URI: http ://github.com/clash82/wp-lemme-know5 Plugin URI: https://github.com/clash82/wp-lemme-know 6 6 Description: Sends e-mail notification for subscribers when a new post is published. 7 Version: 0. 3.07 Version: 0.4.0 8 8 Author: Rafał Toborek 9 Author URI: http ://toborek.info/about/9 Author URI: https://toborek.info/about/ 10 10 License: GPLv2 11 11 License URI: https://opensource.org/licenses/GPL-2.0 … … 67 67 require_once 'src/publish.php'; 68 68 require_once 'src/ajax.php'; 69 require_once 'src/sender.php'; -
wp-lemme-know/trunk/readme.txt
r1566665 r1740284 4 4 Tags: notifications, email, newsletter, subscribe2, mailing, smtp 5 5 Requires at least: 4.6 6 Tested up to: 4.7.0 6 Tested up to: 4.8.2 7 Requires PHP: 5.4 7 8 Stable tag: trunk 8 9 License: GPLv2 10 Donate link: https://www.paypal.me/clash82 9 11 10 12 Sends e-mail notification for all subscribers when a new post is published. … … 12 14 == Description == 13 15 14 This plugin is currently in alpha stage. It includes only basic features like sending e-mail notifications using built-in PHP mail() function or by using SMTP server. Work of this plugin depends mostly on SMTP server configuration.16 This plugin is currently in alpha stage. It includes only basic features like sending e-mail notifications using built-in PHP mail() function or by using external SMTP server (recommended). Work of this plugin depends mostly on SMTP server configuration. 15 17 16 18 Lemme Know plugin allows you to send e-mail notifications only for a small amount of subscribers. There are plans to implement Cron-based solution which will allows to send notifications in portions and bypass server limitations. … … 44 46 == Changelog == 45 47 48 = v0.4.0 = 49 * fixed: send notifications only when `post` type content is published, 50 * added: new test SMTP configuration option which allows you to test the current configuration by sending an example e-mail. 51 46 52 = v0.3.0 = 47 * replaced SwiftMailer with built-in PHPMailer (decreased plugin size!) 53 * replaced SwiftMailer with built-in PHPMailer (decreased plugin size!). 48 54 49 55 = v0.2.0 = … … 53 59 54 60 = v0.1.0 = 55 * first alpha release 61 * first alpha release. 56 62 57 63 == Upgrade notice == -
wp-lemme-know/trunk/src/ajax.php
r1553050 r1740284 9 9 } 10 10 11 add_action('wp_ajax_test_email', 'wp_lemme_know_ajax_test_email_callback'); 11 12 add_action('wp_ajax_subscribe', 'wp_lemme_know_ajax_subscribe_callback'); 12 13 add_action('wp_ajax_nopriv_subscribe', 'wp_lemme_know_ajax_subscribe_callback'); 14 15 function wp_lemme_know_ajax_test_email_callback() 16 { 17 $sender = new WP_LemmeKnowNotificationSender( 18 $_POST['mailerType'] === 'default' ? false : true, 19 $_POST['hostname'], 20 $_POST['port'], 21 $_POST['user'], 22 $_POST['pass'], 23 $_POST['encryption'], 24 $_POST['authMode'] 25 ); 26 27 $body = wp_lemme_know_parse_body(stripcslashes($_POST['mailBody'])); 28 29 $sender 30 ->setSubject($_POST['mailTitle']) 31 ->setFrom($_POST['mailFrom'], $_POST['mailFromName']) 32 ->setAddress($_POST['email']) 33 ->setBody($body) 34 ->setDebug(true); 35 36 if ($sender->send() === true) { 37 die (json_encode([ 38 'status' => 0 // e-mail was successfully sent 39 ])); 40 } 41 42 die (json_encode([ 43 'status' => 1, // there were some issues when sending e-mail 44 'results' => $sender->getDebugDetails() 45 ])); 46 } 13 47 14 48 function wp_lemme_know_ajax_subscribe_callback() -
wp-lemme-know/trunk/src/publish.php
r1566665 r1740284 13 13 function wp_lemme_know_publish_callback($newStatus, $oldStatus, $post) 14 14 { 15 if ('publish' !== $newStatus || 'publish' === $oldStatus) { 15 // we do not accept updates other than `post` type 16 if ('post' !== get_post_type($post)) { 17 return; 18 } 19 20 // only `publish` status is accepted 21 if ('publish' !== $newStatus 22 || 'publish' === $oldStatus) { 16 23 return; 17 24 } … … 26 33 * Sends e-mails. 27 34 * 28 * @param string[]$subscribers35 * @param array $subscribers 29 36 * @param WP_Post $post 30 37 */ … … 37 44 } 38 45 39 // temporary disable max_execution_time (doesn't work if PHP is running in safe-mode) 40 ini_set('max_execution_time', 0); 46 $sender = new WP_LemmeKnowNotificationSender( 47 $options->getOption('mailer_type') === 'smtp' ? true : false, 48 $options->getOption('smtp_host'), 49 $options->getOption('smtp_port'), 50 $options->getOption('smtp_user'), 51 $options->getOption('smtp_pass'), 52 $options->getOption('smtp_encryption'), 53 $options->getOption('smtp_auth_mode') 54 ); 41 55 42 require_once ABSPATH.'wp-includes/class-phpmailer.php'; 43 $mailer = new PHPMailer(true); 44 45 if ($options->getOption('mailer_type') === 'smtp') { 46 require_once ABSPATH.'wp-includes/class-smtp.php'; 47 48 $mailer->isSMTP(); 49 $mailer->SMTPAutoTLS = false; 50 $mailer->SMTPAuth = true; 51 $mailer->Host = $options->getOption('smtp_host'); 52 $mailer->Port = $options->getOption('smtp_port'); 53 $mailer->Username = $options->getOption('smtp_user'); 54 $mailer->Password = $options->getOption('smtp_pass'); 55 $mailer->SMTPSecure = $options->getOption('smtp_encryption'); 56 $mailer->AuthType = $options->getOption('smtp_auth_mode'); 57 58 // additional settings for PHP 5.6 59 $mailer->SMTPOptions = [ 60 'ssl' => [ 61 'verify_peer' => false, 62 'verify_peer_name' => false, 63 'allow_self_signed' => true, 64 ] 65 ]; 66 } 67 68 $mailer->setFrom($options->getOption('mail_from'), $options->getOption('mail_from_name')); 69 $mailer->isHTML(true); 70 $mailer->Subject = $options->getOption('mail_title'); 71 $mailer->CharSet = 'UTF-8'; 56 $sender 57 ->setFrom( 58 $options->getOption('mail_from'), 59 $options->getOption('mail_from_name') 60 ) 61 ->setSubject($options->getOption('mail_title')); 72 62 73 63 foreach ($subscribers as $item) { 74 $mailer->clearAddresses(); 75 $mailer->clearReplyTos(); 76 77 $mailer->Body = wp_lemme_know_parse_body( 78 $options->getOption('mail_body'), 79 $post, 80 $item['hash'] 81 ); 82 $mailer->addAddress($item['email'], $item['email']); 83 $mailer->addReplyTo($item['email'], $item['email']); 84 85 try { 86 $mailer->send(); 87 } catch (Exception $e) { 88 error_log(sprintf('wp-lemme-know error: %s', $e->getMessage())); 89 } 64 $sender 65 ->setAddress($item['email']) 66 ->setBody(wp_lemme_know_parse_body( 67 $options->getOption('mail_body'), 68 $post, 69 $item['hash'] 70 )) 71 ->send(); 90 72 } 91 73 } … … 121 103 * 122 104 * @param string $body 123 * @param WP_Post $post124 * @param string $hash105 * @param WP_Post|null $post 106 * @param string|null $hash 125 107 * 126 108 * @return string 127 109 */ 128 function wp_lemme_know_parse_body($body, $post , $hash)110 function wp_lemme_know_parse_body($body, $post = null, $hash = null) 129 111 { 130 112 return str_replace([ … … 137 119 '{{unsubscribe_url}}', 138 120 ], [ 139 $post ->post_title,140 $post ->post_content,141 $post ->post_excerpt,142 $post ->post_date,143 $post ->post_author,144 get_permalink($post),145 sprintf('%s/lemme_know/unsubscribe/%s/', get_site_url(), $hash )121 $post ? $post->post_title : __('Example title'), 122 $post ? $post->post_content : __('Example content'), 123 $post ? $post->post_excerpt : __('Example excerpt'), 124 $post ? $post->post_date : __('Example post date'), 125 $post ? $post->post_author : __('Example post author'), 126 $post ? get_permalink($post) : '#', 127 sprintf('%s/lemme_know/unsubscribe/%s/', get_site_url(), $hash ? $hash : __('real-hash-will-be-placed-here')) 146 128 ], $body); 147 129 } -
wp-lemme-know/trunk/src/settings.php
r1566665 r1740284 7 7 if (!defined('ABSPATH')) { 8 8 exit; 9 } 10 11 add_action( 12 'admin_enqueue_scripts', 13 'wp_lemme_know_admin_enqueue_script' 14 ); 15 16 function wp_lemme_know_admin_enqueue_script() 17 { 18 global $pluginData; 19 20 wp_register_style( 21 'wp-lemme-know-admin-style', 22 plugin_dir_url(__FILE__).'../assets/css/style-admin.css', 23 false, 24 $pluginData['Version'] 25 ); 26 wp_enqueue_style('wp-lemme-know-admin-style'); 27 28 wp_enqueue_script( 29 'wp-lemme-know-admin-javascript', 30 plugin_dir_url(__FILE__).'../assets/js/lemme-know-admin.js', 31 false, 32 $pluginData['Version'], 33 false 34 ); 9 35 } 10 36 … … 20 46 ); 21 47 22 function wp_lemme_know_options_page() { 48 function wp_lemme_know_options_page() 49 { 23 50 require_once __DIR__.'/../templates/settings.php'; 24 51 } … … 145 172 ); 146 173 174 // tests 175 add_settings_section( 176 'wp_lemme_know_options_tests', 177 __('Tests', 'wp-lemme-know'), 178 'wp_lemme_know_tests_callback', 179 'wp_lemme_know_plugin' 180 ); 181 add_settings_field( 182 'test_email', 183 __('Provide an e-mail address to send an example notification', 'wp-lemme-know'), 184 'wp_lemme_know_test_email_callback', 185 'wp_lemme_know_plugin', 186 'wp_lemme_know_options_tests' 187 ); 188 147 189 // notifications 148 190 add_settings_section( … … 201 243 { 202 244 printf( 203 '<input type="text" name="wp_lemme_know_options[mail_title]" value="%s" class="regular-text ltr" /><p class="description">%s</p>',245 '<input type="text" id="wp-lemme-know-options-mail-title" name="wp_lemme_know_options[mail_title]" value="%s" class="regular-text ltr" /><p class="description">%s</p>', 204 246 WP_LemmeKnowDefaults::getInstance()->getOption('mail_title'), 205 247 __('text will be used as a title for e-mail notifications') … … 210 252 { 211 253 printf( 212 '<input type="text" name="wp_lemme_know_options[mail_from]" value="%s" class="regular-text ltr" /><p class="description">%s</p>',254 '<input type="text" id="wp-lemme-know-options-mail-from" name="wp_lemme_know_options[mail_from]" value="%s" class="regular-text ltr" /><p class="description">%s</p>', 213 255 WP_LemmeKnowDefaults::getInstance()->getOption('mail_from'), 214 256 __('if empty then no messages will be sent (useful if you want to temporary disable e-mail sending)') … … 219 261 { 220 262 printf( 221 '<input type="text" name="wp_lemme_know_options[mail_from_name]" value="%s" class="regular-text ltr" />',263 '<input type="text" id="wp-lemme-know-options-mail-from-name" name="wp_lemme_know_options[mail_from_name]" value="%s" class="regular-text ltr" />', 222 264 WP_LemmeKnowDefaults::getInstance()->getOption('mail_from_name') 223 265 ); … … 227 269 { 228 270 printf( 229 '<textarea name="wp_lemme_know_options[mail_body]" class="large-text" rows="10" cols="50">%s</textarea><p class="description">%s</p>',271 '<textarea id="wp-lemme-know-options-mail-body" name="wp_lemme_know_options[mail_body]" class="large-text" rows="10" cols="50">%s</textarea><p class="description">%s</p>', 230 272 WP_LemmeKnowDefaults::getInstance()->getOption('mail_body'), 231 273 __('available short codes are: {{post_title}}, {{post_body}}, {{post_excerpt}}, {{post_date}}, {{post_author}}, {{post_url}} and {{unsubscribe_url}}') … … 263 305 { 264 306 printf( 265 '<input type="text" name="wp_lemme_know_options[smtp_host]" value="%s" class="regular-text ltr" /><p class="description">%s</p>',307 '<input type="text" id="wp-lemme-know-options-smtp-host" name="wp_lemme_know_options[smtp_host]" value="%s" class="regular-text ltr" /><p class="description">%s</p>', 266 308 WP_LemmeKnowDefaults::getInstance()->getOption('smtp_host'), 267 309 __('eg. mail.example.com') … … 272 314 { 273 315 printf( 274 '<input type="number" name="wp_lemme_know_options[smtp_port]" value="%s" class="regular-text ltr" /><p class="description">%s</p>',316 '<input type="number" id="wp-lemme-know-options-smtp-port" name="wp_lemme_know_options[smtp_port]" value="%s" class="regular-text ltr" /><p class="description">%s</p>', 275 317 WP_LemmeKnowDefaults::getInstance()->getOption('smtp_port'), 276 318 __('eg. 25, 587 (TLS) or 467 (SSL)') … … 280 322 function wp_lemme_know_smtp_auth_mode_callback() 281 323 { 282 printf('<select name="wp_lemme_know_options[smtp_auth_mode]"><option value="PLAIN" %s>%s</option><option value="LOGIN" %s>%s</option><option value="CRAM-MD5" %s>%s</option></select>',324 printf('<select id="wp-lemme-know-options-smtp-auth-mode" name="wp_lemme_know_options[smtp_auth_mode]"><option value="PLAIN" %s>%s</option><option value="LOGIN" %s>%s</option><option value="CRAM-MD5" %s>%s</option></select>', 283 325 selected(WP_LemmeKnowDefaults::getInstance()->getOption('smtp_auth_mode'), 'PLAIN', false), 284 326 'PLAIN', … … 292 334 function wp_lemme_know_smtp_encryption_callback() 293 335 { 294 printf('<select name="wp_lemme_know_options[smtp_encryption]"><option value="" %s>%s</option>><option value="tls" %s>%s</option><option value="ssl" %s>%s</option></select>',336 printf('<select id="wp-lemme-know-options-smtp-encryption" name="wp_lemme_know_options[smtp_encryption]"><option value="" %s>%s</option>><option value="tls" %s>%s</option><option value="ssl" %s>%s</option></select>', 295 337 selected(WP_LemmeKnowDefaults::getInstance()->getOption('smtp_encryption'), '', false), 296 338 __('none'), … … 305 347 { 306 348 printf( 307 '<input type="text" name="wp_lemme_know_options[smtp_user]" value="%s" class="regular-text ltr" />',349 '<input type="text" id="wp-lemme-know-options-smtp-user" name="wp_lemme_know_options[smtp_user]" value="%s" class="regular-text ltr" />', 308 350 WP_LemmeKnowDefaults::getInstance()->getOption('smtp_user') 309 351 ); … … 313 355 { 314 356 printf( 315 '<input type="password" name="wp_lemme_know_options[smtp_pass]" value="%s" class="regular-text ltr" />',357 '<input type="password" id="wp-lemme-know-options-smtp-pass" name="wp_lemme_know_options[smtp_pass]" value="%s" class="regular-text ltr" />', 316 358 WP_LemmeKnowDefaults::getInstance()->getOption('smtp_pass') 359 ); 360 } 361 362 function wp_lemme_know_tests_callback() 363 { 364 printf( 365 '<p>%s</p>', 366 __('Use this option to test above configuration by sending an example e-mail message. Please, be aware that the current on-screen configuration will be used (not the saved one). Remember also that this tool allows you only to check if SMTP configuration is correct. In case of a mail() function, you will not be able to know if message was sent correctly, check your e-mail inbox instead.', 'wp-lemme-know') 367 ); 368 } 369 370 function wp_lemme_know_test_email_callback() 371 { 372 printf( 373 '<input type="text" id="wp-lemme-know-admin-test-email" class="regular-text ltr" placeholder="%s" /> 374 <br /><br /> 375 <button type="button" id="wp-lemme-know-admin-test-send" class="button button-primary">%s</button> 376 <div id="wp-lemme-know-admin-test-results" class="wp-lemme-know-admin-test-results">Results</div> 377 <script> 378 (function() { 379 new clash82.LemmeKnowAdmin({ 380 sendingMsg: "%s", 381 successMsg: "%s", 382 errorMsg: "%s", 383 internalErrorMsg: "%s" 384 }); 385 }) (); 386 </script>', 387 __('[email protected]'), 388 __('Send e-mail notification now'), 389 __('Sending test message, please wait...'), 390 __('Congratulations! test e-mail was sent, configuration is correct'), 391 __('ERROR').': '.__("couldn't send an email using current settings"), 392 __('ERROR').': '.__('internal error occurred') 317 393 ); 318 394 }
Note: See TracChangeset
for help on using the changeset viewer.