PluginProbe ʕ •ᴥ•ʔ
Rich Showcase for Google Reviews / 3.1
Rich Showcase for Google Reviews v3.1
6.9.10 6.9.9 6.9.8 6.9.7 6.9.6 trunk 1.4 1.42 1.43 1.44 1.45 1.46 1.47 1.48 1.49 1.5 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 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.7 1.6.8 1.6.9 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3 2.4 2.4.1 2.4.2 2.5 2.5.1 2.6 2.6.1 2.6.2 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.6.1 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.8.1 4.8.2 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.7.1 5.8 5.9 5.9.1 5.9.2 5.9.3 5.9.7 6.0 6.1 6.2 6.3 6.4 6.4.1 6.5 6.6 6.6.1 6.6.2 6.7 6.8 6.8.1 6.8.2 6.9 6.9.1 6.9.2 6.9.3 6.9.4 6.9.4.1 6.9.4.2 6.9.4.3 6.9.4.4 6.9.5
widget-google-reviews / includes / class-reviews-cron.php
widget-google-reviews / includes Last commit date
admin 2 years ago core 2 years ago class-activator.php 3 years ago class-assets.php 2 years ago class-builder-page.php 3 years ago class-deactivator.php 3 years ago class-debug-info.php 2 years ago class-feed-ajax.php 2 years ago class-feed-block.php 2 years ago class-feed-deserializer.php 2 years ago class-feed-old.php 4 years ago class-feed-page.php 3 years ago class-feed-serializer.php 3 years ago class-feed-shortcode.php 3 years ago class-feed-widget.php 4 years ago class-plugin-overview-ajax.php 3 years ago class-plugin-overview.php 3 years ago class-plugin-settings.php 2 years ago class-plugin-support.php 3 years ago class-plugin.php 2 years ago class-post-types.php 3 years ago class-reviews-cron.php 2 years ago class-settings-save.php 3 years ago class-view.php 2 years ago index.php 4 years ago page-setting-fig.php 3 years ago page-setting-support.php 4 years ago
class-reviews-cron.php
109 lines
1 <?php
2
3 namespace WP_Rplg_Google_Reviews\Includes;
4
5 use WP_Rplg_Google_Reviews\Includes\Core\Connect_Google;
6
7 class Reviews_Cron {
8
9 private $connect_google;
10 private $feed_deserializer;
11
12 public function __construct(Connect_Google $connect_google, Feed_Deserializer $feed_deserializer) {
13 $this->connect_google = $connect_google;
14 $this->feed_deserializer = $feed_deserializer;
15 }
16
17 public function register() {
18 add_action('grw_revupd_schedule', array($this, 'update_schedule'));
19
20 $revupd_cron = get_option('grw_revupd_cron');
21 $next_cron_run = wp_next_scheduled('grw_revupd_schedule');
22
23 if ($revupd_cron !== '0' && !$next_cron_run) {
24 $start_at = rand(0, 60 * 60 * 12);
25 wp_schedule_event($start_at, 'daily', 'grw_revupd_schedule');
26 } elseif ($next_cron_run) {
27 update_option('grw_revupd_cron_timeout', $next_cron_run - time());
28 }
29 }
30
31 public function update_schedule() {
32
33 $start_time = floor(microtime(true) * 1000);
34 $end_time = 0;
35 $feed_updated_ids = array();
36
37 $feed_conn_cache = array();
38
39 $feed_ids = get_option('grw_feed_ids');
40 $ids = explode(",", $feed_ids);
41 $ids_count = count($ids);
42
43 if ($ids_count > 0) {
44
45 // Trying to walk by all reviews feed to update these
46 for ($i = 0; $i < $ids_count; $i++) {
47
48 // Get next reviews feed ID
49 $id = array_shift($ids);
50
51 // Get next reviews feed
52 $feed = $this->feed_deserializer->get_feed($id);
53 if ($feed != false && strlen($feed->post_content) > 0) {
54
55 // Parse json content to obtain reviews connectors
56 $json = json_decode($feed->post_content);
57 if ($json->connections && count($json->connections) > 0) {
58
59 // Loop by all connectors without repeatable
60 foreach ($json->connections as $conn) {
61
62 // Create pair 'place_id:lang' to update it
63 $arg_local_img = isset($conn->local_img) ? $conn->local_img : 'false';
64
65 $args = array($conn->id, $conn->lang, $arg_local_img);
66 $args_key = implode(":", $args);
67
68 // If not met, update
69 if (!in_array($args_key, $feed_conn_cache)) {
70 $this->connect_google->grw_refresh_reviews($args);
71 array_push($feed_conn_cache, $args_key);
72 }
73 }
74
75 // Put reviews feed ID to log
76 array_push($feed_updated_ids, $id);
77
78 // Put reviews feed ID to the end of feed_ids option
79 array_push($ids, $id);
80 update_option('grw_feed_ids', implode(",", $ids));
81
82 // Clear feed cache
83 delete_transient('grw_feed_' . GRW_VERSION . '_' . $id . '_reviews', false);
84
85 // Check execution time
86 $end_time = floor(microtime(true) * 1000) - $start_time;
87 if ($end_time > 500) {
88 break;
89 }
90
91 }
92 }
93 }
94
95 }
96
97 // Log information
98 $now = floor(microtime(true) * 1000);
99 update_option('grw_revupd_cron_log', 'Executed at ' . $now . ' in ' . $end_time . 'ms for feeds: ' . implode(", ", $feed_updated_ids));
100 }
101
102 public function deactivate() {
103 $next_scheduled = wp_next_scheduled('grw_revupd_schedule');
104 if ($next_scheduled) {
105 wp_unschedule_event($next_scheduled, 'grw_revupd_schedule');
106 update_option('grw_revupd_cron_timeout', '');
107 }
108 }
109 }