Plugin Directory

Changeset 1032176


Ignore:
Timestamp:
11/24/2014 11:20:02 PM (11 years ago)
Author:
dansod
Message:

Added new version 1.1.0

Location:
subscribe-to-category/trunk
Files:
5 edited

Legend:

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

    r1028927 r1032176  
    2020     * Initialize the plugin by setting localization and loading public scripts
    2121     * and styles.
     22     *
     23     * @since  1.0.0
    2224     */
    2325    private function __construct() {
     
    3234        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
    3335
     36        // load admin css
     37        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
     38
     39        // load admin scripts
     40        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
     41
    3442    }
    3543
    3644    /**
    3745     * Single instance of this class.
     46     *
     47     * @since  1.0.0
    3848     */
    3949    public static function get_instance() {
     
    4959    /**
    5060     * Store options to an array
     61     *
     62     * @since  1.0.0
    5163     */
    5264    private function set_options(){
     
    5668    /**
    5769     * Return the plugin slug.
     70     *
     71     * @since  1.0.0
    5872     */
    5973    public function get_plugin_slug() {
     
    6377    /**
    6478     * Fired when the plugin is activated.
     79     *
     80     * @since  1.0.0
    6581     */
    6682    public static function activate( $network_wide ) {
     
    93109    /**
    94110     * Fired when the plugin is deactivated.
     111     *
     112     * @since  1.0.0
    95113     */
    96114    public static function deactivate( $network_wide ) {
     
    126144     * Add some settings when plugin is activated
    127145     * - Cron schedule
     146     *
     147     * @since  1.0.0
    128148     */
    129149    private static function single_activate() {
     
    140160     * - delete options
    141161     * - delete hook
     162     *
     163     * @since  1.0.0
    142164     */
    143165    private static function single_deactivate() {
     
    182204    /**
    183205     * Get all blog ids of blogs
     206     *
     207     * @since  1.0.0
    184208     */
    185209    private static function get_blog_ids() {
     
    194218    /**
    195219     * Load the plugin text domain for translation
     220     *
     221     * @since  1.0.0
    196222     */
    197223    public function load_plugin_textdomain() {
     
    201227    /**
    202228     * Register and enqueue public style sheet
     229     *
     230     * @since  1.0.0
    203231     */
    204232    public function enqueue_styles() {
     
    209237    }
    210238
     239
     240    /**
     241    * Register and enqueue admin style sheet
     242    *
     243    * @since  1.1.0
     244    */
     245    public function enqueue_admin_styles() {
     246        wp_enqueue_style( 'stc-admin-style', STC_PLUGIN_URL . '/css/admin-style.css', array() );
     247    }
     248
     249    /**
     250    * Register and enqueue admin scripts
     251    *
     252    * @since  1.1.0
     253    */
     254    public function enqueue_admin_scripts() {
     255
     256    wp_register_script( 'back-end-script', STC_PLUGIN_URL . '/js/admin-script.js', array( 'jquery' ), false, true );
     257 
     258    // load stc back-end script
     259    wp_enqueue_script( 'back-end-script' );
     260
     261    wp_localize_script( 'back-end-script', 'ajax_object', array(
     262      'ajaxurl'     => admin_url( 'admin-ajax.php' ),
     263      'ajax_nonce'  => wp_create_nonce('ajax_nonce')
     264      )
     265    ); // setting ajaxurl and nonce
     266           
     267       
     268    }
     269
     270
    211271}
  • subscribe-to-category/trunk/classes/class-settings.php

    r1028927 r1032176  
    2222    /**
    2323     * Constructor
     24     *
     25     * @since  1.0.0
    2426     */
    2527    public function __construct() {
     
    2931        add_action( 'admin_menu', array( $this, 'add_plugin_page' ) );
    3032        add_action( 'admin_init', array( $this, 'register_settings' ) );
    31         add_action( 'init', array( $this, 'get_requests'), 999 ); // $_GET
    32         add_action( 'init', array( $this, 'get_transients'), 99 ); // transients
     33
     34        // Ajax call for sendings emails manually
     35        add_action( 'wp_ajax_force_run', array( $this, 'force_run' ) );
    3336
    3437      }
     
    3841
    3942    /**
    40      * Getting $_GET requests
    41      */
    42     public function get_requests(){
    43 
    44       // Bypass scheduled event and run event manually
    45       if( isset( $_GET['action'] ) && $_GET['action'] == 'stc-force-run' ){
    46 
    47         // security check
    48         if( !current_user_can('manage_options') )
    49           die(__( 'You are not allowed to run this action.', STC_TEXTDOMAIN ));
    50 
    51         // check nonce
    52         check_admin_referer( 'stc_force_run');
    53 
    54         $subscriber = STC_Subscribe::get_instance();
    55         $subscriber->stc_send_email();
    56 
    57         // Redirect to url for settings and print notice
    58         $url = admin_url( 'options-general.php?page=stc-subscribe-settings' );
    59        
    60         // set transient for showing admin notice in settings
    61         set_transient( 'stc_notice_id', '1', 3600 );
    62         wp_redirect( $url );
    63         exit;       
    64 
    65       }
    66  
    67     }
    68 
    69     /**
    70      * Get transients
    71      */
    72     public function get_transients(){
    73 
    74       $notice = get_transient( 'stc_notice_id' );
    75 
    76       // add action for admin_notices if there is a transient set
    77       if( !empty( $notice ) ){
    78         add_action( 'admin_notices', array( $this, 'stc_admin_notice' ) );
    79       }
    80 
    81       return false;
    82     }
    83 
    84 
    85     /**
    86      * Prints out admin notice in settings
    87      */
    88     public function stc_admin_notice(){
    89 
    90       $notice = $this->get_admin_notice( get_transient('stc_notice_id') );
    91 
    92       $notice_class = 'updated';
    93       if( get_transient('stc_notice_id') == 0 ){
    94         $notice_class = 'error';
    95       }
    96 
    97       printf( '<div id="message" class="%s"><p><strong>%s</strong></p></div>', $notice_class, $notice );
    98       delete_transient( 'stc_notice_id' );
    99      
    100     }
    101 
    102     /**
    103      * Returns messages to show in admin notice
    104      *
    105      * @param  int $notice_id
    106      * @return array with notice id
    107      */
    108     public function get_admin_notice( $notice_id ){
    109       $notice = array(
    110         __( 'Something went wrong when triggering scheduled event', STC_TEXTDOMAIN ),
    111         __( 'Scheduled event successfully executed', STC_TEXTDOMAIN )
    112       );
    113      
    114       return $notice[$notice_id];
     43     * Ajax call for trigger send action manually
     44     *
     45     * @since  1.1.0
     46     *
     47     * @return [type] [description]
     48     */
     49    public function force_run(){
     50      check_ajax_referer( 'ajax_nonce', 'nonce' );
     51 
     52      $subscriber = STC_Subscribe::get_instance();
     53      $subscriber->stc_send_email();
     54
     55      _e( 'Scheduled event successfully executed', STC_TEXTDOMAIN );
     56
     57      die();
    11558    }
    11659
    11760    /**
    11861     * Add options page
     62     *
     63     * @since  1.0.0
     64     *
    11965     */
    12066    public function add_plugin_page() {
     
    14288    /**
    14389     * Options page callback
     90     *
     91     * @since  1.0.0
     92     *
    14493     */
    14594    public function create_admin_page() {
     
    160109              <td class="desc"><strong><?php _e( 'Schedule: ', STC_TEXTDOMAIN ); ?></strong> <?php _e('E-mail is scheduled to be sent once every hour.', STC_TEXTDOMAIN ); ?></td>
    161110              <td class="desc"></td>
    162               <td class="desc textright"><a href="<?php echo wp_nonce_url('options-general.php?page=stc-subscribe-settings&action=stc-force-run', 'stc_force_run');?>"> <?php _e( 'Click here to run this action right now', STC_TEXTDOMAIN ); ?></a></td>
     111              <td class="desc textright"><div class="stc-force-run-action"><button type="button" id="stc-force-run" class="button button-primary"><?php _e( 'Click here to run this action right now', STC_TEXTDOMAIN ); ?></button></div></td>
    163112            </tr>
    164113            <tr>
    165               <td class="desc" colspan="3"><?php printf( __('Next run is going to be <strong>%s</strong> and will include %s posts.', STC_TEXTDOMAIN ), $next_run, $this->get_posts_in_que() ); ?></td>
     114              <td class="desc" colspan="3"><?php printf( __('Next run is going to be <strong>%s</strong> and will include %s posts.', STC_TEXTDOMAIN ), $next_run, '<span id="stc-posts-in-que">' . $this->get_posts_in_que() . '</span>' ); ?></td>
    166115            </tr>
    167116          </tbody>
     
    186135    /**
    187136     * Get current posts in que to be sent
     137     *
     138     * @since  1.0.0
     139     *
    188140     * @return int sum of posts
    189141     */
     
    209161    /**
    210162     * Returns the time in seconds until a specified cron job is scheduled.
     163     *
     164     * @since  1.0.0
    211165    */
    212166    public function get_next_cron_time( $cron_name ){
     
    224178    /**
    225179     * Register and add settings
     180     *
     181     * @since  1.0.0
     182     *
    226183     */
    227184    public function register_settings(){       
     
    294251    }
    295252
     253    /**
     254     * Print outs text for deactivation info
     255     *
     256     * @since  1.0.0
     257     *
     258     * @return [type] [description]
     259     */
    296260    public function section_deactivation_info(){
    297261      ?>
     
    302266    /**
    303267     * Sanitize setting fields
     268     *
     269     * @since  1.0.0
     270     *
    304271     * @param array $input
    305272     */
     
    336303    /**
    337304     * Printing section text
     305     *
     306     * @since  1.0.0
     307     *
    338308     */
    339309    public function print_section_info(){
     
    343313    /**
    344314     * Get the settings option array and print one of its values
     315     *
     316     * @since  1.0.0
     317     *
    345318     */
    346319    public function stc_email_from_callback() {
     
    354327    /**
    355328     * Get the settings option array and print one of its values
     329     *
     330     * @since  1.0.0
     331     *
    356332     */
    357333    public function stc_title_callback() {
     
    364340    /**
    365341     * Get the settings option array and print one of its values
     342     *
     343     * @since  1.0.0
     344     *
    366345     */
    367346    public function stc_css_callback() {
     
    379358    /**
    380359     * Get the settings option array and print one of its values
     360     *
     361     * @since  1.0.0
     362     *
    381363     */
    382364    public function stc_remove_subscribers_callback() {
     
    394376    /**
    395377     * Form for filtering categories on export to excel
     378     *
     379     * @since  1.0.0
     380     *
    396381     */
    397382    public function export_to_excel_form(){
     
    426411    /**
    427412     * Export method for excel
     413     *
     414     * @since  1.0.0
     415     *
    428416     */
    429417    public function export_to_excel(){
     
    497485    /**
    498486     * Method for cleaning data to excel
     487     *
     488     * @since  1.0.0
     489     *
    499490     */
    500491    public function clean_data_for_excel( &$str ) {
  • subscribe-to-category/trunk/classes/class-subscribe.php

    r1028927 r1032176  
    2424    private $settings = array();
    2525    private $post_type = 'stc';
    26 
     26    private $sleep_flag = 25;
     27
     28    /**
     29     * Constructor
     30     *
     31     * @since  1.0.0
     32     */
    2733    function __construct(){
    2834        $this->init();
     
    3137    /**
    3238     * Single instance of this class.
     39     *
     40     * @since  1.0.0
    3341     */
    3442    public static function get_instance() {
     
    4452    /**
    4553     * Init method
    46      * @return [type] [description]
     54     *
     55     * @since  1.0.0
     56     *
     57     * @return [type] [description]
    4758     */
    4859    private function init(){
    4960
    50 
    51 
    5261      add_action( 'init', array( $this, 'register_post_type'), 99 );
    5362      add_action( 'create_category', array( $this, 'update_subscriber_categories') );
     
    7281    /**
    7382     * Adding a newly created category to subscribers who subscribes to all categories
     83     *
     84     * @since  1.0.0
     85     *
    7486     * @param $category_id The id for newly created category
    7587     */
     
    104116    /**
    105117     * Method for printing unsubscription text on custom page
     118     *
     119     * @since  1.0.0
    106120     */
    107121    public function unsubscribe_html(){
     
    122136    /**
    123137     * Collecting data through _GET
    124      *
     138     *
     139     * @since  1.0.0
    125140     */
    126141    public function collect_get_data(){
     
    150165     *
    151166     * @TODO: add contact email if something went wrong
     167     *
     168     * @since  1.0.0
    152169     */
    153170    private function unsubscribe_user(){
     
    183200    /**
    184201     * Listen for every new post and update post meta if post type 'post'
     202     *
     203     * @since  1.0.0
     204     *
    185205     * @param  string $old_status
    186206     * @param  string $new_status
     
    203223    /**
    204224     * Sending an email to a subscriber with a confirmation link to unsubscription
     225     *
     226     * @since  1.0.0
     227     *
    205228     * @param  int $stc_id post id for subscriber
    206229     * @return [type]         [description]
     
    245268    /**
    246269     * Returns the content for email unsubscription
     270     *
     271     * @since  1.0.0
     272     *
    247273     * @param  array $stc
    248274     * @return string
     
    261287    /**
    262288     * Collect data from _POST for subscription
     289     *
     290     * @since  1.0.0
     291     *
    263292     * @return string Notice to user
    264      *
    265293     */
    266294    public function collect_post_data(){
     
    346374    /**
    347375     * Check if subscriber already exists
     376     *
     377     * @since  1.0.0
     378     *
    348379     * @return int post_id
    349380     */
     
    363394    /**
    364395     * Update user with selected categories if user exists, else add user as new user.
     396     *
     397     * @since  1.0.0
     398     * 
    365399     * @param  string $post_data currently not in use
    366400     */
     
    406440    /**
    407441     * Save post for stc post_type from admin
     442     *
     443     * @since  1.0.0
    408444     */
    409445    public function save_post_stc( $post_id ) {
     
    482518    /**
    483519     * Display error in wordpress format as notice if exists
     520     *
     521     * @since  1.0.0
    484522     */
    485523    public function save_post_stc_error(){
     
    498536    /**
    499537     * Render html to subscribe to categories
    500      * @return [type] [description]
     538     *
     539     * @since  1.0.0
     540     *
     541     * @return [type] [description]
    501542     *
    502543     * @todo add some filter
     
    516557    /**
    517558     * Adding jQuery to footer
     559     *
     560     * @since  1.0.0
    518561     */
    519562    public function add_script_to_footer(){
     
    559602    /**
    560603     * Html for subscribe form
     604     *
     605     * @since  1.0.0
     606     * 
    561607     * @return [type] [description]
    562608     */
     
    647693    /**
    648694     * On the scheduled action hook, run a function.
     695     *
     696     * @since  1.0.0
    649697     */
    650698    public function stc_send_email() {
     
    680728        $this->send_notifier( $outbox );
    681729      }
     730
    682731    }
    683732
    684733    /**
    685734     * Send notifier to subscribers
     735     *
     736     * @since  1.0.0
     737     *
    686738     * @param  object $outbox
    687739     */
     
    739791
    740792      // loop through subscribers and send notice
     793      $i = 1; // loop counter
    741794      foreach ($emails as $email ) {
    742795
     
    754807        wp_mail( $email['email'], $subject, $message, $headers );
    755808
     809        // sleep 2 seconds once every 25 email to prevent blacklisting
     810        if( $i == $sleep_flag ){
     811          sleep(2); // sleep for two seconds, then proceed
     812          $i = 1; // reset loop counter
     813        }
     814
     815        $i++;
     816
    756817      }
    757818
     
    767828     * Render html to email.
    768829     * Setting limit to content as we still want the user to click and visit our site.
     830     *
     831     * @since  1.0.0
     832     *
    769833     * @param  object $email
    770834     */   
     
    781845    /**
    782846     * Cut a text string closest word on a given length.
     847     *
     848     * @since  1.0.0
     849     *
    783850     * @param  string $string
    784851     * @param  int $max_length
     
    806873    /**
    807874     * Get all subscribers with subscribed categories
     875     *
     876     * @since  1.0.0
     877     *
    808878     * @return object Subscribers
    809879     */
     
    837907    /**
    838908     * Register custom post type for subscribers
     909     *
     910     * @since  1.0.0
    839911     */
    840912    public function register_post_type(){
  • subscribe-to-category/trunk/readme.txt

    r1028956 r1032176  
    44Requires at least: 3.9
    55Tested up to: 4.0
    6 Stable tag: 1.0.0
     6Stable tag: 1.1.0
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5757== Changelog ==
    5858
     59= 1.1.0 =
     60* Added php sleep() function to prevent sending all e-mails in the same scope.
     61* Using Ajax when send is manually triggered in back-end
     62
    5963= 1.0.0 =
    6064* First release
  • subscribe-to-category/trunk/subscribe-to-category.php

    r1028928 r1032176  
    44  Plugin URI: http://dcweb.nu
    55  Description: Lets your visitor subscribe to posts for one or several categories.
    6   Version: 1.0.0
     6  Version: 1.1.0
    77  Author: Daniel Söderström
    88  Author URI: http://dcweb.nu/
Note: See TracChangeset for help on using the changeset viewer.