Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inpsyde/menu-cache
Easily cache rendered menus using the Transients API.
https://github.com/inpsyde/menu-cache
cached-menus transients-api wordpress wordpress-plugin
Last synced: about 2 months ago
JSON representation
Easily cache rendered menus using the Transients API.
- Host: GitHub
- URL: https://github.com/inpsyde/menu-cache
- Owner: inpsyde
- License: gpl-2.0
- Archived: true
- Created: 2016-10-24T15:09:04.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-12-10T12:19:42.000Z (about 5 years ago)
- Last Synced: 2024-10-29T01:37:18.646Z (2 months ago)
- Topics: cached-menus, transients-api, wordpress, wordpress-plugin
- Language: PHP
- Homepage: https://packagist.org/packages/inpsyde/menu-cache
- Size: 37.1 KB
- Stars: 72
- Watchers: 11
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-wp-speed-up - Inpsyde Menu Cache - Easily cache rendered menus using the Transients API. (Caching Helping Plugins)
README
# Inpsyde Menu Cache
[![Version](https://img.shields.io/packagist/v/inpsyde/menu-cache.svg)](https://packagist.org/packages/inpsyde/menu-cache)
[![Status](https://img.shields.io/badge/status-active-brightgreen.svg)](https://github.com/inpsyde/menu-cache)
[![Build](https://img.shields.io/travis/inpsyde/menu-cache.svg)](http://travis-ci.org/inpsyde/menu-cache)
[![Downloads](https://img.shields.io/packagist/dt/inpsyde/menu-cache.svg)](https://packagist.org/packages/inpsyde/menu-cache)
[![License](https://img.shields.io/packagist/l/inpsyde/menu-cache.svg)](https://packagist.org/packages/inpsyde/menu-cache)> Easily cache rendered menus using the Transients API.
## Introduction
The `wp_nav_menu()` function calls `_wp_menu_item_classes_by_context()`, which again, depending on the context, calls `wp_get_object_terms()`, which is **not** cached, multiple times.
With lots of taxonomies, terms and menu items, this can lead to a fair amount of (totally redundant) database queries.This plugin lets you cache rendered menus (assuming they don't have dynamic components) for re-use.
## Installation
Install with [Composer](https://getcomposer.org):
```sh
$ composer require inpsyde/menu-cache
```### Requirements
This package requires PHP 5.4 or higher.
## Usage
Once activated, the plugin caches **all** menus, by default for **five minutes**.
The menus to be cached, as well as the expiration, can be customized by using the appropriate filter.### Filters
Need to customize anything?
Just use the provided filters.**Please note:** when you use the below class constants for the filters, make sure that the class is actually available.
This can be as easy as _guarding_ your customization with `if ( class_exists( 'Inpsyde\MenuCache\MenuCache' ) )`.#### `Inpsyde\MenuCache\MenuCache::FILTER_EXPIRATION`
The `Inpsyde\MenuCache\MenuCache::FILTER_EXPIRATION` filter allows you to define the expiration for all cached menus.
The default value is 300, which is 5 minutes.**Arguments:**
- `int` `$expiration`: Expiration in seconds.
**Usage Example:**
```php
theme_location}";
}, 10, 2 );
```#### `Inpsyde\MenuCache\MenuCache::FILTER_KEY_ARGUMENT`
The `Inpsyde\MenuCache\MenuCache::FILTER_KEY_ARGUMENT` filter allows you to customize the menu argument name that is used to store the menu key (for later look-up).
**Arguments:**
- `string` `$key_argument`: Current key argument name.
**Usage Example:**
```php
theme_location, 'some_prefix_here_' );
}, 10, 2 );
```#### `Inpsyde\MenuCache\MenuCache::FILTER_THEME_LOCATIONS`
The `Inpsyde\MenuCache\MenuCache::FILTER_THEME_LOCATIONS` filter allows you to define theme locations to restrict caching menus to.
**Arguments:**
- `string|string[]` `$theme_locations`: One or more theme locations.
**Usage Example:**
```php