Plugin Directory

Changeset 1326085


Ignore:
Timestamp:
01/11/2016 09:54:06 PM (10 years ago)
Author:
Studiofreya
Message:

Caching of the menu implemented.

Location:
sf-category-menu/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sf-category-menu/trunk/readme.txt

    r1319552 r1326085  
    2020* Translation ready
    2121* Doesn't show empty categories
     22* Caching of the menu
    2223
    2324= Live demo: =
  • sf-category-menu/trunk/sf-category-menu.php

    r1277377 r1326085  
    44 * Plugin Name: SF Category Menu Widget
    55 * Plugin URI: http://studiofreya.com/sf-category-menu/
    6  * Description: Easy treeview menu for WordPress categories.
    7  * Version: 1.3
     6 * Description: Easy treeview menu for WordPress categories, with catergory caching
     7 * Version: 1.4
    88 * Author: Studiofreya AS
    99 * Author URI: http://studiofreya.com
     
    110110    function widget( $args, $instance )
    111111    {
     112        $option_name = "sf_category_menu_cache";
     113        $option_created = "sf_category_menu_cache_created";
     114        $cached_content = get_option($option_name, false);
     115        $cached_time = get_option($option_created, 0);
     116        $now = time();
     117       
     118        if (!$cached_content || ($cached_time + 6*3600 < $now))
     119        {
     120            ob_start();
     121            $this->do_create_data($args, $instance);
     122            $output_content = ob_get_contents();
     123           
     124            // Save cached content
     125            $autoload = true; // Menu is visible on most pages
     126            update_option($option_name, $output_content, $autoload);
     127            update_option($option_created, $now, $autoload);
     128        }
     129        else
     130        {
     131            echo $cached_content;
     132        }
     133       
     134    }
     135   
     136    function do_create_data( $args, $instance )
     137    {
    112138        $exclude_categories = $instance['exclude_cat'];
    113139        $exclude_categories_arr = explode(",", $exclude_categories);
     
    147173        </script>
    148174        <?php
    149 
    150175    }
    151176
Note: See TracChangeset for help on using the changeset viewer.