Plugin Directory

Changeset 1375863


Ignore:
Timestamp:
03/21/2016 08:07:44 PM (10 years ago)
Author:
jkrill
Message:

3.5.1 - bug fixes to caching system

Location:
wp-jump-menu
Files:
64 added
3 edited

Legend:

Unmodified
Added
Removed
  • wp-jump-menu/trunk/assets/js/wpjm-main.js

    r1375382 r1375863  
    1616        var $el = jQuery('#wp-pdd').on('change', function () {
    1717            if (this.value === '__reload__') {
    18                 self.wpjm_load();
     18                self.wpjm_refresh();
    1919            } else {
    2020                window.location = this.value;
    2121            }
    2222        });
    23         if (window.localStorage) {
    24             var $clearCacheOpt = jQuery('<option value="__reload__">' + opts.reloadText + '</option>');
    25             $el.find('option:last').parent().append($clearCacheOpt);
    26         }
     23       
     24        var $clearCacheOpt = jQuery('<option value="__reload__">' + opts.reloadText + '</option>');
     25        $el.find('option:last').parent().append($clearCacheOpt);
     26
    2727        if (opts.useChosen) {
    2828            $el.customChosen({position: opts.position, search_contains: true});
     
    4141        // load new
    4242        jQuery.get(self.wpjm_get_opts().baseUrl + '?action=wpjm_menu', function (html) {
    43             if (window.localStorage) {
    44                 localStorage.setItem(CACHE_KEY, html);
    45             }
    4643            self.wpjm_render(html);
    4744        });
    4845    };
     46
     47    this.wpjm_refresh = function() {
     48        // remove old stuff if it's there
     49        jQuery(WPJM_PARENT_ID).children('*:not(script):not(.ab-item, .loader)').remove();
     50        // load new
     51        jQuery.get(self.wpjm_get_opts().baseUrl + '?action=wpjm_menu&refresh=true', function (html) {
     52            self.wpjm_render(html);
     53        });
     54    }
    4955
    5056    this.wpjm_init_html = function (opts) {
     
    5258        $parent.data('opts', opts);
    5359
    54         var cached = window.localStorage && window.localStorage.getItem(CACHE_KEY);
    55         if (cached) {
    56             self.wpjm_render(cached);
    57         } else {
    58             self.wpjm_load();
    59         }
    60         $parent.find('.ab-item').click(self.wpjm_load);
     60        self.wpjm_load();
     61
     62        $parent.find('.ab-item').click(self.wpjm_refresh);
    6163    };
    6264
  • wp-jump-menu/trunk/readme.txt

    r1375383 r1375863  
    55Author URI: http://krillwebdesign.com
    66Tags: posts, pages, admin, jump, menu, quick, links, custom post types
    7 Requires at least: 3.2.1
     7Requires at least: 3.7
    88Tested up to: 4.4.2
    9 Stable tag: 3.5
     9Stable tag: 3.5.1
    1010
    1111Creates a drop-down menu in the admin area which makes it easy to jump to a page, post, custom post type or media file for editing.
     
    110110
    111111== Changelog ==
     112= 3.5.1 =
     113* Bug fix on caching system.
     114
    112115= 3.5 =
    113116* Ajax loading of menu to improve load time of large sites (special thanks to Denis Andrejew)
  • wp-jump-menu/trunk/wp-jump-menu.php

    r1375382 r1375863  
    99Plugin URI: http://wpjumpmenu.com
    1010Description: Creates a drop-down menu (jump menu) in a bar across the top or bottom of the screen that makes it easy to jump right to a page, post, or custom post type in the admin area to edit.
    11 Version: 3.5
     11Version: 3.5.1
    1212Author: Jim Krill
    1313Author URI: http://krillwebdesign.com
     
    2525        $options,
    2626        $current_user,
    27         $options_page;
     27        $options_page,
     28        $menu_cache_label,
     29        $menu_refresh_cache_label;
    2830
    2931    /*
     
    4042        $this->path = plugin_dir_path( __FILE__ );
    4143        $this->dir = plugins_url( '', __FILE__ );
    42         $this->version = '3.5';
     44        $this->version = '3.5.1';
    4345        $this->upgrade_version = '';
    4446        $this->options = get_option( 'wpjm_options' );
     47        $this->menu_cache_label = "wpjm_menu";
     48        $this->menu_refresh_cache_label = "wpjm_needs_refresh";
    4549
    4650        // set text domain
     
    8387
    8488        // Clear LocalStorage on save
    85         add_action( 'save_post', array( $this, 'clear_local_storage' ));
    86         add_action( 'admin_footer', array( $this, 'refresh_local_storage'));
     89//      add_action( 'save_post', array( $this, 'clear_local_storage' ), 10, 3);
     90        foreach($this->options['postTypes'] as $key=>$val) {
     91            add_action( 'save_post_'.$key, array($this, 'clear_local_storage'), 10, 3);
     92        }
     93//      add_action( 'admin_footer', array( $this, 'refresh_local_storage'));
    8794
    8895        if ( current_user_can('manage_options')) {
     
    141148            'useChosen' => isset( $this->options['useChosen'] ) && $this->options['useChosen'] == 'true',
    142149            'position' => esc_js($this->options['position']),
    143             'reloadText' => __('Reload list'),
     150            'reloadText' => __('Refresh Jump Menu'),
    144151            'currentPageID' => $post_id
    145152        ));
     
    179186     * @created: 03/20/2016
    180187     */
    181     function clear_local_storage()
    182     {
    183         update_option('wpjm-needs-refresh', 1);
     188    function clear_local_storage( $post_id, $post, $update )
     189    {
     190
     191//      error_log('WPJM: post id: '.$post_id);
     192//      error_log('WPJM: post: '.json_encode($post));
     193//      error_log('WPJM: update: '.json_encode($update));
     194
     195        // Do nothing if this is a auto-draft, revision, etc.
     196        if (!$update) {
     197            return;
     198        }
     199
     200//      error_log('WPJM: clear local storage');
     201        update_option($this->menu_refresh_cache_label, 1);
     202
    184203    }
    185204
     
    193212    function refresh_local_storage()
    194213    {
    195         $needs_refresh = get_option('wpjm-needs-refresh');
     214        $needs_refresh = get_option($this->menu_refresh_cache_label);
    196215        if ($needs_refresh == 1) {
    197216            echo '<script>jQuery(document).ready(function(){wpjm.wpjm_load(); console.log("refreshed.");});</script>';
    198217        }
    199         delete_option('wpjm-needs-refresh');
     218        delete_option($this->menu_refresh_cache_label);
    200219    }
    201220
     
    454473
    455474    function wpjm_menu() {
    456         echo $this->wpjm_page_dropdown();
     475
     476        $wpjm_menu = "";
     477        $wpjm_refresh = isset($_GET['refresh'])?$_GET['refresh']:false;
     478
     479        $needs_refresh = get_option($this->menu_refresh_cache_label);
     480        $wpjm_menu = get_option($this->menu_cache_label);
     481        if ($needs_refresh == 1 || !$wpjm_menu || $wpjm_refresh) {
     482            $wpjm_menu = $this->wpjm_page_dropdown();
     483            update_option($this->menu_cache_label, $wpjm_menu);
     484            delete_option($this->menu_refresh_cache_label);
     485
     486        } else {
     487
     488//          error_log('WPJM: Using cached menu');
     489
     490        }
     491
     492        echo $wpjm_menu;
     493
    457494        if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
    458495          wp_die();
Note: See TracChangeset for help on using the changeset viewer.