WordPress.org

Ready to get started?Download WordPress

Forums

Subscribe2
[resolved] Question about email preview and upgrade proposal (with some code) (18 posts)

  1. orion42
    Member
    Posted 1 year ago #

    I'm trying to try some update in the script but if I set the daily or weekly digest and I try to send a preview email, I receive only one email instead of the 4 emails received with the "For each post" option.
    It's normal ?

    Also with options different from "For each post" the email-title is always [{BLOGNAME}] - "Daily/Weekly Digest Report"
    I've solved this problem editing clss-s2-core.php at line 1624, adding the notification_subject to the mail subject.

    Original line:

    $subject .=  $display . " " . __('Digest Email', 'subscribe2'); //42  add in email subject: "Daily/Weekly Digest Report"

    My edit (with some comment):

    // Get email subject // 42 Add the email title from settings page
    
    $subject .= html_entity_decode(stripslashes(wp_kses($this->substitute($this->subscribe2_options['notification_subject']), ''))); //42
    
    //$subject .=  $display . " " . __('Digest Email', 'subscribe2'); //42  add in email subject: "Daily/Weekly Digest Report"

    It will be useful to have in the setting page some option to set up different template/titles related to the frequency option.
    E.g. for title
    For Each Post option enabled
    [{BLOGNAME}] - "There is a new post in our blog"
    For Daily/Weekly option enabled
    [{BLOGNAME}] - "Today/This week there are {number_of_new_post} new post in our blog"

    The same could be done with the email body, for having better text.

    I suggest this changes because sometime i switch between "For Each Post" and "Daily" frequency option, for not spamming with too many email (but if it's an important post i use "For Each Post" to notify soon as possible my users ).

    Other possible changes:
    {TITLE}, {POST}, {PERMALINK},... and other "for per-post emails only" can become array for daily/weekly notification, so you can adjust your template,
    {number_of_new_post} : Total number of new post for daily/weekly notification

    http://wordpress.org/extend/plugins/subscribe2/

  2. orion42
    Member
    Posted 1 year ago #

    I've done a lots of editing.
    I've added some new features. This is the code:

    in settings.php:
    Row's number are referred to my edited script, so can be different of some row. My new code is marked with //42 at the end of line (sometimes I'll reportin this message also some orignal code for better understanding)

    Declaration of new variables if they are not empty
    row 87

    // email subject and body templates
    // ensure that are not empty before updating
    if ( !empty($_POST['notification_subject']) ) {
    	$this->subscribe2_options['notification_subject'] = $_POST['notification_subject'];
    }
    
    if ( !empty($_POST['notification_subject_hourly']) ) { //42
    	$this->subscribe2_options['notification_subject_hourly'] = $_POST['notification_subject_hourly'];
    }
    
    if ( !empty($_POST['notification_subject_twicedaily']) ) { //42
    	$this->subscribe2_options['notification_subject_twicedaily'] = $_POST['notification_subject_twicedaily'];
    }
    
    if ( !empty($_POST['notification_subject_daily']) ) { //42
    	$this->subscribe2_options['notification_subject_daily'] = $_POST['notification_subject_daily'];
    }
    
    if ( !empty($_POST['notification_subject_weekly']) ) { //42
    	$this->subscribe2_options['notification_subject_weekly'] = $_POST['notification_subject_weekly'];
    }
    
    if ( !empty($_POST['mailtext']) ) {
    	$this->subscribe2_options['mailtext'] = $_POST['mailtext'];
    }
    
    if ( !empty($_POST['mailtext_digest']) ) { // 42
    	$this->subscribe2_options['mailtext_digest'] = $_POST['mailtext_digest'];
    }

    Also added another Submit button at the top of the page, near the beginning of Email template section

    row 321:

    // submit
    echo "<p class=\"submit\" style=\"text-align: center\"><input type=\"submit\" class=\"button-primary\" name=\"submit\" value=\"" . __('Submit', 'subscribe2') . "\" /></p>"; //42
    
    // email templates

    New layout for new inputs: notification_subject_hourly/twicedaily/daily/weekly .
    New text box for digest mail (hourly/twicedaily/daily/weekly)

    row 332:

    //42 - Begin edit
    echo "<br /><b>" . __('Email subject line', 'subscribe2') . ": </b>";
    
    echo "<br /><br />\r\n"; //42
    
    echo "<label>" . __('If <em>For Each Post</em> option enabled', 'subscribe2') .": ";
    echo "<input type=\"text\" name=\"notification_subject\" value=\"" . stripslashes($this->subscribe2_options['notification_subject']) . "\" size=\"60\" />";
    echo "</label>";
    
    echo "<br />\r\n"; //42
    
    echo "<label>" . __('If <em>Hourly</em> option enabled', 'subscribe2') .": ";
    echo "<input type=\"text\" name=\"notification_subject_hourly\" value=\"" . stripslashes($this->subscribe2_options['notification_subject_hourly']) . "\" size=\"60\" />";
    echo "</label>";
    echo "<br />\r\n"; //42
    
    echo "<label>" . __('If <em>Twice a day</em> option enabled', 'subscribe2') .": ";
    echo "<input type=\"text\" name=\"notification_subject_twicedaily\" value=\"" . stripslashes($this->subscribe2_options['notification_subject_twicedaily']) . "\" size=\"60\" />";
    echo "</label>";
    echo "<br />\r\n"; //42
    
    echo "<label>" . __('If <em>Daily</em> option enabled', 'subscribe2') .": ";
    echo "<input type=\"text\" name=\"notification_subject_daily\" value=\"" . stripslashes($this->subscribe2_options['notification_subject_daily']) . "\" size=\"60\" />";
    echo "</label>";
    echo "<br />\r\n"; //42
    
    echo "<label>" . __('If <em>Weekly</em> option enabled', 'subscribe2') .": ";
    echo "<input type=\"text\" name=\"notification_subject_weekly\" value=\"" . stripslashes($this->subscribe2_options['notification_subject_weekly']) . "\" size=\"60\" />";
    echo "</label>";
    
    echo "<br /><br />\r\n";
    echo "<b>" . __('Email body', 'subscribe2') . ": </b>";
    
    echo "<br />\r\n";
    echo "<textarea rows=\"9\" cols=\"60\" name=\"mailtext\">" . stripslashes($this->subscribe2_options['mailtext']) . "</textarea>\r\n";
    
    echo "<br /><br />\r\n";
    echo "<b>" . __('Email body (for digest)', 'subscribe2') . ": </b>";
    echo "<br />\r\n";
    echo "<textarea rows=\"9\" cols=\"60\" name=\"mailtext_digest\">" . stripslashes($this->subscribe2_options['mailtext_digest']) . "</textarea>\r\n";
    
    //42 End Edit
  3. orion42
    Member
    Posted 1 year ago #

    File options.php

    row 146:

    if (!isset($this->subscribe2_options['notification_subject'])) {
    	$this->subscribe2_options['notification_subject'] = "[{BLOGNAME}] TITLE";
    } // Default notification email subject
    
    if (!isset($this->subscribe2_options['notification_subject_hourly'])) { //42
    	$this->subscribe2_options['notification_subject_hourly'] = "[{BLOGNAME}] TITLE";
    } // Default notification email subject
    
    if (!isset($this->subscribe2_options['notification_subject_twicedaily'])) { //42
    	$this->subscribe2_options['notification_subject_twicedaily'] = "[{BLOGNAME}] TITLE";
    } // Default notification email subject
    
    if (!isset($this->subscribe2_options['notification_subject_daily'])) { //42
    	$this->subscribe2_options['notification_subject_daily'] = "[{BLOGNAME}] TITLE";
    } // Default notification email subject
    
    if (!isset($this->subscribe2_options['notification_subject_weekly'])) { //42
    	$this->subscribe2_options['notification_subject_weekly'] = "[{BLOGNAME}] TITLE";
    } // Default notification email subject

    File: class-2-core.php

    row 148:

    // change old CAPITALISED keywords to those in {PARENTHESES}; since version 6.4
    $keywords = array('BLOGNAME', 'BLOGLINK', 'TITLE', 'POST', 'POSTTIME', 'TABLE', 'TABLELINKS', 'PERMALINK', 'TINYLINK', 'DATE', 'TIME', 'MYNAME', 'EMAIL', 'AUTHORNAME', 'LINK', 'CATS', 'TAGS', 'COUNT', 'ACTION');
    $keyword = implode('|', $keywords);
    $regex = '/(?<!\{)\b('.$keyword.')\b(?!\{)/xm';
    $replace = '{\1}';
    
    $this->subscribe2_options['mailtext'] = preg_replace($regex, $replace, $this->subscribe2_options['mailtext']);
    
    $this->subscribe2_options['mailtext_digest'] = preg_replace($regex, $replace, $this->subscribe2_options['mailtext_digest']);//42		
    
    $this->subscribe2_options['notification_subject'] = preg_replace($regex, $replace, $this->subscribe2_options['notification_subject']);
    $this->subscribe2_options['notification_subject_hourly'] = preg_replace($regex, $replace, $this->subscribe2_options['notification_subject_hourly']); //42
    $this->subscribe2_options['notification_subject_twicedaily'] = preg_replace($regex, $replace, $this->subscribe2_options['notification_subject_twicedaily']); //42
    $this->subscribe2_options['notification_subject_daily'] = preg_replace($regex, $replace, $this->subscribe2_options['notification_subject_daily']); //42
    $this->subscribe2_options['notification_subject_weekly'] = preg_replace($regex, $replace, $this->subscribe2_options['notification_subject_weekly']); //42

    row 302:

    $message = wordwrap(strip_tags($message), 140, "\n"); //42 - Raised the maximum number of char for better layout

    Use digest-template
    row 1489:

    // if we have posts, let's prepare the digest
    $datetime = get_option('date_format') . ' @ ' . get_option('time_format');
    $all_post_cats = array();
    $ids = array();
    //$mailtext = apply_filters('s2_email_template', $this->subscribe2_options['mailtext']);
    $mailtext = apply_filters('s2_email_template', $this->subscribe2_options['mailtext_digest']); //42 Use digest-template 
    
    $table = '';
    $tablelinks = '';
    $message_post= '';
    $message_posttime = '';
    
    $message_counter = 0 ; //42 - Define a new internal index for post

    Show the number of post in digest email (in future upgrade it will be a shortcode)
    e.g.
    #1 - Title 1
    Content 1

    #2 - Title 2
    ....

    row 1542:

    // if this post is excluded
    // don't include it in the digest
    if ( $check ) {
    	continue;
    }
    
    $post_title = html_entity_decode($post->post_title, ENT_QUOTES);
    ('' == $table) ? $table .= "* " . $post_title : $table .= "\r\n* " . $post_title;
    ('' == $tablelinks) ? $tablelinks .= "* " . $post_title : $tablelinks .= "\r\n* " . $post_title;
    
    $message_counter += 1 ; // 42 - Contatore interno dei post
    $post_title = "#" . $message_counter  . " - ". $post_title;//42

    New variable for post link (in digest)
    row 1751:

    $tablelinks .= "\r\n" . $this->get_tracking_link(get_permalink($post->ID)) . "\r\n";
    
    			$post_link = $this->get_tracking_link(get_permalink($post->ID)); //42

    Add a read more at the end of each single post (for digest) , and a line of - sign
    row 1619:

    $excerpt .= "\r\n\r\n" .  __( 'Read more: ') . "\r\n" . $post_link . "\r\n\r\n" ; //42 
    
    $message_post .= $excerpt . "\r\n\r\n";
    
    $message_post = $message_post . "---------------------------------------------------------------------------" . "\r\n\r\n"; //42
    
    $message_posttime .= $excerpt . "\r\n\r\n";

    Use a different title for hourly/twicedaily/daily/weekly digest
    Row 1660:

    $display = $scheds[$email_freq]['display'];
    
    //( '' == get_option('blogname') ) ? $subject = "" : $subject = "[" . stripslashes(html_entity_decode(get_option('blogname'), ENT_QUOTES)) . "] "; // 42 - Edited, removed
    
    // Get email subject // 42 Add the email title from settings page
    
    if ( $this->subscribe2_options['email_freq'] == 'hourly' ) {
      //$subject .= html_entity_decode(stripslashes(wp_kses($this->substitute($this->subscribe2_options['notification_subject']), ''))); //42
    	$subject .= html_entity_decode(stripslashes(wp_kses($this->substitute($this->subscribe2_options['notification_subject_hourly']), ''))); //42
    //	$subject .= "1";
    }elseif ( $this->subscribe2_options['email_freq'] == 'twicedaily' ) {
    		$subject .= html_entity_decode(stripslashes(wp_kses($this->substitute($this->subscribe2_options['notification_subject_twicedaily']), ''))); //42
    }elseif ( $this->subscribe2_options['email_freq'] == 'daily' ) {
    		$subject .= html_entity_decode(stripslashes(wp_kses($this->substitute($this->subscribe2_options['notification_subject_daily']), ''))); //42
    }elseif ( $this->subscribe2_options['email_freq'] == 'weekly' ) {
    		$subject .= html_entity_decode(stripslashes(wp_kses($this->substitute($this->subscribe2_options['notification_subject_weekly']), ''))); //42
    }

    If you need I can send you the edited files

    I often use http://mergely.com/ for comparing fies

  4. mattyrob
    Member
    Posted 1 year ago #

    @orion42,

    While I can see that you have a reasonable case for adding these new options I don't this this would appeal to a great number of Subscribe2 users and may even confuse the already extensive Settings page.

    You could make use of the in-built 's2_email_subject' filter to assess the Subscribe2 frequency settings and return the appropriate email subject. Maybe something like this:

    function s2_subject_changes($subject) {
    	global $mysubscribe2;
    	if ($mysubscribe2->subscribe2_options['email_freq'] == 'never') {
    		return "This is my preferred per-post email subject";
    	} elseif ($mysubscribe2->subscribe2_options['email_freq'] == 'hourly') {
    		return "This is my preferred hourly email subject";
    	} elseif ($mysubscribe2->subscribe2_options['email_freq'] == 'daily') {
    		return "This is my preferred daily email subject";
    	} else {
    		return "Defautl email subject";
    	}
    }
    add_filter('s2_email_subject', 's2_subject_changes');

    Also, the proposed {number_of_new_post} keyword already exists as {COUNT}.

    Thanks for the tip re merely.com but I use TextWrangler on OSX and it offers that feature on my desktop with the ability to cross merge.

  5. orion42
    Member
    Posted 1 year ago #

    Maybe I've made too many changes also for my use. I think in my script I'll edit and use only two titles and two text for single post and digest mail (in this way there are only 2 field more than the original)

    Anyway there are some of my code that can be useful to everybody:

    - I've add a button near the top of the page, so you don't have to scroll till the bottom. (in settings.php)
    - Added a label tag for the input box (also i've set a higher number of character for the input box)

    Can you re-think about the first edit I've made ? I think it's a lot better if the digest mail has the title taken from the 'notification_subject' and not a standard text like
    [{BLOGNAME}] - "Daily/Weekly Digest Report"

    I've another question:

    My digest mail sometime shows up to the last 5 article posted in the blog, intead of only the new published ones. There can be some problem related to wp-cron ? ( The plugin still needs wp-cron for digest ? )
    thanks

  6. mattyrob
    Member
    Posted 1 year ago #

    @orion42,

    You don't need the WP-Cron plugin anymore, it was built into the WordPress core a long time ago. It might be to do with that but I can't be sure as I haven't used it for such a long time.

  7. mattyrob
    Member
    Posted 1 year ago #

    @orion42,

    Try the development code for the plugin, I've improved (I think anyway) the settings page to have a tabbed interface so the Submit button needs much less scrolling :)

    Let me know what you think if you take a look.

  8. orion42
    Member
    Posted 1 year ago #

    I did not know existed the development log, i think is really useful. It seems like the one in google-code projects.
    Where can I see what revision of the plugin do I have ? (from the wp-plugin settings page I can only see the main version number)

    Another couple of question (related to my problems, so I can understand better the original plugin behavior):
    With daily/week report the plugin should send email each day/week always ? Also if there are no new posts ?
    The report mail should contain only the new posts ?

    And a couple of possible future upgrade:
    - Adding the featured image in html mail (maybe with a shortcode {IMAGE} ). or also custom field (I use custom post field to have different preview in home page or if the article doesen't have an image)
    - Subscribers option to chose the frequency of mail (each/daily/week/...)

  9. mattyrob
    Member
    Posted 1 year ago #

    @orion42,

    There isn't really a version number for the development code - the stables releases are the only versioned code. The Development code and log allows early access though.

    The Digest mail only sends if there is new content, it doesn't send all old items and it doesn't send if there hasn't been anything newly published.

    {IMAGE} is in the paid version and allowing Subscribers to choose email frequency has been requested before and is on the roadmap for some time in the future.

  10. orion42
    Member
    Posted 1 year ago #

    That's a lot better.
    Anyway now the only main edit I keep is to change the email subject for digest, just 2 rows in class-s2-core.php @ 1639
    Removed:

    //( '' == get_option('blogname') ) ? $subject = "" : $subject = "[" . stripslashes(html_entity_decode(get_option('blogname'), ENT_QUOTES)) . "] "; // 42 - Removed
    //$subject .= $display . " " . __('Digest Email', 'subscribe2'); //42 - Removed

    Added:
    $subject = html_entity_decode(stripslashes(wp_kses($this->substitute($this->subscribe2_options['notification_subject']), ''))); // Get email subject // 42 - Add the email title from settings page

  11. mattyrob
    Member
    Posted 1 year ago #

    @orion42,

    This is an unnecessary change as there is a filter for the email subject called 's2_email_subject'.

    You can apply a filter to this that checks the subjects for the word "Digest" and if it does replace it with your preferred text.

  12. orion42
    Member
    Posted 1 year ago #

    I' just copy and paste the $subject declaration as in single email.
    I'm not so expert with filters. Where I have to declare it (If I declare the filter out of this script then I still can access the subscribe2_options variable, or they are declared locally)?
    Can you write me an example about it?

  13. mattyrob
    Member
    Posted 1 year ago #

    @orion42,

    The basics are covered in the FAQ, but the code would look something like this:

    function s2_subject_changes($subject) {
    global $mysubscribe2;
    if ( strpos($subject, 'Digest') ) {
    return html_entity_decode(stripslashes(wp_kses($this->substitute($this->subscribe2_options['notification_subject']), '')));;
    }
    }

    add_filter('s2_email_subject', 's2_subject_changes');

    (create a new plugin with this or add to your theme functions.php file)

  14. orion42
    Member
    Posted 1 year ago #

    Thanks very much !
    If I understand well, I can do the same with the future "maximum char number" variable (and with also other variable already set) and adding a filter that change the value without edit the script file, right ?

    Something like this:

    function s2_message_chars_changes($message_chars) {
    global $mysubscribe2;
       if ( $output != '140') ) {
          return 140;
       }
    }
    
    add_filter('s2_email_max_msg_chars', 's2_message_chars_changes');
  15. mattyrob
    Member
    Posted 1 year ago #

    @orion42,

    No, this isn't something you can use for everything, only in places where the code allows it through implementation of a filter. (Essentially an API)

    There is a filter for the email subject as quite a few people want to have control over it, there isn't one for the word wrap length as in 6 years you are the only person to raise an issue.

  16. orion42
    Member
    Posted 1 year ago #

    ok, and there is a filter also for the email body ?
    In digest mail I've edted the code to have a bold title and and a dashed line as separator between the single article excract.

  17. mattyrob
    Member
    Posted 1 year ago #

    @orion42,

    There is but it would involve you creating code to entirely rework the digest email to make individual changes within the body of the email.

    If you want to try anyway the filter is called 's2_digest_email'.

  18. orion42
    Member
    Posted 1 year ago #

    Thanks,
    if I´ll have some free time I´ll Maybe if it's to complex I´ll be not worth it just for a bold title and a dashed line.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic