Changeset 1032176
- Timestamp:
- 11/24/2014 11:20:02 PM (11 years ago)
- Location:
- subscribe-to-category/trunk
- Files:
-
- 5 edited
-
classes/class-main.php (modified) (12 diffs)
-
classes/class-settings.php (modified) (18 diffs)
-
classes/class-subscribe.php (modified) (26 diffs)
-
readme.txt (modified) (2 diffs)
-
subscribe-to-category.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
subscribe-to-category/trunk/classes/class-main.php
r1028927 r1032176 20 20 * Initialize the plugin by setting localization and loading public scripts 21 21 * and styles. 22 * 23 * @since 1.0.0 22 24 */ 23 25 private function __construct() { … … 32 34 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); 33 35 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 34 42 } 35 43 36 44 /** 37 45 * Single instance of this class. 46 * 47 * @since 1.0.0 38 48 */ 39 49 public static function get_instance() { … … 49 59 /** 50 60 * Store options to an array 61 * 62 * @since 1.0.0 51 63 */ 52 64 private function set_options(){ … … 56 68 /** 57 69 * Return the plugin slug. 70 * 71 * @since 1.0.0 58 72 */ 59 73 public function get_plugin_slug() { … … 63 77 /** 64 78 * Fired when the plugin is activated. 79 * 80 * @since 1.0.0 65 81 */ 66 82 public static function activate( $network_wide ) { … … 93 109 /** 94 110 * Fired when the plugin is deactivated. 111 * 112 * @since 1.0.0 95 113 */ 96 114 public static function deactivate( $network_wide ) { … … 126 144 * Add some settings when plugin is activated 127 145 * - Cron schedule 146 * 147 * @since 1.0.0 128 148 */ 129 149 private static function single_activate() { … … 140 160 * - delete options 141 161 * - delete hook 162 * 163 * @since 1.0.0 142 164 */ 143 165 private static function single_deactivate() { … … 182 204 /** 183 205 * Get all blog ids of blogs 206 * 207 * @since 1.0.0 184 208 */ 185 209 private static function get_blog_ids() { … … 194 218 /** 195 219 * Load the plugin text domain for translation 220 * 221 * @since 1.0.0 196 222 */ 197 223 public function load_plugin_textdomain() { … … 201 227 /** 202 228 * Register and enqueue public style sheet 229 * 230 * @since 1.0.0 203 231 */ 204 232 public function enqueue_styles() { … … 209 237 } 210 238 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 211 271 } -
subscribe-to-category/trunk/classes/class-settings.php
r1028927 r1032176 22 22 /** 23 23 * Constructor 24 * 25 * @since 1.0.0 24 26 */ 25 27 public function __construct() { … … 29 31 add_action( 'admin_menu', array( $this, 'add_plugin_page' ) ); 30 32 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' ) ); 33 36 34 37 } … … 38 41 39 42 /** 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(); 115 58 } 116 59 117 60 /** 118 61 * Add options page 62 * 63 * @since 1.0.0 64 * 119 65 */ 120 66 public function add_plugin_page() { … … 142 88 /** 143 89 * Options page callback 90 * 91 * @since 1.0.0 92 * 144 93 */ 145 94 public function create_admin_page() { … … 160 109 <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> 161 110 <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> 163 112 </tr> 164 113 <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> 166 115 </tr> 167 116 </tbody> … … 186 135 /** 187 136 * Get current posts in que to be sent 137 * 138 * @since 1.0.0 139 * 188 140 * @return int sum of posts 189 141 */ … … 209 161 /** 210 162 * Returns the time in seconds until a specified cron job is scheduled. 163 * 164 * @since 1.0.0 211 165 */ 212 166 public function get_next_cron_time( $cron_name ){ … … 224 178 /** 225 179 * Register and add settings 180 * 181 * @since 1.0.0 182 * 226 183 */ 227 184 public function register_settings(){ … … 294 251 } 295 252 253 /** 254 * Print outs text for deactivation info 255 * 256 * @since 1.0.0 257 * 258 * @return [type] [description] 259 */ 296 260 public function section_deactivation_info(){ 297 261 ?> … … 302 266 /** 303 267 * Sanitize setting fields 268 * 269 * @since 1.0.0 270 * 304 271 * @param array $input 305 272 */ … … 336 303 /** 337 304 * Printing section text 305 * 306 * @since 1.0.0 307 * 338 308 */ 339 309 public function print_section_info(){ … … 343 313 /** 344 314 * Get the settings option array and print one of its values 315 * 316 * @since 1.0.0 317 * 345 318 */ 346 319 public function stc_email_from_callback() { … … 354 327 /** 355 328 * Get the settings option array and print one of its values 329 * 330 * @since 1.0.0 331 * 356 332 */ 357 333 public function stc_title_callback() { … … 364 340 /** 365 341 * Get the settings option array and print one of its values 342 * 343 * @since 1.0.0 344 * 366 345 */ 367 346 public function stc_css_callback() { … … 379 358 /** 380 359 * Get the settings option array and print one of its values 360 * 361 * @since 1.0.0 362 * 381 363 */ 382 364 public function stc_remove_subscribers_callback() { … … 394 376 /** 395 377 * Form for filtering categories on export to excel 378 * 379 * @since 1.0.0 380 * 396 381 */ 397 382 public function export_to_excel_form(){ … … 426 411 /** 427 412 * Export method for excel 413 * 414 * @since 1.0.0 415 * 428 416 */ 429 417 public function export_to_excel(){ … … 497 485 /** 498 486 * Method for cleaning data to excel 487 * 488 * @since 1.0.0 489 * 499 490 */ 500 491 public function clean_data_for_excel( &$str ) { -
subscribe-to-category/trunk/classes/class-subscribe.php
r1028927 r1032176 24 24 private $settings = array(); 25 25 private $post_type = 'stc'; 26 26 private $sleep_flag = 25; 27 28 /** 29 * Constructor 30 * 31 * @since 1.0.0 32 */ 27 33 function __construct(){ 28 34 $this->init(); … … 31 37 /** 32 38 * Single instance of this class. 39 * 40 * @since 1.0.0 33 41 */ 34 42 public static function get_instance() { … … 44 52 /** 45 53 * Init method 46 * @return [type] [description] 54 * 55 * @since 1.0.0 56 * 57 * @return [type] [description] 47 58 */ 48 59 private function init(){ 49 60 50 51 52 61 add_action( 'init', array( $this, 'register_post_type'), 99 ); 53 62 add_action( 'create_category', array( $this, 'update_subscriber_categories') ); … … 72 81 /** 73 82 * Adding a newly created category to subscribers who subscribes to all categories 83 * 84 * @since 1.0.0 85 * 74 86 * @param $category_id The id for newly created category 75 87 */ … … 104 116 /** 105 117 * Method for printing unsubscription text on custom page 118 * 119 * @since 1.0.0 106 120 */ 107 121 public function unsubscribe_html(){ … … 122 136 /** 123 137 * Collecting data through _GET 124 * 138 * 139 * @since 1.0.0 125 140 */ 126 141 public function collect_get_data(){ … … 150 165 * 151 166 * @TODO: add contact email if something went wrong 167 * 168 * @since 1.0.0 152 169 */ 153 170 private function unsubscribe_user(){ … … 183 200 /** 184 201 * Listen for every new post and update post meta if post type 'post' 202 * 203 * @since 1.0.0 204 * 185 205 * @param string $old_status 186 206 * @param string $new_status … … 203 223 /** 204 224 * Sending an email to a subscriber with a confirmation link to unsubscription 225 * 226 * @since 1.0.0 227 * 205 228 * @param int $stc_id post id for subscriber 206 229 * @return [type] [description] … … 245 268 /** 246 269 * Returns the content for email unsubscription 270 * 271 * @since 1.0.0 272 * 247 273 * @param array $stc 248 274 * @return string … … 261 287 /** 262 288 * Collect data from _POST for subscription 289 * 290 * @since 1.0.0 291 * 263 292 * @return string Notice to user 264 *265 293 */ 266 294 public function collect_post_data(){ … … 346 374 /** 347 375 * Check if subscriber already exists 376 * 377 * @since 1.0.0 378 * 348 379 * @return int post_id 349 380 */ … … 363 394 /** 364 395 * Update user with selected categories if user exists, else add user as new user. 396 * 397 * @since 1.0.0 398 * 365 399 * @param string $post_data currently not in use 366 400 */ … … 406 440 /** 407 441 * Save post for stc post_type from admin 442 * 443 * @since 1.0.0 408 444 */ 409 445 public function save_post_stc( $post_id ) { … … 482 518 /** 483 519 * Display error in wordpress format as notice if exists 520 * 521 * @since 1.0.0 484 522 */ 485 523 public function save_post_stc_error(){ … … 498 536 /** 499 537 * Render html to subscribe to categories 500 * @return [type] [description] 538 * 539 * @since 1.0.0 540 * 541 * @return [type] [description] 501 542 * 502 543 * @todo add some filter … … 516 557 /** 517 558 * Adding jQuery to footer 559 * 560 * @since 1.0.0 518 561 */ 519 562 public function add_script_to_footer(){ … … 559 602 /** 560 603 * Html for subscribe form 604 * 605 * @since 1.0.0 606 * 561 607 * @return [type] [description] 562 608 */ … … 647 693 /** 648 694 * On the scheduled action hook, run a function. 695 * 696 * @since 1.0.0 649 697 */ 650 698 public function stc_send_email() { … … 680 728 $this->send_notifier( $outbox ); 681 729 } 730 682 731 } 683 732 684 733 /** 685 734 * Send notifier to subscribers 735 * 736 * @since 1.0.0 737 * 686 738 * @param object $outbox 687 739 */ … … 739 791 740 792 // loop through subscribers and send notice 793 $i = 1; // loop counter 741 794 foreach ($emails as $email ) { 742 795 … … 754 807 wp_mail( $email['email'], $subject, $message, $headers ); 755 808 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 756 817 } 757 818 … … 767 828 * Render html to email. 768 829 * Setting limit to content as we still want the user to click and visit our site. 830 * 831 * @since 1.0.0 832 * 769 833 * @param object $email 770 834 */ … … 781 845 /** 782 846 * Cut a text string closest word on a given length. 847 * 848 * @since 1.0.0 849 * 783 850 * @param string $string 784 851 * @param int $max_length … … 806 873 /** 807 874 * Get all subscribers with subscribed categories 875 * 876 * @since 1.0.0 877 * 808 878 * @return object Subscribers 809 879 */ … … 837 907 /** 838 908 * Register custom post type for subscribers 909 * 910 * @since 1.0.0 839 911 */ 840 912 public function register_post_type(){ -
subscribe-to-category/trunk/readme.txt
r1028956 r1032176 4 4 Requires at least: 3.9 5 5 Tested up to: 4.0 6 Stable tag: 1. 0.06 Stable tag: 1.1.0 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 57 57 == Changelog == 58 58 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 59 63 = 1.0.0 = 60 64 * First release -
subscribe-to-category/trunk/subscribe-to-category.php
r1028928 r1032176 4 4 Plugin URI: http://dcweb.nu 5 5 Description: Lets your visitor subscribe to posts for one or several categories. 6 Version: 1. 0.06 Version: 1.1.0 7 7 Author: Daniel Söderström 8 8 Author URI: http://dcweb.nu/
Note: See TracChangeset
for help on using the changeset viewer.