Changeset 2050442
- Timestamp:
- 03/14/2019 12:11:13 PM (7 years ago)
- Location:
- wp-admin-cache/trunk
- Files:
-
- 5 edited
-
index.css (modified) (1 diff)
-
index.js (modified) (1 diff)
-
index.php (modified) (7 diffs)
-
readme.txt (modified) (3 diffs)
-
settings.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wp-admin-cache/trunk/index.css
r2046135 r2050442 1 .wp-admin-cache-label {position:fixed;bottom:0px;right:0px;background:#00DD00;color:#fff;padding:2px 5px;z-index:10000;opacity:.5;font-size:11px;font-weight:bold} 1 .wp-admin-cache-label {position:fixed;bottom:0px;right:0px;background:#00DD00;color:#fff;z-index:10000;opacity:.5;font-size:11px;font-weight:bold;padding:0px 5px;pointer-events: none } 2 .wp-admin-cache-pageList {background-color:rgba(255,255,255,.7);padding:5px} -
wp-admin-cache/trunk/index.js
r2046135 r2050442 1 jQuery(document).ready(function ($) { 1 function wp_admin_cache_prefetch(urls) { 2 if (urls.length == 0) return; 3 4 var countDown = 0; 5 var refresh = 0; 6 7 function exec() { 8 countDown--; 9 if (countDown < 0) { 10 countDown = 60; 11 jQuery.ajax({ 12 url: urls[0], 13 method: 'POST', 14 data: {'wp_admin_cache_prefetch': 1, 'wp_admin_cache_refresh': refresh} 15 }).done(function (data) { 16 if (data.indexOf("prefetched") == 0) { 17 var expiration = data.split(':')[1] * 1; 18 if (expiration < 60) { 19 countDown = expiration - 2; 20 refresh = 1; 21 } 22 } 23 else { 24 for (var i = 1; i < urls.length; i++) { 25 function exec2(url) { 26 jQuery.ajax({ 27 url: url, 28 method: 'POST', 29 data: {'wp_admin_cache_prefetch': 1, 'wp_admin_cache_refresh': refresh} 30 }).done(function (data) { 31 32 }); 33 } 34 if (urls[i] != '') exec2(urls[i]); 35 } 36 refresh = false; 37 } 38 }); 39 } 2 40 3 41 4 42 43 } 44 setInterval(exec, 1000); 45 46 } 47 48 jQuery(function ($) { 49 $(".wp-admin-cache-selectAll").on("click", function () { 50 var check = this; 51 $(this).closest("form").find(".wp-admin-cache-pageList input[type=checkbox]").each(function () { 52 this.checked = check.checked; 53 }); 54 }); 55 5 56 }); 6 7 8 function wp_cache_prefetch(url){9 function exec(){10 jQuery.ajax({11 url: url12 }).done(function(data) {13 //console.log("WP Cache caching: "+url);14 });15 }16 setInterval(exec,1000*50);17 setTimeout(exec,1000);18 } -
wp-admin-cache/trunk/index.php
r2048532 r2050442 5 5 Plugin URI: https://www.wpadmincache.com 6 6 Description: The first cache plugin for WordPress admin area 7 Version: 0. 1.37 Version: 0.2.0 8 8 Author: Grf Studio 9 9 Author URI: https://www.grfstudio.com … … 22 22 private $beginStarted = false; 23 23 private $currentCaching = ''; 24 private $enabled = false; 24 25 25 26 function __construct() { 26 27 if (!is_admin()) return; 27 28 $this->settings = json_decode(get_option('wp_admin_cache_settings'), true); 29 $this->enabled = $this->settings['enabled']; 28 30 add_action('admin_menu', array($this, 'init')); 29 31 add_action('admin_print_footer_scripts', array($this, 'writeScripts')); 30 if ($this-> settings['enabled']) {32 if ($this->enabled) { 31 33 $this->begin(); 32 34 $this->autoPurgeCache(); … … 36 38 function init() { 37 39 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 wp_enqueue_script('wp-admin-cache-script', plugin_dir_url(__FILE__) . 'index.js', array(), '0.2.0'); 41 wp_enqueue_style('wp-admin-cache-style', plugin_dir_url(__FILE__) . 'index.css', array(), '0.2.0'); 40 42 $session = wp_get_session_token(); 41 43 if (!isset($_COOKIE['wp-admin-cache-session']) || $_COOKIE['wp-admin-cache-session'] != $session) setcookie('wp-admin-cache-session', $session, 0, admin_url()); … … 43 45 44 46 function writeScripts() { 45 echo '<script>'; 46 foreach ($this->getEnabledUrls() as $url) echo 'wp_cache_prefetch("' . $url . '"); '; 47 echo '</script>'; 47 if ($this->enabled) { 48 echo '<script>wp_admin_cache_prefetch(['; 49 foreach ($this->getEnabledUrls() as $url) echo '"' . $url . '",'; 50 echo ']); </script>'; 51 } 48 52 } 49 53 … … 102 106 $tName = 'wp-admin-cached-' . $token . $currentPage; 103 107 $content = get_transient($tName); 104 if ($_SERVER['REQUEST_METHOD'] === 'POST' ) {108 if ($_SERVER['REQUEST_METHOD'] === 'POST' && !isset($_POST['wp_admin_cache_prefetch'])) { 105 109 $this->purgeCache(); 106 110 return; 107 111 } 112 if(isset($_POST['wp_admin_cache_refresh']) && $_POST['wp_admin_cache_refresh']=='1')$content=false; 108 113 if ($content === false) { 109 114 $this->currentCaching = $tName; 110 115 ob_start(array($this, 'end')); 111 116 } else { 117 if (isset($_POST['wp_admin_cache_prefetch'])) { 118 preg_match('/--wp-admin-cached:(.*)--/', $content, $matches); 119 echo 'prefetched:'.(($this->settings['duration']*60)-(time()-$matches[1])); 120 die(); 121 } 112 122 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);123 echo str_replace('</body>', '<div class="wp-admin-cache-label">cached page</div></body>', $content); 114 124 } else { 115 echo str_replace('</body>', '<!--wp-admin-cached--></body>', $content);125 echo $content; 116 126 } 117 127 die(); … … 121 131 122 132 function end($content) { 133 if (strpos($content, '</html>') === false) return; 123 134 $duration = $this->settings['duration']; 124 135 if ($duration == '') $duration = '5'; 136 $content=str_replace('</body>', '<!--wp-admin-cached:' . time() . '--></body>', $content); 125 137 set_transient($this->currentCaching, $content, 60 * $duration); 138 if (isset($_POST['wp_admin_cache_prefetch'])) { 139 return 'prefetching'; 140 } 126 141 return $content; 127 142 } … … 133 148 if (strpos($key, '.php') !== false && strpos($key, '/') === false) array_push($a, $key); 134 149 } 135 $args = array('show_ ui' => true);150 $args = array('show_in_menu' => true); 136 151 foreach (get_post_types($args) as $type) { 152 if($type!='attachment'){ 137 153 $url = 'edit.php?post_type=' . $type; 138 if (!in_array($url, $a)) array_push($a, $url); 154 if (!in_array($url, $a)) array_push($a, $url); 155 } 156 139 157 } 140 158 array_push($a, 'widgets.php'); -
wp-admin-cache/trunk/readme.txt
r2048532 r2050442 2 2 Contributors: grfstudio 3 3 Tags: admin cache, admin performance, admin speed, slow admin 4 Stable tag: 0. 1.34 Stable tag: 0.2.0 5 5 Requires PHP: 5.6 6 6 Requires at least: 4.6 … … 13 13 14 14 This lightweight plugin caches the most visited pages in the admin area; it uses ajax to prefetch the pages and stores them on the server for each user. 15 15 16 The plugin is useful for sites with many installed plugins, which often make the administrative section very slow. 16 17 … … 41 42 == Changelog == 42 43 44 = 0.2.0 = 45 46 * Added the possibility to execute the plugin before the others, in order to speed up the sending of cached pages much more! 47 * Improved prefetching mechanism 48 * Improved UI 49 43 50 = 0.1.3 = 44 51 -
wp-admin-cache/trunk/settings.php
r2048532 r2050442 1 <?php if(!isset($this))die(''); 2 if(!is_admin())die(''); 1 <?php 2 if (!isset($this)) die(''); 3 if (!is_admin()) die(''); 4 $status=''; 3 5 if (isset($_POST['wp_admin_cache_save'])) { 4 check_admin_referer('wp_admin_cache_settings_n'); 5 $obj = array(); 6 $obj['enabled'] = sanitize_text_field($_POST['wp_admin_cache_enabled']); 7 if(isset($_POST['wp_admin_cache_url_enabled'])){ 8 $urlsEnabled=$_POST['wp_admin_cache_url_enabled']; 9 $a=array(); 10 foreach($urlsEnabled as $value){ 11 array_push($a,sanitize_text_field($value)); 12 } 13 $obj['enabled-urls']= $a; 14 } 15 $obj['show-label'] = (int)sanitize_text_field($_POST['wp_admin_cache_show_label']); 16 $obj['duration'] = (int)sanitize_text_field($_POST['wp_admin_cache_duration']); 17 update_option('wp_admin_cache_settings', json_encode($obj)); 18 $this->movePluginAtTop(); 19 $this->purgeCache(); 6 check_admin_referer('wp_admin_cache_settings_n'); 7 $obj = array(); 8 $obj['enabled'] = sanitize_text_field($_POST['wp_admin_cache_enabled']); 9 $this->enabled=$obj['enabled']; 10 if (isset($_POST['wp_admin_cache_url_enabled'])) { 11 $urlsEnabled = $_POST['wp_admin_cache_url_enabled']; 12 $a = array(); 13 foreach ($urlsEnabled as $value) { 14 array_push($a, sanitize_text_field($value)); 15 } 16 $obj['enabled-urls'] = $a; 17 } 18 $obj['show-label'] = (int) sanitize_text_field($_POST['wp_admin_cache_show_label']); 19 $obj['load-first'] = (int) sanitize_text_field($_POST['wp_admin_cache_load_first']); 20 $obj['duration'] = (int) sanitize_text_field($_POST['wp_admin_cache_duration']); 21 22 update_option('wp_admin_cache_settings', json_encode($obj)); 23 if ($obj['load-first'] == 1) { 24 $this->movePluginAtTop(); 25 } 26 $this->purgeCache(); 27 28 $status= '<div class="updated notice"><p>'.__('Settings updated', 'wp-admin-cache').'</p></div>'; 29 20 30 } 21 31 22 32 $settings = json_decode(get_option('wp_admin_cache_settings'), true); 23 $enabled =$settings['enabled'];24 $enabledUrls =$settings['enabled-urls'];25 $duration =$settings['duration'];26 if ($duration=='')$duration='5';27 global $menu, $_registered_pages,$admin_page_hooks;33 $enabled = $settings['enabled']; 34 $enabledUrls = $settings['enabled-urls']; 35 $duration = $settings['duration']; 36 if ($duration == '') $duration = '5'; 37 global $menu, $_registered_pages, $admin_page_hooks; 28 38 ?> 39 <?php echo $status ?> 29 40 <form method="post"> 30 <h2><?php echo __('Cached pages','wp-admin-cache') ?></h2> 31 <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 <p><?php echo __('The plugin is currently under development, any feedback that helps us to improve it is much appreciated.')?></p> 33 <ul> 34 <li><h3> 35 <label><input type="checkbox" name="wp_admin_cache_enabled" value="1" <?php if($enabled) echo 'checked' ?>> <?php echo __('Cache enabled','wp-admin-cache') ?></label> 36 </h3></li> 37 <?php 38 foreach ( $this->getPageHooks() as $url ) { 39 $checked=''; 40 if(in_array($url,$enabledUrls))$checked='checked'; 41 echo '<li><label><input type="checkbox" name="wp_admin_cache_url_enabled[]" value="'.$url.'" '.$checked.' > '.$url.'</label></li>'; 42 } 43 ?> 44 </ul> 45 <div> 46 <?php echo __('Cache duration','wp-admin-cache') ?>: <input type="number" name="wp_admin_cache_duration" value="<?php echo $duration ?>"> <?php echo __('minutes','wp-admin-cache') ?> 47 </div> 48 <p> 49 <label><input type="checkbox" name="wp_admin_cache_show_label" value="1" <?php if($settings['show-label']=='1') echo 'checked' ?>> <?php echo __('Show a label on each cached page','wp-admin-cache') ?></label> 50 </p> 51 <input type="submit" name="wp_admin_cache_save" value="<?php echo __('Save and purge cache','wp-admin-cache') ?>" class="button button-primary" > 52 <?php 53 if ( function_exists('wp_nonce_field') ) 54 wp_nonce_field('wp_admin_cache_settings_n'); 55 ?> 41 <h3> 42 <label><input type="checkbox" name="wp_admin_cache_enabled" value="1" <?php if ($enabled) echo 'checked' ?>> <?php echo __('Cache enabled', 'wp-admin-cache') ?></label> 43 </h3> 44 <h2><?php echo __('Cached pages', 'wp-admin-cache') ?></h2> 45 <p><?php echo __('Select which pages should be cached.', 'wp-admin-cache'); ?></p> 46 <p><label><input type="checkbox" class="wp-admin-cache-selectAll" /><?php echo __('Select/unselect all', 'wp-admin-cache') ?></label></p> 47 <ul class="wp-admin-cache-pageList"> 48 <?php 49 foreach ($this->getPageHooks() as $url) { 50 $checked = ''; 51 if (in_array($url, $enabledUrls)) $checked = 'checked'; 52 echo '<li><label><input type="checkbox" name="wp_admin_cache_url_enabled[]" value="' . $url . '" ' . $checked . ' > ' . $url . '</label></li>'; 53 } 54 ?> 55 </ul> 56 <p> 57 <?php echo __('Max cache duration', 'wp-admin-cache') ?>: <input type="number" name="wp_admin_cache_duration" value="<?php echo $duration ?>"> <?php echo __('minutes', 'wp-admin-cache') ?><br> 58 <?php echo __('The cache is regenerated after the specified time, or when certain events occur (adding or updating a post or a page, saving options, saving widgets, activating plugins).', 'wp-admin-cache') ?><br> 59 <?php echo __('Important: the cache is managed for each user; if more than one user is connected, not all users may have updated pages; in these cases, reduce the duration of the cache.', 'wp-admin-cache') ?> 60 </p> 61 <p> 62 <label><input type="checkbox" name="wp_admin_cache_show_label" value="1" <?php if ($settings['show-label'] == '1') echo 'checked' ?>> <?php echo __('Show a label on each cached page (shows which pages are actually cached)', 'wp-admin-cache') ?></label> 63 </p> 64 <p> 65 <label><input type="checkbox" name="wp_admin_cache_load_first" value="1" <?php if ($settings['load-first'] == '1') echo 'checked' ?>> <?php echo __('Load this plugin before others (can improve performance of cached pages)', 'wp-admin-cache') ?></label> 66 </p> 67 <input type="submit" name="wp_admin_cache_save" value="<?php echo __('Save and purge cache', 'wp-admin-cache') ?>" class="button button-primary" > 68 69 <p><?php echo __('The plugin is under development, more features and optimizations will be activated soon.') ?></p> 70 <?php 71 if (function_exists('wp_nonce_field')) wp_nonce_field('wp_admin_cache_settings_n'); 72 ?> 56 73 </form>
Note: See TracChangeset
for help on using the changeset viewer.