PluginProbe
RabbitLoader / 2.18.2
RabbitLoader v2.18.2
4.0.2 4.0.1 4.0 3.2.0 3.1.1 3.1.0 3.0.5 3.0.3 3.0.4 2.17.1 2.17.2 2.17.3 2.17.4 2.17.5 2.17.6 2.17.7 2.18.0 2.18.1 2.18.2 2.18.3 2.18.4 2.18.5 2.18.6 2.18.7 2.18.8 All 129 releases
rabbit-loader / inc / admin.php

admin.php in RabbitLoader 2.18.2, at inc/admin.php

584 lines 24.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class RabbitLoader_21_Admin{
4
5 private static $purge_queue = null;
6 public static $rabbitloader_cache_warnings = false;
7 public static $admin_notice_shown = false;
8
9 const PURGE_POST_CHANGE = "PURGE_POST";
10 const PURGE_THEME_CHANGE = "PURGE_THEME";
11 const PURGE_PLUG_CHANGE = "PURGE_PLUGIN";
12 const PURGE_MANUAL_USER = "PURGE_USER";
13
14 public static function addActions(){
15 add_action('admin_notices', 'RabbitLoader_21_Admin::admin_notices');
16 add_action('network_admin_notices', 'RabbitLoader_21_Admin::admin_notices' );
17 //add_action('admin_init', 'RabbitLoader_21_Admin::init');
18 add_action('shutdown', 'RabbitLoader_21_Admin::shutdown');
19 add_action('admin_menu', 'RabbitLoader_21_Admin::leftMenuOption' );
20 add_action('enqueue_block_editor_assets', 'RabbitLoader_21_Admin::postSubmitButton');
21
22 add_action('admin_enqueue_scripts', function(){
23 wp_enqueue_script('rabbitloader-index', RABBITLOADER_PLUG_URL . 'admin/js/index.js', ['jquery'], RABBITLOADER_PLUG_VERSION);
24 wp_localize_script( 'rabbitloader-index', 'rabbitloader_local_vars', [
25 'admin_ajax' => admin_url( 'admin-ajax.php' ),
26 'hostname' => get_option('rabbitloader_field_domain')
27 ]);
28 });
29
30 //we need to listen for a few things to invalidate cache
31 #reading settings changed (permalink, post per page)
32 #post+page+comment+tag+category added, deleted, updated
33 #theme+plugin activated deactivated
34 add_action( 'save_post', function($post_ID, $post, $update){
35 RabbitLoader_21_Admin::onPostChange($post_ID, self::PURGE_POST_CHANGE);
36 }, 10, 3 );
37 add_action( 'wp_insert_post', function($post_ID, $post, $update){
38 RabbitLoader_21_Admin::onPostChange($post_ID, self::PURGE_POST_CHANGE);
39 }, 10, 3 );
40 add_action( 'draft_to_publish', function($post){
41 if(!empty($post)){
42 RabbitLoader_21_Admin::onPostChange($post->ID, self::PURGE_POST_CHANGE);
43 }
44 }, 10, 1 );
45 add_action( 'pending_to_publish', function($post){
46 if(!empty($post)){
47 RabbitLoader_21_Admin::onPostChange($post->ID, self::PURGE_POST_CHANGE);
48 }
49 }, 10, 1);
50 add_action( 'transition_post_status', function($new_status, $old_status, $post){
51 //No need to purge if the post was not public before and its not even now
52 if('publish' !== $old_status && 'publish' !== $new_status){
53 return;
54 }
55 RabbitLoader_21_Admin::onPostChange($post->ID, self::PURGE_POST_CHANGE);
56 }, 10, 3);
57 add_action( 'transition_comment_status', function($new_status, $old_status, $comment){
58 RabbitLoader_21_Admin::onPostChange($comment->comment_post_ID, self::PURGE_POST_CHANGE);
59 }, 10, 3);
60 add_action( 'comment_post', function($comment_ID, $comment_approved, $commentdata){
61 if($comment_approved==1){
62 $comment = get_comment( $comment_ID );
63 RabbitLoader_21_Admin::onPostChange($comment->comment_post_ID, self::PURGE_POST_CHANGE);
64 }
65 }, 10, 3);
66
67 add_action( 'switch_theme', function(){
68 RabbitLoader_21_Admin::onPostChange('all', self::PURGE_THEME_CHANGE);
69 }, 10, 0);
70 // add_action( 'upgrader_process_complete', function(){
71 // RabbitLoader_21_Admin::onPostChange('all', self::PURGE_PLUG_CHANGE);
72 // }, 10, 0);
73 // add_action( 'activated_plugin', function(){
74 // RabbitLoader_21_Admin::onPostChange('all', self::PURGE_PLUG_CHANGE);
75 // }, 10, 0);
76 // add_action( 'deactivated_plugin', function(){
77 // RabbitLoader_21_Admin::onPostChange('all', self::PURGE_PLUG_CHANGE);
78 // }, 10, 0);
79
80 add_action( 'woocommerce_updated_product_stock', function($product_id){
81 RabbitLoader_21_Admin::onPostChange($product_id, self::PURGE_POST_CHANGE);
82 }, 10, 1);
83 add_action( 'woocommerce_updated_product_price', function($product_id){
84 RabbitLoader_21_Admin::onPostChange($product_id, self::PURGE_POST_CHANGE);
85 }, 10, 1);
86 add_action( 'woocommerce_rest_insert_product', function($post, $request, $creating) {
87 RabbitLoader_21_Admin::onPostChange($post->ID, self::PURGE_POST_CHANGE);
88 }, 10, 3);
89 add_action( 'woocommerce_rest_insert_product_object', function($product, $request, $creating) {
90 RabbitLoader_21_Admin::onPostChange($product->id, self::PURGE_POST_CHANGE);
91 }, 10, 3);
92 add_action( 'woocommerce_product_object_updated_props', function($product, $updated) {
93 RabbitLoader_21_Admin::onPostChange($product->get_id(), self::PURGE_POST_CHANGE);
94 }, 0, 2);
95
96 add_action( 'wp_ajax_rabbitloader_ajax_purge', function(){
97 $response = [
98 'result'=>false
99 ];
100 if(!empty($_POST['post_id'])){
101 $post_id = RabbitLoader_21_Util_Core::get_param('post_id', true);
102 RabbitLoader_21_Admin::onPostChange($post_id, self::PURGE_MANUAL_USER);
103 $response = [
104 'result'=>true
105 ];
106 }else{
107 RabbitLoader_21_Admin::onPostChange('all', self::PURGE_MANUAL_USER);
108 $response = [
109 'result'=>true
110 ];
111 }
112 RabbitLoader_21_Core::sendJsonResponse($response);
113 });
114
115 add_action( 'wp_ajax_rabbitloader_mode_change', function(){
116 $response = [
117 'result'=>true
118 ];
119 $private_mode = !empty($_POST['private_mode']);
120 RabbitLoader_21_Core::getWpUserOption($user_options);
121 $user_options['private_mode_val'] = $private_mode;
122 $user_options['private_mode_ts'] = date('c');
123 RabbitLoader_21_Core::updateUserOption($user_options);
124 RabbitLoader_21_Core::sendJsonResponse($response);
125
126 });
127 add_action( 'wp_ajax_rabbitloader_ajax_cron', function(){self::deferred_exe();});
128 add_action( 'rl_site_connected', function(){self::rl_site_connected();});
129 add_action( 'plugins_loaded', 'RabbitLoader_AD_AD::on_plugins_loaded');
130 //listeners for taxonomy changes
131 }
132
133 public static function init(){
134 }
135
136 public static function leftMenuOption(){
137 self::get_warnings($notification_count, false);
138 add_menu_page(
139 'RabbitLoader',
140 $notification_count ? sprintf('RabbitLoader <span class="awaiting-mod">%d</span>', $notification_count) : 'RabbitLoader',
141 'manage_options',
142 'rabbitloader',
143 'RabbitLoader_21_Tab_Init::echoPluginPage',
144 dirname(plugin_dir_url(__FILE__)) . '/images/icon_16.png',
145 //'',
146 20
147 );
148
149 $page = RabbitLoader_21_Util_Core::get_param('page');
150
151 if($page=='rabbitloader'){
152 add_action( 'admin_head', 'admin_styles', 10, 1);
153 function admin_styles($a) {
154 echo '<link rel="stylesheet" href="'.RABBITLOADER_PLUG_URL . 'admin/css/bootstrap.v5.1.3.min.css'.'" type="text/css" media="all" />
155 <link rel="stylesheet" href="'.RABBITLOADER_PLUG_URL . 'admin/css/style.css'.'" type="text/css" media="all" />';
156 }
157 }
158 }
159
160
161 protected static function isPluginActivated(){
162
163 return !empty(RabbitLoader_21_Core::getWpOptVal('api_token'));
164 }
165
166 private static function load_purged_urls(){
167 RabbitLoader_21_Core::get_log_file('purge_urls_fl', $purge_urls_fl);
168 if(file_exists($purge_urls_fl)){
169 $purge_queue = json_decode(file_get_contents($purge_urls_fl), true);
170 }
171 if(empty($purge_queue)){
172 $purge_queue = [];
173 }
174 return $purge_queue;
175 }
176
177 public static function onPostChange($post_id, $purge_source){
178 if(self::$purge_queue===null){
179 self::$purge_queue = self::load_purged_urls();
180 }
181 if($post_id=='all'){
182 self::$purge_queue['all'] = true;
183 }else{
184 //invalidate cache for individual post
185 try{
186 if(wp_is_post_autosave($post_id) || wp_is_post_revision($post_id)){
187 //no need to purge cache for these posts as they are never displayed on website
188 return;
189 }
190 }catch(\Throwable $e){
191 RabbitLoader_21_Core::on_exception($e);
192 }
193
194 if(empty(self::$purge_queue['post_ids'])){
195 self::$purge_queue['post_ids'] = [];
196 }
197 self::$purge_queue['post_ids'][$post_id] = true;
198
199 $post_ancestors = get_post_ancestors($post_id);
200 foreach ($post_ancestors as $parent_id) {
201 self::$purge_queue['post_ids'][$parent_id] = true;
202 }
203 }
204 self::$purge_queue['purge_source'] = $purge_source;
205 }
206
207 private static function execute_purge()
208 {
209 $purge_queue = self::load_purged_urls();
210 $purge_urls_json = '{}';
211 RabbitLoader_21_Core::get_log_file('purge_urls_fl', $purge_urls_fl);
212 RabbitLoader_21_Util_Core::fpc($purge_urls_fl, $purge_urls_json, WP_DEBUG);
213
214 RabbitLoader_21_Core::getWpUserOption($user_options);
215
216 $purge_source = empty($purge_queue['purge_source'])?'':$purge_queue['purge_source'];
217 $clean_cache = strcmp($purge_source, self::PURGE_MANUAL_USER)===0 || !empty($user_options['purge_on_change']);
218
219 if(!empty($purge_queue['all'])){
220 if($clean_cache){
221 RabbitLoader_21_Core::purge_all($purge_count, $purge_source, $tp_purge_count);
222 }
223 try{
224 RabbitLoader_21_Core::push_recent_posts($queued_offset, $queued_count, $published_count);
225 }catch(\Throwable $e){
226 RabbitLoader_21_Core::on_exception($e);
227 }
228 }else if(!empty($purge_queue['post_ids'])){
229 $urls_to_purge = [];
230 RabbitLoader_21_Core::get_common_cache_urls($urls_to_purge);
231 foreach($purge_queue['post_ids'] as $post_ID=>$val){
232 $post_obj = get_post(intval($post_ID));
233 if(!$post_obj){
234 continue;
235 }
236 $post_canonical_url = wp_get_canonical_url($post_ID);
237 $urls_to_purge[] = $post_canonical_url;
238 RabbitLoader_21_Admin::get_all_taxonomies($post_ID, $post_obj->post_type, $tax_ids, $urls_to_purge);
239 if($clean_cache){
240 RabbitLoader_21_TP::purge_post_id($post_ID, $tp_purge_count);
241 }
242 }
243 $cache_missed_log = '';
244 $urls_to_purge = array_filter($urls_to_purge);
245 foreach($urls_to_purge as $url){
246 if($clean_cache){
247 RabbitLoader_21_Core::purge_url_cache_local($url, $local_purge_count, $tp_purge_count);
248 RabbitLoader_21_Core::purge_url_cache_local(rawurldecode($url), $local_purge_count, $tp_purge_count);
249 }
250 $cache_missed_log .= "\n".$url;
251 }
252 if(!empty($cache_missed_log)){
253 RabbitLoader_21_Util_Core::fac('cache_missed', $cache_missed_log, WP_DEBUG);
254 }
255
256 RabbitLoader_21_Core::callPostApi('purge/request', ['purge_source'=>$purge_source, 'urls'=>array_slice($urls_to_purge,0, 100)], $apiError, $apiMessage);
257 do_action('rl_purge_request_complete', $urls_to_purge, $apiError);
258 }
259 }
260
261 public static function shutdown()
262 {
263 if(!empty(self::$purge_queue)){
264 $purge_urls_json = json_encode(self::$purge_queue);
265 RabbitLoader_21_Core::get_log_file('purge_urls_fl', $purge_urls_fl);
266 RabbitLoader_21_Util_Core::fpc($purge_urls_fl, $purge_urls_json, WP_DEBUG);
267 }
268 }
269
270 private static function get_all_taxonomies($post_ID, $post_type, &$tax_ids, &$tax_urls) {
271 $tax_ids = array();
272 $taxonomies = get_object_taxonomies($post_type);
273 foreach ($taxonomies as $taxonomy) {
274 $taxonomy_data = get_taxonomy($taxonomy);
275 if ($taxonomy_data instanceof WP_Taxonomy && $taxonomy_data->public===false) {
276 continue;
277 }
278 $terms = get_the_terms( $post_ID, $taxonomy );
279
280 if (empty($terms) || is_wp_error($terms)) {
281 continue;
282 }else{
283 foreach ($terms as $term) {
284 if(!empty($term)){
285 $tax_ids[] = $term->term_taxonomy_id;
286 $tax_url = get_term_link($term);
287 if(!is_wp_error($tax_url) && !empty($tax_url)){
288 $tax_urls[] = $tax_url;
289 }
290 }
291 }
292 }
293 }
294
295 $other_urls_to_merge = [];
296 try{
297 $other_urls_to_merge[] = get_author_posts_url(get_post_field('post_author', $post_ID));
298 $other_urls_to_merge[] = get_author_feed_link(get_post_field('post_author', $post_ID));
299 $other_urls_to_merge[] = get_post_type_archive_link($post_type);
300 $other_urls_to_merge[] = get_post_type_archive_feed_link($post_type);
301 $other_urls_to_merge[] = get_permalink($post_ID);
302 $other_urls_to_merge[] = get_post_comments_feed_link($post_ID);
303 }catch(Throwable $e){
304 RabbitLoader_21_Core::on_exception($e);
305 }
306 if(!empty($other_urls_to_merge)){
307 foreach($other_urls_to_merge as $other_url){
308 if(!empty($other_url) && !is_wp_error($other_url)){
309 $tax_urls[] = $other_url;
310 }
311 }
312 }
313 }
314
315 public static function admin_notices(){
316
317 try{
318 $page = RabbitLoader_21_Util_Core::get_param('page');
319
320 if(self::$admin_notice_shown || ($page=='rabbitloader')){
321 return;
322 }
323
324 self::$admin_notice_shown = true;
325
326 $plug_url = admin_url("admin.php?page=rabbitloader");
327
328 if(!self::isPluginActivated()){
329 echo '
330 <div class="notice notice-error is-dismissible"><p>';
331 printf(RabbitLoader_21_Util_WP::__('RabbitLoader is disconnected. Your pages are not optimized. <a href="%s">Click here to connect</a>'), $plug_url);
332 echo '</p></div>';
333 }else{
334 self::get_warnings($notification_count, false);
335
336 if($notification_count>0){
337 echo '<div class="notice notice-error is-dismissible"><p>';
338 printf(RabbitLoader_21_Util_WP::_n( 'RabbitLoader has %d warning which is affecting your website\'s optimizations. <a href="%s">check details</a>', 'RabbitLoader has %d warnings which may affect your website\'s optimizations. <a href="%s">check details</a>', $notification_count), $notification_count, $plug_url);
339 echo '</p></div>';
340 }
341 }
342 }catch(Throwable $e){
343 RabbitLoader_21_Core::on_exception($e);
344 }
345 }
346
347 protected static function get_warnings(&$count, $print){
348
349 if(self::$rabbitloader_cache_warnings === false){
350
351 self::$rabbitloader_cache_warnings = [];
352
353 $otherConflictPluginMessages = RabbitLoader_21_Conflicts::getMessages();
354 foreach ($otherConflictPluginMessages as $plugMessage) {
355 self::$rabbitloader_cache_warnings[] = $plugMessage;
356 }
357
358 $adv_cache_msg = RabbitLoader_21_Util_WP::__("The file /wp-content/advanced-cache.php is not writable. Please make sure that the PHP script has write access to the /wp-content/ directory and refresh this page to make RabbitLoader work efficiently.");
359
360 if(!defined('RABBITLOADER_AC_ACTIVE') || (RABBITLOADER_PLUG_VERSION!=RABBITLOADER_AC_PLUG_VERSION)){
361 $aac_code = self::activate_advanced_cache();
362 if($aac_code==4){
363 self::$rabbitloader_cache_warnings[] = $adv_cache_msg;
364 }
365 }
366
367 $cache_warning = RabbitLoader_21_Util_WP::__("The file /wp-config.php is not writable. Please make sure the file is writable or set WP_CACHE value to true to make RabbitLoader work efficiently.");
368 if ((!defined("WP_CACHE") || !WP_CACHE)) {
369 if (!self::update_wp_config_const('WP_CACHE', 'true')) {
370 self::$rabbitloader_cache_warnings[] = $cache_warning;
371 $cache_warning = '';
372 }
373 }
374
375 if (!self::create_cache_folder()) {
376 self::$rabbitloader_cache_warnings[] = RabbitLoader_21_Util_WP::__("The folder /wp-content/ is not writable. Please make sure that the PHP script has write access to the /wp-content/ directory and refresh this page. This is required to store the cached content.");
377 }
378
379 RabbitLoader_21_Core::getWpOption($rl_wp_options);
380 if(!empty($rl_wp_options['rl_hb_messages'])){
381 foreach($rl_wp_options['rl_hb_messages'] as $message){
382 if(!empty($message['fd'])){
383 self::$rabbitloader_cache_warnings[] = RabbitLoader_21_Util_WP::__($message['fd']);
384 }
385 }
386 }
387 if(!empty($rl_wp_options['rl_latest_plugin_v'])){
388 if(version_compare(RABBITLOADER_PLUG_VERSION, $rl_wp_options['rl_latest_plugin_v'])==-1){
389 self::$rabbitloader_cache_warnings[] = RabbitLoader_21_Util_WP::__("You are using an outdated version of RabbitLoader plugin. Please update it for a better experience.");
390 }
391 }
392 }
393
394 $count = count(self::$rabbitloader_cache_warnings);
395
396 if($print){
397 foreach(self::$rabbitloader_cache_warnings as $message){
398 // echo '<div class="alert alert-danger" role="alert">';
399 // _e($message, RABBITLOADER_TEXT_DOMAIN);
400 // echo '</div>';
401 echo '<div class="notice notice-error"><p><b>';
402 RabbitLoader_21_Util_WP::_e('Warning'); echo ': </b>';
403 _e($message, RABBITLOADER_TEXT_DOMAIN);
404 echo '</div>';
405 }
406 }
407 }
408
409 private static function create_cache_folder(){
410
411 $dirs = [
412 RABBITLOADER_CACHE_DIR,
413 RabbitLoader_21_Util_WP::get_cache_dir('short'),
414 RabbitLoader_21_Util_WP::get_cache_dir('long')
415 ];
416
417 $dirs_exists = 0;
418
419 try{
420 foreach($dirs as $dir){
421 if (!file_exists($dir)){
422 if(@mkdir($dir, 0755, true)){
423 ++$dirs_exists;
424 }
425 }else{
426 ++$dirs_exists;
427 }
428 }
429 if(count($dirs)!=$dirs_exists){
430 return false;
431 }
432
433 //add htaccess file for security
434 $htaccess_loc = RABBITLOADER_CACHE_DIR.DIRECTORY_SEPARATOR.".htaccess";
435 if (!file_exists($htaccess_loc)) {
436 $htaccess_content = "deny from all";
437 RabbitLoader_21_Util_Core::fpc($htaccess_loc, $htaccess_content, WP_DEBUG);
438 }
439
440 return file_exists($htaccess_loc);
441
442 }catch(Throwable $e){
443 RabbitLoader_21_Core::on_exception($e);
444 }
445 }
446
447 public static function activate_advanced_cache(){
448
449 try{
450 if (!empty(RabbitLoader_21_Conflicts::getMessages())){
451 return 1;
452 }
453
454 if(!self::create_cache_folder()){
455 return 2;
456 }
457
458 $adv_cache_sample = RABBITLOADER_PLUG_DIR . "advanced-cache.php";
459 $file_updated = false;
460 if (file_exists($adv_cache_sample)) {
461 $adv_cache_contents = file_get_contents($adv_cache_sample);
462 $adv_cache_contents = str_replace("%%RABBITLOADER_AC_ABSPATH%%", ABSPATH, $adv_cache_contents);
463 $adv_cache_contents = str_replace("%%RABBITLOADER_AC_PLUG_DIR%%", RABBITLOADER_PLUG_DIR, $adv_cache_contents);
464 $adv_cache_contents = str_replace("%%RABBITLOADER_AC_LOGGED_IN_COOKIE%%", LOGGED_IN_COOKIE, $adv_cache_contents);
465 $adv_cache_contents = str_replace("%%RABBITLOADER_AC_CACHE_DIR%%", RABBITLOADER_CACHE_DIR, $adv_cache_contents);
466 $adv_cache_contents = str_replace("%%RABBITLOADER_AC_PLUG_VERSION%%", RABBITLOADER_PLUG_VERSION, $adv_cache_contents);
467 $adv_cache_contents = str_replace("%%RABBITLOADER_AC_PLUG_ENV%%", RABBITLOADER_PLUG_ENV, $adv_cache_contents);
468
469 $advanced_cache_file = WP_CONTENT_DIR . DIRECTORY_SEPARATOR.'advanced-cache.php';
470 $file_updated = RabbitLoader_21_Util_Core::fpc($advanced_cache_file, $adv_cache_contents, WP_DEBUG);
471 }
472
473 if($file_updated){
474 self::update_wp_config_const('WP_CACHE', 'true');
475 return 3;
476 }else{
477 return 4;
478 }
479 }catch(Throwable $e){
480 RabbitLoader_21_Core::on_exception($e);
481 }
482 }
483
484 private static function update_wp_config_const($const_name, $const_val){
485 $wp_config_path = RabbitLoader_21_Util_WP::get_wp_config();
486 //check if config file is writable
487 if ( empty($wp_config_path) || !is_writable($wp_config_path)) {
488 //echo 'rl_not_writable__';
489 return;
490 }
491
492 $lines = file( $wp_config_path );
493 $last_line = count($lines) - 1;
494
495 $new_file = array();
496 $const_added = false;
497 foreach ( $lines as $current_line=>$line_content ) {
498 //check if constant is already defined
499 if ( preg_match( "/define\(\s*'{$const_name}'/i", $line_content ) ) {
500 $const_added = true;
501 $new_file[] = "define( '{$const_name}', {$const_val} ); //RabbitLoader\n";
502 continue; //dont't break here, its a complete file rewrite
503 }
504
505 $thatsAllLine = (preg_match( "/\/\* That's all, stop editing!.*/i", $line_content )); //constants should be before this line.
506 $isLast = ($thatsAllLine && !defined($const_name)) || ($last_line==$current_line);
507
508 // If we reach the end and no define - add it.
509 if (empty($const_added) && $isLast) {
510 $new_file[] = "define( '{$const_name}', {$const_val} ); //RabbitLoader\n";
511 }
512
513 $new_file[] = $line_content;
514 }
515 $file_contents = implode("", $new_file);
516 return RabbitLoader_21_Util_Core::fpc($wp_config_path, $file_contents, WP_DEBUG);
517 }
518
519 public static function plugin_deactivate(){
520 try{
521 self::update_wp_config_const('WP_CACHE', 'false');
522 $advanced_cache_file = WP_CONTENT_DIR . DIRECTORY_SEPARATOR.'advanced-cache.php';
523 if (file_exists($advanced_cache_file)) { //during uninstall RABBITLOADER_AC_ACTIVE will not be there
524 $adv_cache_contents = "";
525 $file_updated = RabbitLoader_21_Util_Core::fpc($advanced_cache_file, $adv_cache_contents, WP_DEBUG);
526 }
527 }catch(Throwable $e){
528 RabbitLoader_21_Core::on_exception($e);
529 }
530 }
531
532 public static function plugin_uninstall(){
533 self::plugin_deactivate();
534
535 $post_data['uninstall'] = 1;
536 $http = RabbitLoader_21_Core::callPOSTAPI('domain/heartbeat', $post_data, $apiError, $apiMessage);
537
538 RabbitLoader_21_Core::cleanAllCachedFiles('long');
539
540 $ourOptions = array('rabbitloader_field_apikey', 'rabbitloader_field_apisecret', 'rabbitloader_field_domain','rl_optimizer_engine_version', 'rabbit_loader_wp_options', 'rabbit_loader_user_options', 'rabbitloader_cdn_prefix');
541
542 foreach ($ourOptions as $optionName) {
543 delete_option($optionName);
544 }
545 }
546
547 public static function postSubmitButton(){
548 wp_enqueue_script('rabbitloader-editor', RABBITLOADER_PLUG_URL . 'admin/js/editor.js', ['wp-edit-post', 'wp-plugins', 'wp-i18n', 'wp-element'], RABBITLOADER_PLUG_VERSION);
549 }
550
551 private static function rl_site_connected(){
552 try{
553 RabbitLoader_21_Core::push_recent_posts($queued_offset, $queued_count, $published_count);
554 RabbitLoader_21_TP::purge_all($tp_purge_count);
555 }catch(\Throwable $e){
556 RabbitLoader_21_Core::on_exception($e);
557 }
558 }
559
560 public static function settings_link($links){
561 $url_settings = esc_url( add_query_arg(
562 'page',
563 'rabbitloader',
564 get_admin_url() . 'admin.php'
565 ));
566 $link = "<a href='$url_settings'>" . __( 'Settings' ) . '</a>';
567 array_push($links, $link);
568 $url_kb = esc_url('https://rabbitloader.com/kb/');
569 $link = "<a target='_blank' href='$url_kb'>" . __( 'Knowledge Base' ) . '</a>';
570 array_push($links, $link);
571 return $links;
572 }
573
574 private static function deferred_exe(){
575 try{
576 self::execute_purge();
577 RabbitLoader_21_Core::clean_orphaned_cached_files(RabbitLoader_21_Util_Core::isDev()?5:50);
578 }catch(\Throwable $e){
579 RabbitLoader_21_Core::on_exception($e);
580 }
581 }
582 }
583
584 ?>