Plugin Directory

Changeset 1234449


Ignore:
Timestamp:
08/31/2015 07:50:47 AM (11 years ago)
Author:
dansod
Message:

Added hooks and filters to make the plugin extensible

Location:
subscribe-to-category/trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • subscribe-to-category/trunk/classes/class-subscribe.php

    r1205558 r1234449  
    7777
    7878      // adding checkbox to publish meta box if activated
    79       if( $this->settings['resend_option'] == 1 )
     79      if( isset( $this->settings['resend_option'] ) && $this->settings['resend_option'] == 1 )
    8080        add_action( 'post_submitbox_misc_actions', array( $this, 'resend_post_option' ) );
    8181
     
    946946        $subject = '=?UTF-8?B?'.base64_encode( $email_subject ).'?=';
    947947
    948         wp_mail( $email['email'], $subject, $message, $headers );
     948
     949        if( STC_DEV_MODE === true ){
     950          echo $subject . '<br>' . $message;
     951          die();
     952        }else{
     953          wp_mail( $email['email'], $subject, $message, $headers ); 
     954        }
     955
    949956
    950957        // sleep 2 seconds once every 25 email to prevent blacklisting
     
    9951002     */   
    9961003    private function email_html_content( $email ){
     1004      $sum_of_words = 130;
     1005
     1006      $output['title']        = '<h3><a href="' . get_permalink( $email['post_id'] ) . '">' . $email['post']->post_title . '</a></h3>';
     1007      $output['link_to_post'] = '<div style="border-bottom: 1px solid #cccccc; padding-bottom: 10px;"><a href="' . get_permalink( $email['post_id'] ) .'">' . __('Click here to read full story', STC_TEXTDOMAIN ) . '</a></div>';
     1008      $output['unsubscribe']  = '<div style="margin-top: 20px;"><a href="' . get_bloginfo('url') . '/?stc_unsubscribe=' . $email['hash'] . '&stc_user=' . $email['email'] . '">' . __('Unsubscribe me', STC_TEXTDOMAIN ) . '</a></div>';
     1009
    9971010      ?>
    998       <h3><a href="<?php echo get_permalink( $email['post_id']) ?>"><?php echo $email['post']->post_title; ?></a></h3>
    999       <div><?php echo apply_filters('the_content', $this->string_cut( $email['post']->post_content, 130 ) );?></div>
    1000       <div style="border-bottom: 1px solid #cccccc; padding-bottom: 10px;"><a href="<?php echo get_permalink( $email['post_id'] ); ?>"> <?php _e('Click here to read full story', STC_TEXTDOMAIN ); ?></a></div>
    1001       <div style="margin-top: 20px;"><a href="<?php echo get_bloginfo('url') . '/?stc_unsubscribe=' . $email['hash'] . '&stc_user=' . $email['email']; ?>"><?php _e('Unsubscribe me', STC_TEXTDOMAIN ); ?></a></div>
     1011      <?php do_action( 'stc_before_message', $email['post_id'], $email['subscriber_id'] ); ?>
     1012     
     1013      <?php do_action( 'stc_before_message_title', $email['post_id'], $email['subscriber_id'] ); ?>
     1014      <?php echo apply_filters( 'stc_message_title_html', $output['title'], $email['post_id'], $email['subscriber_id'] ); ?>
     1015      <?php do_action( 'stc_after_message_title', $email['post_id'], $email['subscriber_id'] ); ?>
     1016
     1017      <?php do_action( 'stc_before_message_content', $email['post_id'], $email['subscriber_id'] ); ?>
     1018      <div><?php echo apply_filters('the_content', $this->string_cut( $email['post']->post_content, apply_filters( 'stc_message_length_sum_of_words', $sum_of_words ) ) );?></div>
     1019      <?php do_action( 'stc_after_message_content', $email['post_id'], $email['subscriber_id'] ); ?>
     1020
     1021      <?php echo apply_filters( 'stc_message_link_to_post_html', $output['link_to_post'] ); ?>
     1022      <?php echo apply_filters( 'stc_message_unsubscribe_html', $output['unsubscribe'] ); ?>
     1023
     1024      <?php do_action( 'stc_after_message', $email['post_id'], $email['subscriber_id'] ); ?>
     1025
    10021026      <?php
    10031027    }
     
    10131037     * @return string
    10141038     */
    1015     private function string_cut( $string, $max_length ){ 
     1039    private function string_cut( $string, $max_length ){
     1040
     1041      if( $max_length < 0 )
     1042        return $string;
    10161043
    10171044      // remove shortcode if there is
  • subscribe-to-category/trunk/readme.txt

    r1205558 r1234449  
    33Tags: subscribe to post, subscribe to category, subscribe to news, subscribe
    44Requires at least: 3.9
    5 Tested up to: 4.2.3
    6 Stable tag: 1.2.1
     5Tested up to: 4.3
     6Stable tag: 1.3
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3535* French
    3636* Italian
     37* Lithuanian
    3738* Russian
    3839* Spanish
     
    5657For both attributes you can use a comma sign to separate multiple categories, like [stc-subscribe category_in="news, article"].
    5758
     59= Filter and hooks =
     60Following filters and hooks can be used for customizing the email message.
     61
     62`<?php
     63// FILTERS
     64// Parameters: $value
     65add_filter( 'stc_message_length_sum_of_words', 'stc_message_length_sum_of_words', 10, 1 ); //set return value to a negative number to show the full content
     66
     67
     68// Parameters: $value, $post_id, $subscriber_post_id
     69add_filter( 'stc_message_title_html', 'my_stc_message_title_html', 10, 3 );
     70add_filter( 'stc_message_link_to_post_html', 'my_stc_message_link_to_post_html', 10, 3 );
     71add_filter( 'stc_message_unsubscribe_html', 'my_stc_message_unsubscribe_html', 10, 3 );
     72
     73// HOOKS
     74// Parameters: $post_id, $subscriber_post_id 
     75add_action( 'stc_before_message', 'my_stc_before_message', 10, 2 );
     76add_action( 'stc_before_message_title', 'my_stc_before_message_title', 10, 2 );
     77add_action( 'stc_after_message_title', 'my_stc_after_message_title', 10, 2 );
     78add_action( 'stc_before_message_content', 'my_stc_before_message_content', 10, 2 );
     79add_action( 'stc_after_message_content', 'my_stc_after_message_content', 10, 2 );
     80add_action( 'stc_after_message', 'my_stc_after_message', 10, 2 );
     81
     82
     83/**
     84 * Example for adding featured image to STC email
     85 */
     86function my_stc_after_message_title( $post_id ){
     87    echo get_the_post_thumbnail( $post_id, 'thumbnail' );
     88}
     89add_action( 'stc_after_message_title', 'my_stc_after_message_title', 10, 2 );
     90
     91?>`
     92
     93
    5894= Optionally but recommended =
    5995As Wordpress Cron is depending on that you have visits on your website you should set up a cron job on your server to hit http://yourdomain.com/wp-cron.php at a regular interval to make sure that WP Cron is running as expected. In current version of Subscribe to Category the WP Cron is running once every hour, that might be an option that is changeable in future versions.
     
    68104
    69105== Changelog ==
     106
     107= 1.3 =
     108* Added hooks and filters to make the plugin extensible
     109* Added Lithuanian language thanks to Claudio
    70110
    71111= 1.2.1 =
  • subscribe-to-category/trunk/subscribe-to-category.php

    r1205565 r1234449  
    44  Plugin URI: http://dcweb.nu
    55  Description: Lets your visitor subscribe to posts for one or several categories.
    6   Version: 1.2.1
     6  Version: 1.3
    77  Author: Daniel Söderström
    88  Author URI: http://dcweb.nu/
     
    1818  define( 'STC_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
    1919  define( 'STC_PLUGIN_PATH', dirname( __FILE__ ) );
     20  define( 'STC_DEV_MODE', false ); // set to true email is printed out on setting page and will not be sent.
    2021
    2122  require_once( 'classes/class-main.php' );
Note: See TracChangeset for help on using the changeset viewer.