PluginProbe
Depicter — Popup & Slider Builder / trunk
Depicter — Popup & Slider Builder vtrunk
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / src / WordPress / WPCronServiceProvider.php

WPCronServiceProvider.php in Depicter — Popup & Slider Builder trunk, at app/src/WordPress/WPCronServiceProvider.php

113 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Depicter\WordPress;
3
4 use WPEmerge\ServiceProviders\ServiceProviderInterface;
5
6 class WPCronServiceProvider implements ServiceProviderInterface
7 {
8
9 /**
10 * Register all dependencies in the IoC container.
11 *
12 * @param Container $container
13 *
14 * @return void
15 */
16 public function register($container) {}
17
18 /**
19 * Bootstrap any services if needed.
20 *
21 * @param Container $container
22 *
23 * @return void
24 */
25 public function bootstrap($container)
26 {
27
28 register_deactivation_hook(DEPICTER_PLUGIN_FILE, [ $this, 'deactivate_cron_jobs'] );
29
30 add_action( 'init', [ $this, 'set_cron_jobs' ] );
31 add_action( 'depicter_check_authorize', [ $this, 'check_user_authorize' ] );
32 add_action( 'depicter_validate_activation', [ $this, 'validateActivation' ], 10 );
33 add_action( 'depicter_collect_usage_data', [ $this, 'collectData' ], 10, 1 );
34
35 add_action('wp_login', [$this, 'on_admin_login'], 10, 2);
36 }
37
38 public function on_admin_login($user_login, $user){
39 if (in_array('administrator', $user->roles)) {
40
41 $this->validateActivation();
42 $this->reschedule_hook('depicter_validate_activation');
43 }
44 }
45
46 /**
47 * Set cron jobs
48 *
49 * @return void
50 */
51 public function set_cron_jobs() {
52 if ( ! wp_next_scheduled( 'depicter_check_authorize' ) ) {
53 wp_schedule_event( time(), 'twicedaily', 'depicter_check_authorize' );
54 }
55
56 if ( ! wp_next_scheduled( 'depicter_validate_activation' ) ) {
57 wp_schedule_event( time(), 'twicedaily', 'depicter_validate_activation' );
58 }
59
60 if ( ! wp_next_scheduled( 'depicter_collect_usage_data' ) ) {
61 wp_schedule_event( time(), 'daily', 'depicter_collect_usage_data' );
62 }
63 }
64
65 /**
66 * check if user has purchased a license or not
67 *
68 * @return void
69 */
70 public function check_user_authorize() {
71 \Depicter::client()->authorize();
72 }
73
74 /**
75 * Validate plugin activation
76 *
77 * @return void
78 */
79 public function validateActivation() {
80 \Depicter::client()->validateActivation();
81 }
82
83 /**
84 * Remove cron jobs on plugin deactivation
85 *
86 * @return void
87 */
88 public function deactivate_cron_jobs() {
89 $timestamp = wp_next_scheduled( 'depicter_check_authorize' );
90 wp_unschedule_event( $timestamp, 'depicter_check_authorize' );
91
92 $timestamp = wp_next_scheduled( 'depicter_validate_activation' );
93 wp_unschedule_event( $timestamp, 'depicter_validate_activation' );
94
95 $timestamp = wp_next_scheduled( 'depicter_collect_usage_data' );
96 wp_unschedule_event( $timestamp, 'depicter_collect_usage_data' );
97 }
98
99 /**
100 * Collect usage date if user accepts collecting data consent
101 * @return void
102 */
103 public function collectData() {
104 \Depicter::usageService()->collect();
105 \Depicter::usageService()->send();
106 }
107
108 private function reschedule_hook($hook, $recurrence = 'twicedaily') {
109 wp_clear_scheduled_hook($hook);
110 wp_schedule_event(time(), $recurrence, $hook);
111 }
112 }
113