Plugin Directory

Changeset 2048532


Ignore:
Timestamp:
03/11/2019 06:32:51 PM (7 years ago)
Author:
grfstudio
Message:

Added cleanup after uninstalling

Location:
wp-admin-cache/trunk
Files:
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • wp-admin-cache/trunk/index.php

    r2048076 r2048532  
    55  Plugin URI: https://www.wpadmincache.com
    66  Description: The first cache plugin for WordPress admin area
    7   Version: 0.1.2
     7  Version: 0.1.3
    88  Author: Grf Studio
    99  Author URI: https://www.grfstudio.com
  • wp-admin-cache/trunk/readme.txt

    r2048074 r2048532  
    22Contributors: grfstudio
    33Tags: admin cache, admin performance, admin speed, slow admin
    4 Stable tag: 0.1.2
     4Stable tag: 0.1.3
    55Requires PHP: 5.6
    66Requires at least: 4.6
     
    4141== Changelog ==
    4242
     43= 0.1.3 =
     44
     45* Added cleanup after uninstalling
     46
    4347= 0.1.2 =
    4448
  • wp-admin-cache/trunk/settings.php

    r2046135 r2048532  
    3030    <h2><?php echo __('Cached pages','wp-admin-cache') ?></h2>
    3131    <p><?php echo __('Select which pages should be cached; since prefetching requires a proper client connection speed, select the pages that will be used most often.','wp-admin-cache');?></p>
    32     <ul>
     32        <p><?php echo __('The plugin is currently under development, any feedback that helps us to improve it is much appreciated.')?></p>
     33        <ul>
    3334        <li><h3>
    3435            <label><input type="checkbox" name="wp_admin_cache_enabled" value="1" <?php if($enabled) echo 'checked' ?>> <?php echo __('Cache enabled','wp-admin-cache') ?></label> 
  • wp-admin-cache/trunk/uninstall.php

    r2048076 r2048532  
    11<?php
    22
    3 /*
    4   Plugin Name: WP Admin Cache
    5   Plugin URI: https://www.wpadmincache.com
    6   Description: The first cache plugin for WordPress admin area
    7   Version: 0.1.2
    8   Author: Grf Studio
    9   Author URI: https://www.grfstudio.com
    10   Text Domain: wp-admin-cache
    11   Domain Path: /languages/
    12   License:
    13  */
     3// if uninstall.php is not called by WordPress, die
     4if (!defined('WP_UNINSTALL_PLUGIN')) {
     5    die;
     6}
     7 
     8delete_option('wp_admin_cache_settings');
     9 
    1410
    15 if (!function_exists('add_action')) {
    16     exit;
    17 }
    1811
    19 class AdminCache {
    2012
    21     private $settings;
    22     private $beginStarted = false;
    23     private $currentCaching = '';
    24 
    25     function __construct() {
    26         if (!is_admin()) return;
    27         $this->settings = json_decode(get_option('wp_admin_cache_settings'), true);
    28         add_action('admin_menu', array($this, 'init'));
    29         add_action('admin_print_footer_scripts', array($this, 'writeScripts'));
    30         if ($this->settings['enabled']) {
    31             $this->begin();
    32             $this->autoPurgeCache();
    33         }
    34     }
    35 
    36     function init() {
    37         add_options_page('WP Admin Cache', 'WP Admin Cache', 'manage_options', 'wp-admin-cache', array($this, 'options_page'));
    38         wp_enqueue_script('wp-admin-cache-script', plugin_dir_url(__FILE__) . 'index.js');
    39         wp_enqueue_style('wp-admin-cache-style', plugin_dir_url(__FILE__) . 'index.css');
    40         $session = wp_get_session_token();
    41         if (!isset($_COOKIE['wp-admin-cache-session']) || $_COOKIE['wp-admin-cache-session'] != $session) setcookie('wp-admin-cache-session', $session, 0, admin_url());
    42     }
    43 
    44     function writeScripts() {
    45         echo '<script>';
    46         foreach ($this->getEnabledUrls() as $url) echo 'wp_cache_prefetch("' . $url . '"); ';
    47         echo '</script>';
    48     }
    49 
    50     function movePluginAtTop() {
    51         $path = str_replace(WP_PLUGIN_DIR . '/', '', __FILE__);
    52         if ($plugins = get_option('active_plugins')) {
    53             if ($key = array_search($path, $plugins)) {
    54                 array_splice($plugins, $key, 1);
    55                 array_unshift($plugins, $path);
    56                 update_option('active_plugins', $plugins);
    57             }
    58         }
    59     }
    60 
    61     function options_page() {
    62         include_once 'settings.php';
    63     }
    64 
    65     function getToken() {
    66         if (isset($_COOKIE['wp-admin-cache-session'])) return $_COOKIE['wp-admin-cache-session'];
    67         return '';
    68     }
    69 
    70     function autoPurgeCache() {
    71         add_action('activated_plugin', array($this, 'purgeCache'));
    72         add_action('deactivated_plugin', array($this, 'purgeCache'));
    73         add_action('wp_insert_post', array($this, 'purgeCache'));
    74         add_filter('widget_update_callback', array($this, 'widget_update_callback'), 10, 3);
    75         add_action('upgrader_process_complete', array($this, 'upgrader_callback'), 10, 2);
    76     }
    77 
    78     function purgeCache() {
    79         foreach ($this->getEnabledUrls() as $url) {
    80             delete_transient('wp-admin-cached-' . $this->getToken() . $url);
    81         }
    82     }
    83 
    84     function widget_update_callback($array) {
    85         $this->purgeCache();
    86         return $array;
    87     }
    88 
    89     function upgrader_callback($upgrader_object, $options) {
    90         $this->purgeCache();
    91     }
    92 
    93     function begin() {
    94         if ($this->beginStarted) return;
    95         $token = $this->getToken();
    96         if ($token == '') return;
    97         $this->beginStarted = true;
    98         $currentPage = add_query_arg(NULL, NULL);
    99         $currentPage = explode('/', $currentPage);
    100         $currentPage = $currentPage[count($currentPage) - 1];
    101         if (in_array($currentPage, $this->getEnabledUrls())) {
    102             $tName = 'wp-admin-cached-' . $token . $currentPage;
    103             $content = get_transient($tName);
    104             if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    105                 $this->purgeCache();
    106                 return;
    107             }
    108             if ($content === false) {
    109                 $this->currentCaching = $tName;
    110                 ob_start(array($this, 'end'));
    111             } else {
    112                 if (isset($this->settings['show-label']) && $this->settings['show-label'] == '1') {
    113                     echo str_replace('</body>', '<div class="wp-admin-cache-label">cached page</div><!--wp-admin-cached--></body>', $content);
    114                 } else {
    115                     echo str_replace('</body>', '<!--wp-admin-cached--></body>', $content);
    116                 }
    117                 die();
    118             }
    119         }
    120     }
    121 
    122     function end($content) {
    123         $duration = $this->settings['duration'];
    124         if ($duration == '') $duration = '5';
    125         set_transient($this->currentCaching, $content, 60 * $duration);
    126         return $content;
    127     }
    128 
    129     function getPageHooks() {
    130         global $admin_page_hooks;
    131         $a = array();
    132         foreach ($admin_page_hooks as $key => $value) {
    133             if (strpos($key, '.php') !== false && strpos($key, '/') === false) array_push($a, $key);
    134         }
    135         $args = array('show_ui' => true);
    136         foreach (get_post_types($args) as $type) {
    137             $url = 'edit.php?post_type=' . $type;
    138             if (!in_array($url, $a)) array_push($a, $url);
    139         }
    140         array_push($a, 'widgets.php');
    141         sort($a);
    142         return $a;
    143     }
    144 
    145     function getEnabledUrls() {
    146         $urls = $this->settings['enabled-urls'];
    147         return $urls;
    148     }
    149 
    150 }
    151 
    152 new AdminCache();
    153 
Note: See TracChangeset for help on using the changeset viewer.