All Projects → inpsyde → menu-cache

inpsyde / menu-cache

Licence: GPL-2.0 License
Easily cache rendered menus using the Transients API.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to menu-cache

AuthPress
Add 2-factor authentication to your WordPress blog site.
Stars: ✭ 16 (-77.46%)
Mutual labels:  wordpress-plugin
pmpro-series
This is the "drip feed content" module for Paid Memberships Pro.
Stars: ✭ 23 (-67.61%)
Mutual labels:  wordpress-plugin
acf-country
ACF Country field - Display a select field of all countries, in any language.
Stars: ✭ 103 (+45.07%)
Mutual labels:  wordpress-plugin
mediapress
The Most advanced Media Gallery Plugin for BuddyPress
Stars: ✭ 31 (-56.34%)
Mutual labels:  wordpress-plugin
WPFBOGP
WordPress Open Graph plugin development
Stars: ✭ 13 (-81.69%)
Mutual labels:  wordpress-plugin
advanced-post-manager
Advanced Post Manager
Stars: ✭ 43 (-39.44%)
Mutual labels:  wordpress-plugin
wp-boilerplate-plugin-with-vuejs
This is an example plugin for Wp plugin developer.
Stars: ✭ 26 (-63.38%)
Mutual labels:  wordpress-plugin
pmpro-approvals
Grants administrators the ability to approve/deny memberships after signup.
Stars: ✭ 13 (-81.69%)
Mutual labels:  wordpress-plugin
tiny-cache
Cache WordPress post content, template part, translations and nav menu output in persistent object cache
Stars: ✭ 26 (-63.38%)
Mutual labels:  wordpress-plugin
wp-graphql-gravity-forms
GraphQL API for interacting with Gravity Forms.
Stars: ✭ 119 (+67.61%)
Mutual labels:  wordpress-plugin
falcon
A WordPress cleanup and performance optimization plugin.
Stars: ✭ 17 (-76.06%)
Mutual labels:  wordpress-plugin
wordpress-nodeinfo
NodeInfo and NodeInfo2 for WordPress
Stars: ✭ 13 (-81.69%)
Mutual labels:  wordpress-plugin
wp-combine-queries
WordPress: Combine multiple WP_Query() queries into a single one, through the custom 'combined_query' attribute of the WP_Query class.
Stars: ✭ 63 (-11.27%)
Mutual labels:  wordpress-plugin
slim-seo
A fast and automated WordPress SEO plugin.
Stars: ✭ 49 (-30.99%)
Mutual labels:  wordpress-plugin
analogwp-templates
Style Kits for Elementor adds a number of intuitive styling controls in the Elementor editor that allow you to apply styles globally or per page.
Stars: ✭ 20 (-71.83%)
Mutual labels:  wordpress-plugin
buoy
🆘 A community-based crisis response system. Because friends don't let friends call the cops. 🔥🚓🔥
Stars: ✭ 68 (-4.23%)
Mutual labels:  wordpress-plugin
hivepress
Free multipurpose directory, listing & classifieds WordPress plugin.
Stars: ✭ 25 (-64.79%)
Mutual labels:  wordpress-plugin
em-beer-manager
Manage your beers with WordPress. Integrates simply with Untappd beer checkins. Great for everyone from home brewers to professional breweries!
Stars: ✭ 15 (-78.87%)
Mutual labels:  wordpress-plugin
txt2img
山寨长微博
Stars: ✭ 13 (-81.69%)
Mutual labels:  wordpress-plugin
cf-civicrm
Caldera Forms CiviCRM Integration
Stars: ✭ 30 (-57.75%)
Mutual labels:  wordpress-plugin

Inpsyde Menu Cache

Version Status Build Downloads License

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:

$ 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

add_filter( \Inpsyde\MenuCache\MenuCache::FILTER_EXPIRATION, function () {

	// Cache menus for 10 minutes.
	return 600;
} );

Inpsyde\MenuCache\MenuCache::FILTER_KEY

The Inpsyde\MenuCache\MenuCache::FILTER_KEY filter allows you to customize the cache key on a per-menu basis. The default value is constructed using a predfined prefix and the MD5 hash of the serialized args object.

Arguments:

  • string $key: Current key.
  • object $args: Menu args.

Usage Example:

<?php

add_filter( \Inpsyde\MenuCache\MenuCache::FILTER_KEY, function ( $key, $args ) {

	// Construct the key based on the theme location only.
	return "cached_menu_{$args->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

add_filter( \Inpsyde\MenuCache\MenuCache::FILTER_KEY_ARGUMENT, function () {

	// Use argument name with a leading underscore.
	return '_menu_key';
} );

Inpsyde\MenuCache\MenuCache::FILTER_SHOULD_CACHE_MENU

The Inpsyde\MenuCache\MenuCache::FILTER_SHOULD_CACHE_MENU filter allows you to customize caching on a per-menu basis.

Arguments:

  • bool $key: Whether or not the menu should be cached.
  • object $args: Menu args.

Usage Example:

<?php

add_filter( \Inpsyde\MenuCache\MenuCache::FILTER_SHOULD_CACHE_MENU, function ( $should_cache_menu, $args ) {

	// Cache all menus for a bunch of dynamically created theme locations.
	return 0 === strpos( $args->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

add_filter( \Inpsyde\MenuCache\MenuCache::FILTER_THEME_LOCATIONS, function () {

	// Cache the menus for the "primary" theme location only.
	return 'primary';
} );

License

Copyright (c) 2017 Inpsyde GmbH

This code is licensed under the GPLv2+ License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].