@@ -57,10 +57,11 @@ public function __construct( string $api_url, array $args = array() ) {
57
57
$ this ->args = wp_parse_args (
58
58
$ args ,
59
59
array (
60
- 'file ' => '' ,
61
- 'item_id ' => false ,
62
- 'version ' => false ,
63
- 'api_url ' => $ api_url ,
60
+ 'file ' => '' ,
61
+ 'item_id ' => false ,
62
+ 'version ' => false ,
63
+ 'api_url ' => $ api_url ,
64
+ 'weekly_check ' => true ,
64
65
)
65
66
);
66
67
$ this ->args ['slug ' ] = $ this ->get_slug ();
@@ -122,6 +123,36 @@ public function ajax_get_license_overlay() {
122
123
wp_send_json_success ( ob_get_clean () );
123
124
}
124
125
126
+ /**
127
+ * Checks the license weekly.
128
+ *
129
+ * @since <next-version>
130
+ * @return void
131
+ */
132
+ public function weekly_license_check () {
133
+ if ( ! defined ( 'DOING_CRON ' ) || ! DOING_CRON ) {
134
+ return ;
135
+ }
136
+
137
+ if ( empty ( $ this ->license ->get_license_key () ) ) {
138
+ return ;
139
+ }
140
+
141
+ $ api_params = wp_parse_args (
142
+ array (
143
+ 'edd_action ' => 'check_license ' ,
144
+ ),
145
+ $ this ->get_default_api_request_args ()
146
+ );
147
+ $ api = new \EasyDigitalDownloads \Updater \Requests \API ( $ this ->args ['api_url ' ] );
148
+ $ license_data = $ api ->make_request ( $ api_params );
149
+ if ( empty ( $ license_data ->success ) ) {
150
+ return ;
151
+ }
152
+
153
+ $ this ->license ->save ( $ license_data );
154
+ }
155
+
125
156
/**
126
157
* Initializes the auto updater.
127
158
*
@@ -152,6 +183,12 @@ private function add_general_listeners() {
152
183
add_action ( 'wp_ajax_edd_sl_sdk_activate_ ' . $ slug , array ( $ this ->license , 'ajax_activate ' ) );
153
184
add_action ( 'wp_ajax_edd_sl_sdk_delete_ ' . $ slug , array ( $ this ->license , 'ajax_delete ' ) );
154
185
add_action ( 'wp_ajax_edd_sl_sdk_update_tracking_ ' . $ slug , array ( $ this ->license , 'ajax_update_tracking ' ) );
186
+ if ( ! empty ( $ this ->args ['weekly_check ' ] ) ) {
187
+ if ( ! wp_next_scheduled ( 'edd_sl_sdk_weekly_license_check_ ' . $ slug ) ) {
188
+ wp_schedule_event ( time (), 'weekly ' , 'edd_sl_sdk_weekly_license_check_ ' . $ slug );
189
+ }
190
+ add_action ( 'edd_sl_sdk_weekly_license_check_ ' . $ slug , array ( $ this , 'weekly_license_check ' ) );
191
+ }
155
192
}
156
193
157
194
/**
0 commit comments