PluginProbe ʕ •ᴥ•ʔ
Post Views Counter / 1.1.1
Post Views Counter v1.1.1
1.7.13 1.7.12 1.7.11 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.2 1.3.2.1 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.7.10 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9
post-views-counter / includes / cron.php
post-views-counter / includes Last commit date
columns.php 10 years ago counter.php 10 years ago cron.php 10 years ago frontend.php 10 years ago functions.php 10 years ago query.php 10 years ago settings.php 10 years ago update.php 10 years ago widgets.php 10 years ago
cron.php
102 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) )
3 exit;
4
5 new Post_Views_Counter_Cron();
6
7 class Post_Views_Counter_Cron {
8
9 public function __construct() {
10 // set instance
11 Post_Views_Counter()->add_instance( 'cron', $this );
12
13 // actions
14 add_action( 'init', array( &$this, 'check_cron' ) );
15 add_action( 'pvc_reset_counts', array( &$this, 'reset_counts' ) );
16 add_action( 'pvc_flush_cached_counts', array( &$this, 'flush_cached_counts' ) );
17
18 // filters
19 add_filter( 'cron_schedules', array( &$this, 'cron_time_intervals' ) );
20 }
21
22 /**
23 * Reset daily counts.
24 *
25 * @global object $wpdb
26 */
27 public function reset_counts() {
28 global $wpdb;
29
30 $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'post_views WHERE type = 0' );
31 }
32
33 /**
34 * Call Post_Views_Counter_Counter::flush_cache_to_db().
35 * This is (un)scheduled on plugin activation/deactivation.
36 */
37 public function flush_cached_counts() {
38 $counter = Post_Views_Counter()->get_instance( 'counter' );
39
40 if ( $counter && $counter->using_object_cache() ) {
41 $counter->flush_cache_to_db();
42 }
43 }
44
45 /**
46 * Add new cron interval from settings.
47 *
48 * @param array $schedules
49 * @return array
50 */
51 public function cron_time_intervals( $schedules ) {
52 $schedules['post_views_counter_interval'] = array(
53 'interval' => Post_Views_Counter()->get_instance( 'counter' )->get_timestamp( Post_Views_Counter()->get_attribute( 'options', 'general', 'reset_counts', 'type' ), Post_Views_Counter()->get_attribute( 'options', 'general', 'reset_counts', 'number' ), false ),
54 'display' => __( 'Post Views Counter reset daily counts interval', 'post-views-counter' )
55 );
56
57 $schedules['post_views_counter_flush_interval'] = array(
58 'interval' => Post_Views_Counter()->get_instance( 'counter' )->get_timestamp( Post_Views_Counter()->get_attribute( 'options', 'general', 'flush_interval', 'type' ), Post_Views_Counter()->get_attribute( 'options', 'general', 'flush_interval', 'number' ), false ),
59 'display' => __( 'Post Views Counter cache flush interval', 'post-views-counter' )
60 );
61
62 return $schedules;
63 }
64
65 /**
66 * Check whether WP Cron needs to add new task.
67 */
68 public function check_cron() {
69 if ( ! is_admin() )
70 return;
71
72 // set wp cron task
73 if ( Post_Views_Counter()->get_attribute( 'options', 'general', 'cron_run' ) ) {
74
75 // not set or need to be updated?
76 if ( ! wp_next_scheduled( 'pvc_reset_counts' ) || Post_Views_Counter()->get_attribute( 'options', 'general', 'cron_update' ) ) {
77
78 // task is added but need to be updated
79 if ( Post_Views_Counter()->get_attribute( 'options', 'general', 'cron_update' ) ) {
80 // remove old schedule
81 wp_clear_scheduled_hook( 'pvc_reset_counts' );
82
83 // set update to false
84 $general = Post_Views_Counter()->get_attribute( 'options', 'general' );
85 $general['cron_update'] = false;
86
87 // update settings
88 update_option( 'post_views_counter_settings_general', $general );
89 }
90
91 // set schedule
92 wp_schedule_event( Post_Views_Counter()->get_instance( 'counter' )->get_timestamp( Post_Views_Counter()->get_attribute( 'options', 'general', 'reset_counts', 'type' ), Post_Views_Counter()->get_attribute( 'options', 'general', 'reset_counts', 'number' ) ), 'post_views_counter_interval', 'pvc_reset_counts' );
93 }
94 } else {
95 // remove schedule
96 wp_clear_scheduled_hook( 'pvc_reset_counts' );
97 remove_action( 'pvc_reset_counts', array( &$this, 'reset_counts' ) );
98 }
99 }
100
101 }
102