Plugin Directory

Changeset 1740284


Ignore:
Timestamp:
10/03/2017 12:20:06 PM (8 years ago)
Author:
clash82
Message:

Adding updated files for the v0.4.0 release

Location:
wp-lemme-know/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • wp-lemme-know/trunk/plugin.php

    r1566665 r1740284  
    33/*
    44Plugin Name: Lemme Know
    5 Plugin URI:  http://github.com/clash82/wp-lemme-know
     5Plugin URI:  https://github.com/clash82/wp-lemme-know
    66Description: Sends e-mail notification for subscribers when a new post is published.
    7 Version:     0.3.0
     7Version:     0.4.0
    88Author:      Rafał Toborek
    9 Author URI:  http://toborek.info/about/
     9Author URI:  https://toborek.info/about/
    1010License:     GPLv2
    1111License URI: https://opensource.org/licenses/GPL-2.0
     
    6767require_once 'src/publish.php';
    6868require_once 'src/ajax.php';
     69require_once 'src/sender.php';
  • wp-lemme-know/trunk/readme.txt

    r1566665 r1740284  
    44Tags: notifications, email, newsletter, subscribe2, mailing, smtp
    55Requires at least: 4.6
    6 Tested up to: 4.7.0
     6Tested up to: 4.8.2
     7Requires PHP: 5.4
    78Stable tag: trunk
    89License: GPLv2
     10Donate link: https://www.paypal.me/clash82
    911
    1012Sends e-mail notification for all subscribers when a new post is published.
     
    1214== Description ==
    1315
    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.
     16This 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.
    1517
    1618Lemme 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.
     
    4446== Changelog ==
    4547
     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
    4652= v0.3.0 =
    47 * replaced SwiftMailer with built-in PHPMailer (decreased plugin size!)
     53* replaced SwiftMailer with built-in PHPMailer (decreased plugin size!).
    4854
    4955= v0.2.0 =
     
    5359
    5460= v0.1.0 =
    55 * first alpha release
     61* first alpha release.
    5662
    5763== Upgrade notice ==
  • wp-lemme-know/trunk/src/ajax.php

    r1553050 r1740284  
    99}
    1010
     11add_action('wp_ajax_test_email', 'wp_lemme_know_ajax_test_email_callback');
    1112add_action('wp_ajax_subscribe', 'wp_lemme_know_ajax_subscribe_callback');
    1213add_action('wp_ajax_nopriv_subscribe', 'wp_lemme_know_ajax_subscribe_callback');
     14
     15function 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}
    1347
    1448function wp_lemme_know_ajax_subscribe_callback()
  • wp-lemme-know/trunk/src/publish.php

    r1566665 r1740284  
    1313function wp_lemme_know_publish_callback($newStatus, $oldStatus, $post)
    1414{
    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) {
    1623        return;
    1724    }
     
    2633 * Sends e-mails.
    2734 *
    28  * @param string[] $subscribers
     35 * @param array $subscribers
    2936 * @param WP_Post $post
    3037 */
     
    3744    }
    3845
    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    );
    4155
    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'));
    7262
    7363    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();
    9072    }
    9173}
     
    121103 *
    122104 * @param string $body
    123  * @param WP_Post $post
    124  * @param string $hash
     105 * @param WP_Post|null $post
     106 * @param string|null $hash
    125107 *
    126108 * @return string
    127109 */
    128 function wp_lemme_know_parse_body($body, $post, $hash)
     110function wp_lemme_know_parse_body($body, $post = null, $hash = null)
    129111{
    130112    return str_replace([
     
    137119        '{{unsubscribe_url}}',
    138120    ], [
    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'))
    146128    ], $body);
    147129}
  • wp-lemme-know/trunk/src/settings.php

    r1566665 r1740284  
    77if (!defined('ABSPATH')) {
    88    exit;
     9}
     10
     11add_action(
     12    'admin_enqueue_scripts',
     13    'wp_lemme_know_admin_enqueue_script'
     14);
     15
     16function 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    );
    935}
    1036
     
    2046);
    2147
    22 function wp_lemme_know_options_page() {
     48function wp_lemme_know_options_page()
     49{
    2350    require_once __DIR__.'/../templates/settings.php';
    2451}
     
    145172    );
    146173
     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
    147189    // notifications
    148190    add_settings_section(
     
    201243{
    202244    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>',
    204246        WP_LemmeKnowDefaults::getInstance()->getOption('mail_title'),
    205247        __('text will be used as a title for e-mail notifications')
     
    210252{
    211253    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>',
    213255        WP_LemmeKnowDefaults::getInstance()->getOption('mail_from'),
    214256        __('if empty then no messages will be sent (useful if you want to temporary disable e-mail sending)')
     
    219261{
    220262    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" />',
    222264        WP_LemmeKnowDefaults::getInstance()->getOption('mail_from_name')
    223265    );
     
    227269{
    228270    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>',
    230272        WP_LemmeKnowDefaults::getInstance()->getOption('mail_body'),
    231273        __('available short codes are: {{post_title}}, {{post_body}}, {{post_excerpt}}, {{post_date}}, {{post_author}}, {{post_url}} and {{unsubscribe_url}}')
     
    263305{
    264306    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>',
    266308        WP_LemmeKnowDefaults::getInstance()->getOption('smtp_host'),
    267309        __('eg. mail.example.com')
     
    272314{
    273315    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>',
    275317        WP_LemmeKnowDefaults::getInstance()->getOption('smtp_port'),
    276318        __('eg. 25, 587 (TLS) or 467 (SSL)')
     
    280322function wp_lemme_know_smtp_auth_mode_callback()
    281323{
    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>',
    283325        selected(WP_LemmeKnowDefaults::getInstance()->getOption('smtp_auth_mode'), 'PLAIN', false),
    284326        'PLAIN',
     
    292334function wp_lemme_know_smtp_encryption_callback()
    293335{
    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>',
    295337        selected(WP_LemmeKnowDefaults::getInstance()->getOption('smtp_encryption'), '', false),
    296338        __('none'),
     
    305347{
    306348    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" />',
    308350        WP_LemmeKnowDefaults::getInstance()->getOption('smtp_user')
    309351    );
     
    313355{
    314356    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" />',
    316358        WP_LemmeKnowDefaults::getInstance()->getOption('smtp_pass')
     359    );
     360}
     361
     362function 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
     370function 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')
    317393    );
    318394}
Note: See TracChangeset for help on using the changeset viewer.